Merged
Conversation
This commit introduces several significant performance optimizations to the `UnifiedPlayerSheet` and its related components, focusing on reducing redundant compositions and deferring the rendering of expensive UI elements.
### Key Changes:
1. **Deferred Composition (`DeferAt` and `DeferUntil`):**
- New composable helpers `DeferAt` and `DeferUntil` have been introduced to delay the composition of UI subtrees until specific conditions are met (e.g., the player sheet is expanded beyond a certain fraction).
- The `AlbumCarouselSection` and `PlayerSongInfo` (title/artist) are now only composed when the sheet expansion is greater than 12% and 20% respectively, significantly reducing initial composition cost.
2. **Smoothed Progress Bar (`rememberSmoothProgress`):**
- A new `rememberSmoothProgress` utility has been created to optimize the `WavyMusicSlider`.
- It reduces the frequency of progress updates from the `ViewModel` (sampling at ~5 FPS) while using `animateFloatAsState` to create a visually smooth 60 FPS animation on the UI.
- This drastically cuts down on recompositions triggered by frequent position updates, especially when the player is not fully expanded.
3. **Conditional Marquee Text (`AutoScrollingTextOnDemand`):**
- A new `AutoScrollingTextOnDemand` composable now checks if the text actually overflows its container *before* applying the expensive auto-scrolling marquee effect.
- This prevents unnecessary performance overhead for shorter titles and artist names that don't need to scroll.
4. **Neighboring Album Art Prefetching (`PrefetchAlbumNeighbors`):**
- A new `PrefetchAlbumNeighbors` composable has been added, which proactively enqueues Coil image requests for the album art of songs adjacent to the current one in the queue.
- This improves the user experience by ensuring that album art is likely already in the memory cache when the user swipes through the carousel.
5. **General Code Cleanup:**
- Removed a significant amount of dead and commented-out code from `UnifiedPlayerSheet.kt`.
- Optimized ripple effects on player controls by reusing a single `Indication` instance.
This commit introduces significant performance optimizations and refactorings to the `UnifiedPlayerSheet`, focusing on animations, gesture handling, and rendering efficiency.
### Key Changes:
1. **Optimized Player Sheet Animations:**
* Introduced a custom `rememberExpansionTransition` composable to manage animations tied to the sheet's expansion fraction. This replaces multiple `animate*AsState` calls with a more efficient, unified transition, reducing recompositions.
* The elevation (`playerAreaElevation`) and mini-player alpha (`miniAlpha`) are now driven by this unified transition.
2. **Improved Drag Gesture Logic:**
* The vertical drag gesture handler (`detectVerticalDragGestures`) has been refactored for clarity and performance.
* It now uses `rememberUpdatedState` for values like `sheetCollapsedTargetY`, `sheetExpandedTargetY`, and `showPlayerContentArea`. This ensures the drag logic always references the latest values without needing to restart the gesture detector, making it more stable and efficient.
3. **Conditional & Optimized `WavyMusicSlider`:**
* A new `isWaveEligible` parameter was added to `WavyMusicSlider`. This boolean, tied to the player sheet's expanded state, disables the wave effect and its underlying `rememberInfiniteTransition` when not visible. This significantly reduces CPU usage and invalidations when the player is collapsed.
* The wave drawing logic was improved to use `quadraticBezierTo` instead of `lineTo`, resulting in a much smoother sine wave animation with fewer drawing artifacts.
4. **Album Art Prefetching Strategy:**
* Implemented two new composables, `PrefetchAlbumNeighbors` and `PrefetchAlbumNeighborsImg`, to proactively load album art for adjacent songs in the queue.
* Prefetching is triggered when the user starts expanding the player sheet or swipes the album carousel, ensuring cover art is ready before it comes into view and improving perceived performance.
5. **General Code Cleanup:**
* Removed unused code, commented-out blocks, and unnecessary recomposition triggers throughout `UnifiedPlayerSheet.kt`.
* Added `key(song.id)` to items in `AlbumCarouselSection` to help Compose uniquely identify and manage items during recomposition.
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.
No description provided.