I'm trying to use jetpack compose navigation, but I had a problem in understanding nested navigation and layout the scaffold.
I had an app screen structure like this
root
├─ A
├─ B <- Had a bottom navigation bar
│ ├─ C
│ ├─ D
and this is the rough specs
- The root would be in the MainActivity and have a NavHost and scaffold.
- The app bar in A and B would be different.
- There would be a bottom nav bar in B, which can be used to navigate between C and D
I have been looking through the docs and StackOverflow, from what I get it is best to just put the scaffold outside of NavHost.
But, for my case how can I update the app bar in A and B it if I don't get an access to the scaffold inside A & B? I can only think to make a branching in the scaffold like the code below
Scaffold(
scaffoldState = scaffoldState,
topBar = {
when {
currentDestination?.parent?.route == "Home" -> {
TopAppBar(
title = {
Text("Home")
},
)
}
currentDestination?.route == "Other screen" -> {
....
}
Also I need an access scaffold state in A.
So what is the best approach to solve this kind of problem?