0

出于某种原因LazyColumn,不要通过鼠标单击和移动手势滚动。到目前为止,它仅适用于鼠标滚轮。对于LazyRows,也无法使用鼠标滚轮滚动。似乎惰性行对于 Compose for desktop 没用。

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

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

@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()
    }
}
4

1 回答 1

2

这是预期的行为。

所有可滚动组件(包括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")
    }
}
于 2022-01-20T02:33:40.633 回答