LazyListState.animateScrollToItem skipping items i...
# compose
b
Hi, I'm trying to use animateScrollToItem method to scroll through all generated items in LazyColumn, but it seems it is skipping through most of them. I'm generating 1000 items in LazyColumn, but using animateScrollToItem(999) seems to scroll through like 50 and already be on the bottom. Is it just that fast that it looks that way, or is there some logic inside to cause that effect?
z
The maintainer is in a different time zone, I’d file a bug
s
Not sure if the implementation changed over time, but I had the opposite problem (my use case was a "scroll to top" button): I didn't want to scroll through the whole list as it was very laggy. Here's what I came up with:
Copy code
suspend fun LazyListState.smoothScrollToTop() {
    if (firstVisibleItemIndex > layoutInfo.visibleItemsInfo.size) {
        scrollToItem(layoutInfo.visibleItemsInfo.size)
    }
    animateScrollToItem(0)
}
I believe you can try a different (slower) animationSpec, if that makes sense