Skip to content

Commit

Permalink
Merge "Update BottomBarNavDemo to new navigation helper methods" into…
Browse files Browse the repository at this point in the history
… androidx-main
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Jun 4, 2021
2 parents c84463e + e87debf commit 3845482
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import androidx.compose.material.icons.filled.Favorite
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
Expand All @@ -50,17 +52,17 @@ fun BottomBarNavDemo() {
bottomBar = {
BottomNavigation {
val navBackStackEntry = navController.currentBackStackEntryAsState().value
val entryRoute = navBackStackEntry?.destination?.route
val currentDestination = navBackStackEntry?.destination
items.forEach { (name, route) ->
BottomNavigationItem(
icon = { Icon(Icons.Filled.Favorite, contentDescription = null) },
label = { Text(name) },
selected = entryRoute == route,
selected = currentDestination?.hierarchy?.any { it.route == route } == true,
onClick = {
navController.navigate(route) {
launchSingleTop = true
restoreState = true
popUpTo(navController.graph.startDestinationId) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
}
Expand Down

0 comments on commit 3845482

Please sign in to comment.