https://kotlinlang.org logo
n

natario1

03/03/2021, 12:50 PM
Anyone confused by the Integration with the bottom nav bar example for Navigation. Because of the nav options used, computing the current route as
navBackStackEntry?.arguments?.getString(KEY_ROUTE)
gives null when you go back to the start tab, so the nav item won't be highlighted. What works is
Copy code
val backstackRoute = backstackEntry?.arguments?.getString(KEY_ROUTE)
val fallbackRoute = runCatching {
    nav.graph.findNode(nav.graph.startDestination)!!.arguments[KEY_ROUTE]!!.defaultValue
}.getOrNull()
val currentRoute = backstackRoute ?: fallbackRoute
(runCatching otherwise nav.graph can throw on first composition). What's wrong here? Do we need at least a better API for peeking the current route?
💯 2