Did anything changed regarding having single NavHo...
# compose
k
Did anything changed regarding having single NavHost in compose? How do I structure the graph when I have 3 subgraphs: • splash • onboarding • home With fragments navigation it was normal to have login flow in separate navigation graph and then you would navigate to home graph with bottom navigation. Am I forced to change visibility of every scaffold component depending on current route and set it up like this?
Copy code
@Composable
fun MainNavHost(
    ...
) {
    Scaffold(
        bottomBar = ...
    ) {
        NavHost(
            navController = navController,
            startDestination = startingDestination.route,
        ) {
            splashGraph()
            onboardingGraph(factory)
            bottomNavigationGraph(factory, paddingValues)
        }
    }
}
Or I can have a NavHost for my bottomNavigationGraph and scaffold inside?
s
Splash shouldn’t be a destination in the first place, but just using
androidx.core:core-splashscreen
https://developer.android.com/develop/ui/views/launch/splash-screen/migrate For onboarding, in theory you can achieve this by keeping your home screen as your start destination, and conditionally navigate to your onboarding in certain situations, this video

https://youtu.be/09qjn706ITA?t=432

discusses about how to handle login destination this way, which would apply to onboarding for you. In practice it may be a bit tricky, but in general the navigation library doesn’t really want you to keep more than one NavHost. Follow this message https://kotlinlang.slack.com/archives/CJLTWPH7S/p1679869124943059?thread_ts=1679868162.988109&cid=CJLTWPH7S and the ones linked back to get more context
k
Ok, so manipulating visibility of scaffold components. Is there an explanation or example how to change navGraph as you would do with fragment navigation?
s
I am not familiar with fragment navigation so not sure what you mean
i
The guidance has not changed - you should have never been doing that in the Fragment world either. You'll note the exact example from the Navigation with Fragment documentation was about showing and hiding the bottom bar based on what destination you are on
👍 1