Compose LazyListState scrollToItem or animatedScrollToItem do not work when there are many items
Asked Answered
F

1

7

When I have a large list of items, OR when i don't have large list of items but each with component renders slowly, the rememberLazyListState.scrollToItem OR rememberLazyListState.animateScrollToItem just don't seem to work in Jetpack Compose LazyColumn. The scroll falls at a random place... I was hoping it'd skip or wait for prev children to render so it can compute the scroll position but it doesn't. Alternative to this would be to build a loop and check firstVisibleItemIndex until it stops increasing but that feels like a major hack!

Freethinker answered 9/8, 2022 at 23:11 Comment(0)
L
0

Although I don't know why, the following code works for me:

 delay(100)  // delay 100
 listState.value.scrollToItem(index)
Lavella answered 17/6 at 6:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.