If a bottom tab acts as a top level destination fo...
# compose
j
If a bottom tab acts as a top level destination for a series of different screens, would this be the correct use-case for a nested graph? If so, how is it possible to determine if the current route belongs to this nested graph? The docs show an example determining if the bottom tab icon is selected by checking if
currentRoute == screen.route
, but what if we’re on a nested route beneath this? https://developer.android.com/jetpack/compose/navigation#bottom-nav
i
Well, if you want to determine what nested graph something is in, you'd look at
navBackStackEntry.destination.parent
- that's the parent NavGraph. I don't think we fill out the route in that as of yet, but the plan is for
route
to become a field on
NavDestination
itself (just like
id
is right now), which would make this quite a bit easier
j
Cool thanks, having
route
available on
NavDestination
would be really helpful. As a workaround for now I’ve just added a property
children
to my
Screen
sealed class which contains a list of child routes. Then to determine if a bottom nav item is selected I just check if
currentRoute
exists in
children