When using Paging3 and a LazyColumn, I lose my scroll position upon phone rotation when my LazyColumn starts with an`item` before displaying my actual paging content
Is there a proper fix for this? See thread for more info
giving a key to the first item does nothing unfortunately
t
Tolriq
11/07/2022, 5:30 PM
It's known and no official support for now you need to hide the first item until the pages are loaded. On phone but there's an issue about that.
z
Zun
11/07/2022, 5:31 PM
One hack I found is this
Copy code
@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 -> androidx.compose.foundation.lazy.rememberLazyListState()
}
}
which comes with the downside of not being able to scroll up programmtically
Zun
11/07/2022, 5:34 PM
@Tolriq guess I won't show any LazyColumn at all when there's no items. This works, thanks. Will change once there's a proper fix for this