Skip to content
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

Use one NavHost (with multiple navigation scaffolds) #101

Conversation

jdkoren
Copy link
Contributor

@jdkoren jdkoren commented Sep 25, 2024

Consolidates all the navigation into one NavHost. A NavigationSuiteScaffold is inserted into each destination screen that wants to show navigation UI.

Fixes #96.

jdkoren added 20 commits August 29, 2024 10:04
Previously, the app had a NavHost but didn't actually call navigate.
NavHost's startDestination was read from external state (the currently
selected nav item), which led to some undesirable behaviors.
- NavHost itself was recomposed when selecting a nav item.
- Pressing back always exited the app because you were always at the
  start destination.

Now the NavHost has a stable startDestination, and nav item state is
driven by the NavHostController's current destination. Selecting a nav
item calls navigate, and the user always goes back through the
startDestination before exiting the app.
composable<Route.Settings> {
SocialiteNavSuite(
navController,
modifier = Modifier.sharedElement(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an interesting issue here when everything comes together with Modifier.sharedElement + NavigationSuiteScaffold inside a NavHost.

The Modifier here that is passed to SocialiteNavSuite ends up being applied to the navigation UI (as displayed by the NavigationSuiteScaffold) and all of the contained content.

We don't want all of the contained content to be part of the shared element - the only thing that should be shared is the navigation UI itself. I think we can accomplish that by using the NavigationSuiteScaffoldLayout @Composable and NavigationSuite instead, which allows us to set the shared element Modifier on the navigation UI itself.

ksp = "2.0.0-1.0.21"
lifecycle = "2.8.4"
material3 = "1.2.1"
media3 = "1.4.1"
navigation = "2.7.7"
navigation = "2.8.0-rc01"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think we can update to 2.8.1 now that it is out.

Base automatically changed from jdk/codelab_2024_fixup to codelab_improve_android_experience_2024 October 2, 2024 17:07
@jdkoren jdkoren closed this Oct 15, 2024
@jdkoren jdkoren deleted the jdk/one_nav_host__multiple_nav_scaffolds branch October 15, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants