https://kotlinlang.org logo
#compose
Title
# compose
l

Lucien Guimaraes

02/23/2023, 1:52 PM
Hello! What's the best behaviour to reset the scroll of LazyColumn/LazyRow after an UI update without being impacted by navigation? Using the following:
Copy code
LaunchedEffect(dataList) {
    lazyListState.scrollToItem(0)
}
Because the coroutine will be cancelled when the LaunchedEffect leaves the composition, this will be triggered if I navigate back to the view. Thanks!
solved 1
a

Albert Chang

02/23/2023, 2:52 PM
You can use
val lazyListState = key(dataList) { rememberLazyListState() }
.
l

Lucien Guimaraes

02/23/2023, 4:42 PM
Thanks, it works like a charm!
9 Views