https://kotlinlang.org logo
Title
r

robnik

09/01/2021, 5:25 PM
How do you make a LazyColumn reset scroll to zero when a model changes? Code in thread is not working.
// Taken from rememberLazyListState()
val lazyListState = rememberSaveable(searchModel.query, saver = LazyListState.Saver) {
        Log.i(TAG, "New lazyListState")
        LazyListState()
    }
…
LazyColumn(state = lazyListState) {
When the the
query
changes I'd like it to be back at scroll position zero. Instead the column is showing new data, but scrolled into it already.
n

nitrog42

09/01/2021, 6:40 PM
I would do : LaunchedEffect(query) { lazyListState.scrollTo(0) }
r

robnik

09/01/2021, 8:11 PM
Okay. I used
scrollToItem(0)
since that's all I see. My problem is now it scrolls to zero when I leave and come back to screen, even when
query
doesn't change.