Skip to content

Instantly share code, notes, and snippets.

@RaheemJnr
Last active October 10, 2021 08:47
Show Gist options
  • Save RaheemJnr/4249df303e5477750a0be0dea87d176d to your computer and use it in GitHub Desktop.
Save RaheemJnr/4249df303e5477750a0be0dea87d176d to your computer and use it in GitHub Desktop.
@Composable
fun BottomNav(navController: NavController) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination
BottomNavigation(
modifier = Modifier
.padding(12.dp, 0.dp, 12.dp, 0.dp)
.height(100.dp),
//backgroundColor = Color.White,
elevation = 0.dp
) {
items.forEach {
BottomNavigationItem(
icon = {
it.icon?.let {
Icon(
imageVector = it,
contentDescription = "",
modifier = Modifier.size(35.dp),
//tint = Color.Gray
)
}
},
label = {
it.title?.let {
Text(
text = it,
//color = Color.Gray
)
}
},
selected = currentRoute?.hierarchy?.any { it.route == it.route } == true,
selectedContentColor = Color(R.color.purple_700),
unselectedContentColor = Color.White.copy(alpha = 0.4f),
onClick = {
it.route?.let { it1 ->
navController.navigate(it1) {
// 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
}
}
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment