Skip to content

Instantly share code, notes, and snippets.

@chiragthummar
Created August 25, 2023 12:23
Show Gist options
  • Save chiragthummar/24b421d6ba192ab42114194e84e84e1f to your computer and use it in GitHub Desktop.
Save chiragthummar/24b421d6ba192ab42114194e84e84e1f to your computer and use it in GitHub Desktop.
@Composable
private fun HomeBottomBar(
destinations: List<TopLevelDestination>,
currentDestination: NavDestination?,
onNavigateToDestination: (route: String) -> Unit
) {
NavigationBar(
modifier = Modifier
.windowInsetsPadding(
WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom)
)
.height(70.dp),
) {
destinations.forEach { destination ->
val selected =
currentDestination?.hierarchy?.any { it.route == destination.route } == true
NavigationBarItem(
selected = selected,
onClick = { onNavigateToDestination(destination.route) },
icon = {
val icon = if (selected) {
destination.selectedIcon
} else {
destination.unselectedIcon
}
Icon(
imageVector = ImageVector.vectorResource(icon),
modifier = Modifier.size(16.dp),
contentDescription = null
)
},
label = {
Text(
text = destination.iconText
)
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment