Marcello Galhardo
07/29/2021, 11:29 AMIan Lake
07/29/2021, 4:36 PMMarcello Galhardo
07/29/2021, 4:59 PMIan Lake
07/29/2021, 5:14 PMIan Lake
07/29/2021, 5:15 PMIan Lake
07/29/2021, 5:25 PMMarcello Galhardo
07/29/2021, 8:50 PMval navController = rememberNavController()
// Screen level
Scaffold(
bottomBar = {
BottomNavigation {
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 = {
navController.navigate(screen.route) {
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
// Avoid multiple copies of the same destination when
// reselecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
restoreState = true
}
}
)
}
}
}
) { innerPadding ->
// -> Here is the nested NavHost <-
NavHost(navController, startDestination = Screen.Profile.route, Modifier.padding(innerPadding)) {
composable(Screen.Profile.route) { Profile(navController) }
composable(Screen.FriendsList.route) { FriendsList(navController) }
}
}
https://developer.android.com/jetpack/compose/navigation#bottom-nav
My understanding from the example above is that: if I need to do a "full screen" navigation I will use the root NavHost but if I'm at (example) a home screen with bottom navigation, I need a second NavHost inside... 🤔Ian Lake
07/29/2021, 8:57 PMMarcello Galhardo
07/29/2021, 9:16 PM