Matti MK
06/21/2022, 11:49 AMScaffold
.
• Graph1 has no scaffold
• Graph2 has typical bottom scaffold
• Graph3 has top and bottom scaffolds, but only with Graph3
routes
I am wondering how to build this. Should I have multiple Scaffold
and NavHost
or instead use just one NavHost
and one Scaffold
, switching out the Scaffold
content based on current Graph? Thank you 🙂kotlinforandroid
06/21/2022, 11:58 AMScaffold
s will result in flickering if you change the nav destination to one that also contains a Scaffold
. If you want the best experience, you probably want to have a single NavHost that contains all graphs. And change the content of the scaffold dynamically.Matti MK
06/21/2022, 12:11 PMNavHost
and Scaffold
. This works decently but not especially smoothly.
Now I’m adding Graph3, which raised the question whether I should do a refactor, but I’m not finding any reasonable resources to make an educated guessColton Idle
06/21/2022, 12:18 PMMatti MK
06/21/2022, 12:21 PMMainActivity
sets MyApp
as content and there:
MyApp() {
val start = if (isLoggedIn) {
Graph.LoggedIn
} else {
Graph.Login
}
Scaffold( ... ) {
NavHost(startDestination = start.route) {
graph1()
graph2()
}
}
}
However, looking at that I believe it does follow the above guidegraph3
that has completely separate Scaffold
requriements, I wonder if I should contain the logic to swap Scaffold
contents there in MyApp
or refactor to another solution.NavHost
and Scaffold
containing Graph1-3, with conditional Scaffold
content.
This seems to work very well