Hey, what’s the best way to smooth scroll to a par...
# compose
h
Hey, what’s the best way to smooth scroll to a particular position in
LazyColumnFor
I’m using alpha08, and I can find methods like
LazyListState.snapToItemIndex
but this is without smooth scrolling and the method
LazyListState.smoothScrollBy
doesn’t take the index. How to smooth scroll to a specific index? Does the API exists for this right now?
h
Thanks for the quick response. I tried the
.scroll {}
API, and I’m not sure if I’m using it correctly. There is only one method for
ScrollScope
and that is
fun scrollBy(pixels: Float): Float
So, I tried this piece of code
Copy code
onClick = {
    coroutineScope.launch {
        state.scroll {
            state.snapToItemIndex(15)
        }
    }
}
But there is not scrolling or snapping to the index in this case, am I doing something wrong here?
a
You can animate the scroll yourself by using scrollBy and withFrameNanos or any of the other suspending animation APIs; you can check the current visible items in between frames
d
There should be a
smoothScrollTo
available iirc.
m
Agree with @Dominaezzz, right now the easiest way is to forget about smooth and use
snapToItemIndex
.