- Notifications
You must be signed in to change notification settings - Fork 5.3k
[JetNews] Fix state saving with drawer #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
1f2622c to 515f17f Compare manuelvicnt reviewed Sep 14, 2021
| // from multiple screens. An event to open the drawer is passed down to each | ||
| // screen that needs it. | ||
| val scaffoldState = rememberScaffoldState() | ||
| val drawerState = rememberDrawerState(DrawerValue.Closed) |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move these variables closer where they're used. Shouldn't be above BWC
Contributor Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated as part of the extraction into rememberSizeAwareDrawerState
manuelvicnt approved these changes Sep 14, 2021
Contributor Author
| Thanks @manuelvicnt ! |
manuelvicnt pushed a commit that referenced this pull request Oct 13, 2021
* [Jetnews] Snackbars large screens support (#631) * [Jetnews] Add WindowSize breakpoints (#632) * [Jetnews] Add NavRail for large screens (#636) * Add initial large screen exploration * PR feedback and refine integration with navrail * Fix formatting and tests * Use rememberUpdatedState for notifyInput * Add remember for windowSize * [Jetnews] Interests screen LS support (#639) * [Jetnews] Large screen support for the Interests tab (#641) * [JetNews] Fix state saving with drawer (#653) * [JetNews] Fix state saving with drawer * Extract into rememberSizeAwareDrawerState * [JetNews] Convert navrail/drawer decision to use currentWindowMetrics (#654) * [JetNews] Convert navrail/drawer decision to use currentWindowMetrics * Move window metrics helpers to WindowSize.kt * [Jetnews] Better TopAppBar in large screens (#650) * [Jetnews] Move NavRail to top level component (#655) * [JetNews] Update window size breakpoints (#658) * [JetNews] Adjust medium behavior (#657) * [JetNews] Adjust medium behavior * Move column decision out of BoxWithConstraints * Follow my own rule for isDrawerActive * Update for PR feedback * Spotless apply * Add TODO for BoxWithConstraints usage * [JetNews] Replace currentWindowMetrics flow with synchronous calculation (#660) * [Jetnews] Consolidate compact and medium layouts (#659) * [Jetnews] Add space between NavRail icons (#663) * [Jetnews] Custom interests layout (#665) * [JetNews] Move window size calculation to activity level (#667) * [JetNews] Move window size calculation to activity level * Re-order WindowSize functions * Fix formatting * Merge main into ls (#672) * Implemented swipe to delete for Jetsnack cart * Replace logic for SwipeToDismiss composable Added Animated visibility as well * Requested adjustments * Removed Opt in * Spotless apply * PR fixes * Swipe to delete polish * Spotless * Removed unnecessary Row * Code polish * feat : improve UX by setting Button semantic role to play image button fix : fix not beeing able to move from CategoryPodcast to EpisodeList with Talkback feat: merge podcast category card with podcast title * Break long lines * Content to trailing lambda, added comments * Fix invalid neutral color #591 * [Jetnews] Showcase PreviewParameterProvider usage. * [Jetnews] Move PostPreviewParameterProvider.kt and add documentation * Fix kdoc format * [Jetsnack] Snackbar support (#645) * Finish checksum.sh sentence (#622) * [All] Update to Compose 1.0.2 * Spotless apply * [All] Revert to previous version of ktlint * [Jetsnack] Add state holder to JetsnackApp (#646) * fix : fixing formating issue * Update Compose Material Catalog AOSP link (#656) * [Crane] Use createEmptyComposeRule for test with injection * [All] Update to Compose 1.0.3 (#671) * [Jetnews] Update to Compose 1.1.0-alpha05 * [Jetnews] Spotless Co-authored-by: Angeles <angeles.bilbao6@gmail.com> Co-authored-by: DEMEY Fanny <fanny.pluvinage@gmail.com> Co-authored-by: Chris Sinco <csinco@google.com> Co-authored-by: Jolanda Verhoef <JolandaVerhoef@users.noreply.github.com> Co-authored-by: Jose Alcérreca <JoseAlcerreca@users.noreply.github.com> Co-authored-by: Alex Vanyo <vanyo@google.com> Co-authored-by: Nick Rout <nickrout@google.com> * [Jetcaster] Add tabletop posture support to the Player screen (#676) Co-authored-by: Alex Vanyo <vanyo@google.com> Co-authored-by: Angeles <angeles.bilbao6@gmail.com> Co-authored-by: DEMEY Fanny <fanny.pluvinage@gmail.com> Co-authored-by: Chris Sinco <csinco@google.com> Co-authored-by: Jolanda Verhoef <JolandaVerhoef@users.noreply.github.com> Co-authored-by: Jose Alcérreca <JoseAlcerreca@users.noreply.github.com> Co-authored-by: Nick Rout <nickrout@google.com>
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.
Fixes the state saving (via
rememberSaveable) throughout the app.Per the design, we conditionally want to allow the drawer to be shown based on the size of the screen. With the current approach we conditionally passed
nullor the drawer content to a top-levelScaffold, which would then allow the drawer to be hidden or shown. If we don't want the drawer to be shown, we instead show the nav rail.This approach has a subtle problem due to the implementation of
Scaffold: when we switch the drawer content betweennulland non-null, we are changing the location of where the content lambda (containing everything else in the app) is called.This changes all of the keys that
rememberSaveableautomatically uses, which is seen as scroll positions not being saved when switching between orientations that allow or disallow showing the drawer.To workaround this, I replaced the top-level
Scaffoldwith aModalDrawer(since that was the only functionality we were using via the top-levelScaffolddirectly anyway). Crucially, thisModalDraweris always called, even if we don't want to allow showing the drawer. This allows calling the content for the rest of the app in exactly one source location. To avoid showing the drawer when we want to show the nav rail instead, we switch between a real, rememberedDrawerStateand a fixed-to-closed drawer state.