Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack compose scroll listener

Is there a way by which I can log an event when scrolling in a Column? I made it scrollable, saved the scroll state, but I can't find where to call a lambda function given as param to composable onScroll: () -> Unit

like image 662
Flaviu Nes Avatar asked Jan 21 '26 08:01

Flaviu Nes


1 Answers

You can observe the scrollState:

 val scrollState = rememberScrollState()
 Column(
    modifier = Modifier
        .verticalScroll(scrollState)
)

You can check the value of this scrollState:

if (scrollState.isScrollInProgress){
    println("scrolling")
}

In case you need to wait for the scroll is completed, you can use if + DisposableEffect:

if (scrollState.isScrollInProgress) {
    DisposableEffect(Unit) {
        onDispose {
            println("scroll completed")
        }
    }
}
like image 148
Gabriele Mariotti Avatar answered Jan 23 '26 21:01

Gabriele Mariotti