Hi everyone, hope you are all doing well. I am usi...
# compose-destinations
d
Hi everyone, hope you are all doing well. I am using compose-destinations in my project. I have a somewhat dynamic
TopAppBar
and navigation should change depending on the screen that's displayed. In my `MainActivity`'s
setContent
I use
DestinationsNavHost
and I pass callbacks to all my functions using
destinationsNavigator
. Now, the issue is that I can't access destinationsNavigator in Place where my
TopAppBar
is
Copy code
Theme {
     Scaffold(
         topBar = {
            onIconClicked = {
               NAVIGATION SHOULD HAPPEN
            }
         }
     ) {

       DestinationsNavHost {
          composable {}
          composable {}
       }
     }
}
How do I "inject" the navigator in topbar? Note: one solution I employed is have a
topAppBarNavigationLambda
and passing it as state, updating it when navigation happens for each
composable
section
r
If you’re not navigating from a screen to a screen, you need to use NavController. You get that the same way you would with official compose navigation, by calling rememberNavController and passing the result of that call to DestinationsNavHost. In latest alpha/beta versions, you can then do
NavController.rememberDestinationsNavigator()
To then get a DestinationsNavigator from that NavController. Which has all compose destinations specific APIs. On current stable versions and older, you have extension functions of NavController that act similar to DestinationsNavigator methods.
s
@Djuro I think what you are trying to build is similar to this https://composedestinations.rafaelcosta.xyz/v2/common-use-cases/bottom-bar-navigation