Using navigation, and having a lazycolumn in my sc...
# compose
p
Using navigation, and having a lazycolumn in my screen A with some scroll done until item 100, for example, when I go to screen B and come back to screen A, the scroll has been lost. I tried saving the list state using
rememberSaveable
with
LazyListState.Saver.
Also tried saving the state in uistate in the viewmodel uistate:
Copy code
data class ScreenUiState(val listState: LazyListState = LazyListState()...
But the scroll is still missing when navigating back. Seems that compose even destroys the viewmodels when navigating back.
z
rememberLazyListState should do it for you
p
nope
as I explained, it's like if compose is destroying the screen (even the viewmodel) each time I go to other screen and come back
z
Is any state being restored on back?
p
I don't understand you
z
If you have something like
rememberSaveable { mutableIntStateOf(0) }
, increment it, then navigate forward and back, does the counter get restored?
p
mmm, I have a lot of things on my viewmodel, for example, texts for fields, and also I have a lot of things on the uistate, and all of them are being restored when coming back, the only think doesn't work is the lazy list state
z
Which nav library are you using?
p
Copy code
navigationCompose = "2.8.9"
z
Jetpack nav should definitely support this, weird.
If you can make a minimal reproducer, I would file a bug
p
let me try tomorrow, thank you
Hi again zach, I solved it, but not with rememberLazyListState
It was necessary to add this when navigating with my navhost:
Copy code
popUpTo(navController.graph.startDestinationId) {
    saveState = true
}
with that, scrolls are remembered even without using rememberLazyListState
without that, even using rememberLazyListState didn't worked
what do you think?
z
i am not really familiar with the jetpack nav library, but that makes sense 😅
if the nav library requires you to opt-in to state saving, and you don't opt-in, state isn't saved, checks out