Description
SearchScreen uses 17 collectAsStateWithLifecycle() calls at the top-level composable. Key issues:
stablePlayerState changes on every play/pause/skip, recomposing the whole screen even when only the now-playing indicator needs updating
selectedSongIds, selectedSongs, and isSelectionMode are three separate flows for one logical concern
favoriteSongIds (a full Set<String>) is collected at the top level
- Album and genre selection state is held in local
remember {} — lost on configuration change
Location
app/src/main/java/com/theveloper/pixelplay/presentation/screens/SearchScreen.kt (1,736 lines)
Expected Behavior
State collection should be scoped to the composables that actually use it. Related state should be merged into single flows. Album/genre selection should be ViewModel-backed.
Actual Behavior
Any state change in any of the 17 flows triggers recomposition of the entire search screen tree.
Fix
- Move
stablePlayerState collection into the now-playing indicator composable
- Merge
selectedSongIds/selectedSongs/isSelectionMode into a single MultiSelectionState flow
- Move album/genre selection to ViewModel-backed state holders
- Use
derivedStateOf for derived state to reduce emission frequency
Description
SearchScreenuses 17collectAsStateWithLifecycle()calls at the top-level composable. Key issues:stablePlayerStatechanges on every play/pause/skip, recomposing the whole screen even when only the now-playing indicator needs updatingselectedSongIds,selectedSongs, andisSelectionModeare three separate flows for one logical concernfavoriteSongIds(a fullSet<String>) is collected at the top levelremember {}— lost on configuration changeLocation
app/src/main/java/com/theveloper/pixelplay/presentation/screens/SearchScreen.kt(1,736 lines)Expected Behavior
State collection should be scoped to the composables that actually use it. Related state should be merged into single flows. Album/genre selection should be ViewModel-backed.
Actual Behavior
Any state change in any of the 17 flows triggers recomposition of the entire search screen tree.
Fix
stablePlayerStatecollection into the now-playing indicator composableselectedSongIds/selectedSongs/isSelectionModeinto a singleMultiSelectionStateflowderivedStateOffor derived state to reduce emission frequency