I am writing a file manager, when I click on the f...
# compose
c
I am writing a file manager, when I click on the folder, the LazyColumn items data will be reloaded to enter the folder, then how can I remember the list position of the previous page so that I can automatically display it to the correct one when I return next time position, for example, the path
a/b/c
, when go to
c
, I should save the location of
a
and
b
z
How are you navigating between pages?
c
@Zach Klippenstein (he/him) [MOD] Just replace the data through the viewModel to reorganize the
LazyColumn
, probably a fake navigation implementation
z
(you don’t need to tag people in threads, they already get notified 🙂 )
Yea, i believe the lazy list scroll state uses compose’s
SaveableStateRegistry
machinery to save and restore scroll position. This requires support from your navigation infra. Jetpack Nav will support this, as should other real navigation libraries (compose-backstack, compose-router i think, etc), but if you’re building one yourself it’s going to take a little extra work.
i
It sounds like, if you're using the same
LazyColumn
, then you'll need to hoist and save the
LazyListState
for each of your lists (i.e., one for
a
, one for
b
, etc.), just passing down the right state with the right contents of the list as you swap between them
c
For some reasons I cannot use navigation, it needs to go back and forward, and navigation only has a backstack
If there are too many file paths (pages), will holding a
LazyListState
for each lists cause performance problems? Maybe just save its
initialFirstVisibleItemIndex
and
initialFirstVisibleItemScrollOffset
for each lists?
i
The
LazyListState
itself is very small; you'd want to hoist the whole object
🙏 2
c
That will be convenient! Thank you for your answer