Jason Inbody
08/02/2021, 8:01 PM@Composable
fun Navigation(user: FinUser, navController: NavHostController) {
NavHost(navController, startDestination = NavigationItem.MapScreen.route) {
composable(NavigationItem.Account.route) {
Account(user = user)
}
composable(NavigationItem.History.route) {
History(user = user)
}
composable(NavigationItem.MapScreen.route) {
MapScreen(user = user)
}
composable(NavigationItem.Promo.route) {
Promo(user = user)
}
composable(NavigationItem.Help.route) {
Help(user = user)
}
}
}
@Composable
fun BottomNavigationBar(user: FinUser, navController: NavController) {
val items = listOf(
NavigationItem.Account,
NavigationItem.History,
NavigationItem.MapScreen,
NavigationItem.Promo,
<http://NavigationItem.Help|NavigationItem.Help>
)
BottomNavigation(
backgroundColor = MaterialTheme.colors.primary,
contentColor = Color.White
) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route
items.forEach { item ->
BottomNavigationItem(
icon = { Icon(item.icon, contentDescription = item.iconName) },
label = { Text(text = item.title) },
selectedContentColor = Color.White,
unselectedContentColor = Color.White.copy(0.4f),
alwaysShowLabel = true,
selected = currentRoute == item.route,
onClick = {
navController.navigate(item.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
navController.graph.startDestinationRoute?.let { route ->
popUpTo(route) {
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
}
}
)
}
}
}
Colton Idle
08/02/2021, 11:34 PMjossiwolf
08/03/2021, 1:53 PMNavHost
in a Scaffold
and show/hide the bottom nav based on the route. You'll want to look at the currentBackStackEntryAsState
and check if you have a route that should have the bottom nav present. Assuming your NavigationItem
is an enum, you can probably implement something very easily ๐Colton Idle
08/03/2021, 6:25 PMjossiwolf
08/07/2021, 8:00 AMClament John
11/16/2021, 5:31 AM