General: Smoother multi-select on tool lists#2477
Merged
Merged
Conversation
Replace rememberSelection<T>() (MutableState<Set<T>>) with a @stable SelectionState<T> holder exposing per-id membership via @composable isSelected(id) backed by derivedStateOf, plus isActive/count as derivedStateOf. Toggling one row now recomposes only that row instead of the whole visible window: previously every visible item subscribed to the single Set state and re-ran its leaf work (thumbnails, file-size/date formatting, plurals) on every toggle. Migrated all 13 call sites across corpsefinder, systemcleaner, deduplicator, analyzer, squeezer, appcontrol, appcleaner, exclusion and swiper. Screen-scope aggregate reads (Squeezer savings, Analyzer selected-items/none-inaccessible) moved into their top-bar composables so they no longer re-invalidate the list. Container composables (CorpseContent, AppJunkPage, FilterContentPage, ClusterContent) now take the holder. AppControl pendingExportIds migrated too, so the old helper could be deleted. Deduplicator details: preserved the keep-one delete cap on toggle/long-press/select-all, and additionally re-apply it after the prune so a cluster shrinking under a held selection (or a restored selection against a smaller cluster) can no longer let a delete take the whole cluster. Adds SelectionState unit tests plus a Robolectric recomposition-isolation test proving a steady-active toggle recomposes only the toggled row.
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.
What changed
When you select multiple items in a tool's list or detail screen (apps, files, duplicates, exclusions…), tapping each item used to make the whole visible list redo work for every row — re-loading thumbnails and re-formatting sizes/dates/counts on every tap. On lower-end devices that showed up as lag while multi-selecting. Now tapping an item only updates that one row, so multi-select stays smooth even on long lists. Nothing about how selection looks or behaves changes.
Technical Context
Set(selection.contains(id)/selection.isNotEmpty()) inside itsitems{}lambda, so every visible row subscribed to the singleMutableState<Set<T>>and recomposed on every toggle — re-running its leaf work (thumbnails,formatShortFileSize, plurals, date formatters).@Stable SelectionState<T>holder (app-common-ui/.../compose/selection/) exposing per-id membership via@Composable isSelected(id)backed byderivedStateOf, so only the row whose membership flips recomposes.isActive/countarederivedStateOftoo, so the container/top bar recompose only on the selection-mode transition / count change, not on every toggle. Replaces and deletes the oldrememberSelectionhelper.CorpseContent/AppJunkPage/FilterContentPage/ClusterContentnow take the holder. AppControl'spendingExportIdswas migrated too so the old helper had no remaining callers.selectedDupesdelete-target model (a separate VM-owned mechanism, notrememberSelection).Review guidance
SelectionState.isSelected—SelectionStateIsolationTestproves a steady-active toggle recomposes only the toggled row, and documents the expected all-row recompose on the empty↔non-empty transition.DeduplicatorDetailsScreen+ClusterContent(cluster clip viaselectionEnabled && isSelected, the cap re-application after prune).Verification
SelectionStateunit tests + Robolectric recomposition-isolation test.