tscheppe
tscheppe

Reputation: 698

Compose for Desktop LazyRow/LazyColumn not scrolling with mouse click

For some reason LazyColumns do not scroll with a mouse click and move gesture. It only works with the mouse wheel so far. For LazyRows it is also not possible to scroll with the mouse wheel. It seems that lazy row is useless for Compose for desktop.

Are there any possiblities to enable a click and move gesture on LazyRow and LazyColum. And if not is it at least possible to enable to scroll through a LazyRow with the mouse wheel?

I used this minimal reproducible example to test the scrolling

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

Upvotes: 9

Views: 4098

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 88072

This is the intended behavior.

All scrollable components (including LazyColumn) work (for now) only with mouse wheel scroll events on the desktop.
The scrollable components should not respond to mouse drag/move events.

Here's a basic example of how you can add drag support to your components:

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")
    }
}

Upvotes: 24

Related Questions