Skip to content

Instantly share code, notes, and snippets.

@carterhudson
Created September 24, 2021 17:23
Show Gist options
  • Save carterhudson/6cbc91e4b72c847b22377edce61fd591 to your computer and use it in GitHub Desktop.
Save carterhudson/6cbc91e4b72c847b22377edce61fd591 to your computer and use it in GitHub Desktop.
@Composable
private fun BottomNavigationBar(
modifier: Modifier = Modifier,
currentDestination: Screen,
onClick: (id: Screen) -> Unit
) {
val bottomBarVisible = bottomBarNavDestinations.contains(currentDestination)
AnimatedVisibility(
visible = bottomBarVisible,
enter = fadeIn(animationSpec = tween(1000)) + slideInVertically(
initialOffsetY = { it },
animationSpec = tween(1000)
),
exit = fadeOut(animationSpec = tween(1000)) + slideOutVertically(
targetOffsetY = { it },
animationSpec = tween(1000)
)
) {
BottomNavigation(modifier = modifier) {
bottomBarNavDestinations.forEach { destination ->
BottomNavigationItem(
icon = {
when (destination) {
Screen.Calendar -> Icon(
imageVector = Icons.Default.CalendarToday,
contentDescription = null
)
Screen.Targets -> Icon(
imageVector = Icons.Default.PieChart,
contentDescription = null
)
Screen.FoodList -> Icon(
imageVector = Icons.Default.Fastfood,
contentDescription = null
)
else -> Unit
}
},
label = { Text(text = destination.name) },
selected = currentDestination == destination,
onClick = { onClick(destination) }
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment