I want to hide my bottom nav on certain screens. R...
# compose
f
I want to hide my bottom nav on certain screens. Right now I'm using the route to compare destinations. This doesn't work with optional arguments anymore, because the
route
property of the `navBackStackEntry`'s
destination
contains the argument syntax. But in order to add arguments later, my own route string needs to be the "base" route without arguments.
Copy code
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
val hideBottomNav = fullScreenDestinations.any { destination ->
    destination.route == currentDestination?.route
}
So here
destination.route
=
"AddEditTask"
while
currentDestination.route
=
"AddEditTask?taskId=taskID"
. How else could I check what destination we are currently on? using
contains
to compare a sub-string seems error-prone.
i
Is there a reason you went with a route based approach rather than an argument based approach? https://kotlinlang.slack.com/archives/CJLTWPH7S/p1627955172336400?thread_ts=1627937745.328400&cid=CJLTWPH7S
f
I followed the instructions for nav arguments with Compose
your link leads me to XML code
ah now I realize that you are not referring to the way I pass arguments, but to the way I check for full-screen destinations
I'll try to implement that, thank you!
@Ian Lake Like this?
Copy code
composable(
            route = BottomNavDestination.Timer.route,
            arguments = listOf(
                navArgument(ARG_SHOW_BOTTOM_NAV) {
                    type = NavType.BoolType
                    defaultValue = true
                }
            )
        ) {
            TimerScreen()
        }
Copy code
Scaffold(
        bottomBar = {
            val navBackStackEntry by navController.currentBackStackEntryAsState()
            val currentDestination = navBackStackEntry?.destination
            val showBottomNav = navBackStackEntry?.arguments?.get(ARG_SHOW_BOTTOM_NAV) == true

[...]
i
Yep. Although you should be able to drop the explicit
BoolType
- it should be automatically determined from the default value
f
Cool, didn't know that! Thank you very much!