Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aware nested navigation when getting current destination #7

Open
mkeeda opened this issue Aug 25, 2021 · 0 comments
Open

Aware nested navigation when getting current destination #7

mkeeda opened this issue Aug 25, 2021 · 0 comments

Comments

@mkeeda
Copy link
Owner

mkeeda commented Aug 25, 2021

Is this code safety?

val currentScreen = Screen.fromRoute(route = backStackEntry.value?.destination?.route)

In the document,

The selected state of each BottomNavigationItem can then be determined by comparing the item's route with the route of the current destination and its parent destinations (to handle cases when you are using nested navigation) via the hierarchy helper method.
https://developer.android.com/jetpack/compose/navigation#bottom-nav

      val navBackStackEntry by navController.currentBackStackEntryAsState()
      val currentDestination = navBackStackEntry?.destination
      items.forEach { screen ->
        BottomNavigationItem(
          icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
          label = { Text(stringResource(screen.resourceId)) },
          selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
          onClick = {
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant