https://kotlinlang.org logo
#compose
Title
# compose
a

Archie

11/30/2021, 2:03 PM
Hi Guys, Whats the best approach for NavGraph where a combination of Persistent TopAppBar and/or BottomNavigationBar but you also need a Full Screen that provide its own TopAppBar/BottomNaivgationBar?
Would it be better to created nested graphs? Like so?
Copy code
// For Full Screen Screens
NavGraph(
   ...
) {
   Scaffold(
       topbar = { ... },
       ...
   ) {
      // For screens with persistent TopBar/BottomBar
      NavGraph(
          ...
      ) {
          ...
      }
   }
}
i

Ian Lake

11/30/2021, 6:22 PM
We've never recommended nested NavHosts as a solution to this (you end up with a lot more of a mess when it comes to deep linking, state management, etc); there's been a number of threads if you search or bottom nav about using your source of truth - the current destination of the NavController - to determine what global nav should or should not appear.
a

Archie

11/30/2021, 11:26 PM
Thanks @Ian Lake. Are there any official guide or documentation for this matter?
i

Ian Lake

12/01/2021, 12:33 AM
In the docs for listening for navigation events, we use showing/hiding your global UI (like a bottom nav) as the example. Of course, everything is easier in the Navigation Compose world, where you get
navController.currentBackStackEntryAsState()
which is how we synchronize the bottom nav with NavController's state
❤️ 1
a

Archie

12/01/2021, 1:25 AM
@Ian Lake can I show you an example of a scenario/project where I think this approach doesn't work specially with animation? Or maybe I am just doing it wrong? Would you be open for that?
i

Ian Lake

12/01/2021, 2:03 AM
We've specifically talked about timing global navigation animations to run after any animations ran on the content within a screen (and even adding an API specifically to get those type of state changes): https://github.com/google/accompanist/issues/633#issuecomment-942988181
❤️ 1
Until actual shared element support is added (both at the Compose and Navigation layer), there will be types of animations that won't be possible
K 1
a

Archie

12/01/2021, 3:15 AM
I see. Thank you very much. This is very informational. Hope we could have Shared Element Transition soon.