Florian
08/09/2021, 11:36 AMjossiwolf
08/09/2021, 12:51 PMFlorian
08/09/2021, 1:03 PMFlorian
08/09/2021, 1:05 PMIan Lake
08/09/2021, 1:47 PMFlorian
08/09/2021, 1:49 PMonClick
part of the bottom nav items with if (currentDestination?.route != destination.route)
Florian
08/09/2021, 1:49 PMFlorian
08/09/2021, 1:49 PMColton Idle
08/09/2021, 2:15 PMTin Tran
08/09/2021, 2:24 PM@OptIn(ExperimentalAnimationApi::class)
@Composable
fun BottomBar(
entry: NavBackStackEntry?,
navController: NavController
) {
val list = listOf(Screens.Home, Screens.MyGame, Screens.Schedule, <http://Screens.Shop|Screens.Shop>, Screens.Account)
val currentRoute = entry?.destination?.route
AnimatedVisibility(
visible = currentRoute in list.map { it.route },
enter = slideInVertically({ it * 2 }),
exit = slideOutVertically({ it * 2 }, snap())
) {
BottomNavigation(
backgroundColor = Color.White
) {
list.forEach { screen ->
val selected = currentRoute == screen.route
val iconRes = screen.icon ?: R.drawable.ic_home
val color by animateColorAsState(targetValue = if (selected) ActionOrange else DarkGray)
BottomNavigationItem(
icon = {
Icon(
painter = painterResource(id = iconRes),
contentDescription = "",
tint = color
)
},
label = {
Text(
text = screen.name.uppercase(),
style = TextStyle(
fontFamily = robotoFamily,
fontWeight = FontWeight.W700,
fontSize = 10.sp
),
modifier = Modifier
.padding(top = 8.dp),
color = color
)
},
selected = selected,
onClick = {
navController.navigate(screen.route) {
navController.graph.startDestinationRoute?.let {
popUpTo(it) {
saveState = true
}
}
launchSingleTop = true
restoreState = true
}
}
)
}
}
}
}
Florian
08/09/2021, 3:29 PM