One Off the Slack: Saving Multiple States for a List
Rin Orz asked:
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 toc, I should save the location ofaandb
[to navigate between pages, I] just replace the data through the viewModel to reorganize the
LazyColumn, probably a fake navigation implementation
Google’s Ian Lake suggested:
It sounds like, if you’re using the same
LazyColumn, then you’ll need to hoist and save theLazyListStatefor each of your lists (i.e., one fora, one forb, etc.), just passing down the right state with the right contents of the list as you swap between them
Rin was concerned about performance:
If there are too many file paths (pages), will holding a
LazyListStatefor each lists cause performance problems? Maybe just save itsinitialFirstVisibleItemIndexandinitialFirstVisibleItemScrollOffsetfor each lists?
Ian indicated that this was not necessary:
The
LazyListStateitself is very small; you’d want to hoist the whole object
Read the original thread in the kotlinlang Slack workspace. Not a member? Join that Slack workspace here!