fix: remember scroll position per folder (#104) - #118
Closed
joelkanyi wants to merge 1 commit into
Closed
Conversation
Keep a per-path map of (firstVisibleIndex, firstVisibleOffset) in FoldersViewModel.
When the LazyColumn observes a folder change, wait for items to load then restore
the saved position if any. Subsequent scroll changes save back to the map.
Path is normalized with trimEnd('/') on both save and lookup. The VM already
normalizes when matching breadcrumb entries, but the raw Folder.path varies
(some paths carry a trailing slash, others don't), which would otherwise key
two distinct entries for the same folder and break restore on back-nav.
Collaborator
Author
|
Superseded by #120, which combines scroll memory with per-path Flow caching. Closing in favor of the combined PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #104.
When navigating in/out of nested folders, the screen now restores the scroll position the user left, per folder path. Each folder remembers its own position so deep trees feel natural to navigate.
How it works
FoldersViewModelholds aMap<String, (index, offset)>keyed by folder path. TheFoldersAndTrackscomposable runs aLaunchedEffectoncurrentFolder.paththat:scrollToItem(index, offset).lazyColumnStateand saves them back through the VM.The order matters. If save monitoring started immediately, the initial
(0, 0)from the freshly-rebuilt paging source would overwrite the real saved value before we could restore it..drop(1)on the snapshotFlow skips that first emission.Path normalization
Folder.pathcarries a trailing slash for some paths (/home/cwilvx/Music/) and not for others (/home/cwilvx/Music). The VM already trims trailing slashes when matching breadcrumb entries, but the rawFolder.pathon_currentFoldervaries depending on entry path. Without normalization in our scroll map the same folder would key two entries, and a back-nav would miss the save. The fix callstrimEnd('/')on both save and lookup.Tested on Pixel 7 Pro
Verified all the cases:
Diag logs during dev confirmed each
restore starthad the right(index, offset)andrestore donefired immediately after items loaded.