Skip to content

Instantly share code, notes, and snippets.

@chientrm
Created April 12, 2023 14:03
Show Gist options
  • Save chientrm/eed9a8e0d0ca5654b684610a3efcf76d to your computer and use it in GitHub Desktop.
Save chientrm/eed9a8e0d0ca5654b684610a3efcf76d to your computer and use it in GitHub Desktop.
Scaffold(
snackbarHost = { SnackbarHost(snackbarHostState) },
bottomBar = {
NavigationBar {
val navBackStackEntry by navController.currentBackStackEntryFlow.collectAsState(null)
val currentDestination = navBackStackEntry?.destination
NavigationBarItem(
selected = currentDestination?.route == Routes.HOME,
onClick = {
navController.navigate(Routes.HOME) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
},
label = { Text("Home") },
icon = {
Icon(
imageVector = if (currentDestination?.route == Routes.HOME)
Icons.Filled.Home
else Icons.Outlined.Home,
contentDescription = "Home Icon",
)
}
)
NavigationBarItem(
selected = currentDestination?.route == Routes.LIBRARY,
onClick = {
navController.navigate(Routes.LIBRARY) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
},
label = { Text("Library") },
icon = {
Icon(
imageVector = if (currentDestination?.route == Routes.LIBRARY)
Icons.Filled.VideoLibrary
else Icons.Outlined.VideoLibrary,
contentDescription = "Library icon",
)
}
)
}
}
) { it ->
NavHost(
navController = navController,
startDestination = Routes.HOME,
Modifier.padding(it),
) {
composable(Routes.HOME) {
HomeTab(
onProfile = { dialog = Dialogs.PROFILE },
app = app,
play = { playerViewModel.play(it) },
)
}
composable(Routes.LIBRARY) {
LibraryTab(
app = app,
onProfile = { dialog = Dialogs.PROFILE },
play = { playerViewModel.play(it) },
startDestination = libraryTabStartDestination,
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment