Thread
#compose
    gsala

    gsala

    1 year ago
    The example in https://developer.android.com/jetpack/compose/navigation#bottom-nav to integrate the new navigation and BottomNavView together doesn't work properly. Is it even right to model the "horizontal" navigation pattern of a bottom navigation menu, with a navigation backstack?
    j

    jaqxues

    1 year ago
    the code snippet pops the back stack and doesnt update
    currentRoute
    , Add the popBackStack under the if and it should work fine I think.
    gsala

    gsala

    1 year ago
    if (currentRoute != screen.route) {
        navController.navigate(screen.route)
    }
    navController.popBackStack(navController.graph.startDestination, false)
    this will always just pop back to the start destination, so I can't navigate to "Apps" then
    j

    jaqxues

    1 year ago
    put both under the if
    gsala

    gsala

    1 year ago
    ah, inside the if. Got it. Thanks 👍
    if (currentRoute != screen.route) {
        navController.popBackStack(navController.graph.startDestination, false)
        navController.navigate(screen.route)
    }
    this seems to work
    j

    jaqxues

    1 year ago
    uhm yeah, inside, sorry. Was modelling under with indentation
    gsala

    gsala

    1 year ago
    Maybe you also know this. If I need to navigate from a composable deep in the hierarchy, should I pass the navController "down", or the click event "up"
    j

    jaqxues

    1 year ago
    You are asking for Guidelines, but I guess we are both still learning how to handle this kind of stuff. I would personally pass a onClick event up if the Composable is really deep inside the hierarchy and pass the NavController down to a reasonably deep Composable. (Maybe you need a navController in another Composable, so pass down the navController to that and do the rest with onClick actions)
    i

    Ian Lake

    1 year ago
    The pattern the docs do is correct: the start destination should always be on the back stack, but other tabs should not keep building up the back stack over and over again as per the material design guidelines. That means in your two tab examples, the stack should be either:- Build alone (when you select the Build tab, the popBackStack would pop anything other than Build off the stack, then the if would prevent a second copy from being created) - Build -> Apps (when you select the Apps tab, every other tab, such as a third tab, would be popped off the stack, making the stack only Build, then you'd add Apps to the stack)
    I do agree that having an early return for handling the reselection case makes a lot of sense though. Do you mind filing an issue so we can add that logic into the example?
    If you look at the testing section of the docs, you'll see we recommend the "passing an onClick up" approach
    gsala

    gsala

    1 year ago
    @Ian Lake Filed it here: https://issuetracker.google.com/issues/172112081. Hopefully that was the right place
    i

    Ian Lake

    1 year ago
    Filing it against AndroidX -> Navigation would have been better, but I'll reroute it to the right person