0

Scroll position of the lazy column is lost when navigating.


val pageItems = myPager?.collectAsLazyPagingItems()

LazyColumn(state = rememberLazyListState(), modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding())) {
       itemsIndexed(pageItems){ index, pageItem ->
            if (pageItem != null) {
                    Text("abc")
            }
        }
}

when navigating to other screen and coming back the state is reset to 0.

Nikhil Dupally
  • 753
  • 1
  • 4
  • 12

1 Answers1

0

This is a known issue . . . I am having the same problem!

https://issuetracker.google.com/179397301 is the issue

This is a work around I found that seems promising, but it hasn't fixed my problem yet...

enter code here 
@Composable
fun <T : Any> LazyPagingItems<T>.rememberLazyListState2(): LazyListState {
// After recreation, LazyPagingItems first return 0 items, then the cached items.
// This behavior/issue is resetting the LazyListState scroll position.
// Below is a workaround. More info<https://issuetracker.google.com/issues/177245496>.
return when (itemCount) {
// Return a different LazyListState instance.
0 -> remember(this) { LazyListState(0, 0) }
// Return rememberLazyListState (normal case).
else -> rememberLazyListState()
}
}
SaGu312
  • 11
  • 2