Can I ask a question re Jetpack Compose Navigation 3, please?

I am using a `NavDisplay` inside a "global" `Scaffold` with a `TopAppBar`, because that allows me to have an app-wide menu.

But I would also like the `TopAppBar` to display a different title depending on the navigation backstack.

How do I do that?

#BuildInPublic #Android #Kotlin #JetpackCompose #Nav3 #FollowerPower

@jexner I believe that the recommendation would be to not have that Scaffold() be global. Extract the menu into a separate composable that can be used from the per-screen Scaffold() and TopAppBar(). That gives you more flexibility (e.g., per-screen app bar actions).

Otherwise, perhaps you could have your entry() lambdas inside your NavDisplay() entryProvider update pageTitle, if the entry is the determining factor for the title.

@commonsguy I thought that, too.

But then I have to pass the 'Navigator' into a bunch of separate menu Composables, and that looks ugly to me. Or is there a way to do that in an elegant way?

The entries are partially injected, following the recipe (https://github.com/android/nav3-recipes/tree/main/app/src/main/java/com/example/nav3recipes/modular/hilt), which means I cannot add anything related to pageTitle into those from other modules, correct?!

nav3-recipes/app/src/main/java/com/example/nav3recipes/modular/hilt at main ยท android/nav3-recipes

Implement common use cases with Jetpack Navigation 3 - android/nav3-recipes

GitHub

@jexner If the issue is literally the Navigator, perhaps instead you pass in an onMenuItemClicked lambda slot parameter to those composables, which they invoke as appropriate.

I am guessing that some people will hoist the Navigator into a composition local to avoid passing it around directly; I do not know if that is a good idea or not.

@commonsguy That first method sounds like a good way, cool!

I had wondered about callbacks, but this could be just one, and it could take some `sealed interface NavEvent` items or so.

Hmm... have to try that...