为桌面撰写 LazyRow/LazyColumn 不通过鼠标单击滚动

tsc*_*ppe 7 kotlin kotlin-multiplatform android-jetpack-compose compose-desktop

由于某些原因LazyColumn,请勿使用鼠标单击和移动手势进行滚动。到目前为止,它仅适用于鼠标滚轮。对于LazyRows 来说,也不可能使用鼠标滚轮滚动。看来惰性行对于桌面版 Compose 没有什么用处。

LazyRow是否有可能在和上启用单击和移动手势LazyColumLazyRow如果没有,至少可以使用鼠标滚轮滚动吗?

我使用这个最小的可重现示例来测试滚动

@Composable
@Preview
fun App() {
    var text by remember { mutableStateOf("Hello, World!") }

    MaterialTheme {
        LazyRow(modifier = Modifier.fillMaxSize()) {
            repeat(100) {
                item {
                    Text("Test Test Test Test $it    ")
                }
            }
        }
    }
}

fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        App()
    }
}
Run Code Online (Sandbox Code Playgroud)

Phi*_*hov 20

这是预期的行为。

所有可滚动组件(包括LazyColumn)(目前)仅适用于桌面上的鼠标滚轮滚动事件。
可滚动组件不应响应鼠标拖动/移动事件。

以下是如何向组件添加拖动支持的基本示例:

val scrollState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()
LazyRow(
    state = scrollState,
    modifier = Modifier
        .draggable(
            orientation = Orientation.Horizontal,
            state = rememberDraggableState { delta ->
                coroutineScope.launch {
                    scrollState.scrollBy(-delta)
                }
            },
        )
) {
    items(100) {
        Text("Test Test Test Test $it")
    }
}
Run Code Online (Sandbox Code Playgroud)