Last active
April 10, 2025 16:09
-
-
Save iamnaran/9532569e335cd346412e61b5dbe6feda to your computer and use it in GitHub Desktop.
Nested Navigation with Multiple Back Stack Android Jetpack Compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun BottomBar( | |
navController: NavHostController, | |
) { | |
val navigationScreen = listOf( | |
AppScreen.Main.Home, AppScreen.Main.Notification, AppScreen.Main.Profile | |
) | |
NavigationBar { | |
val navBackStackEntry by navController.currentBackStackEntryAsState() | |
val currentRoute = navBackStackEntry?.destination?.route | |
navigationScreen.forEach { item -> | |
NavigationBarItem( | |
selected = currentRoute == item.route, | |
label = { | |
Text(text = stringResource(id = item.title!!), style = MaterialTheme.typography.displaySmall) | |
}, | |
icon = { | |
// BadgedBox(badge = {}) { | |
// | |
// } | |
Icon( | |
imageVector = (if (item.route == currentRoute) item.selectedIcon else item.unselectedIcon)!!, | |
contentDescription = stringResource(id = item.title!!) | |
) | |
}, | |
onClick = { | |
navController.navigate(item.route) { | |
popUpTo(navController.graph.findStartDestination().id) { | |
saveState = true | |
} | |
launchSingleTop = true | |
restoreState = true | |
} | |
}, | |
) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
Scaffold( | |
snackbarHost = { | |
SnackbarHost(hostState = snackbarHostState) | |
}, | |
bottomBar = { | |
if (bottomBarState.value) { | |
BottomBar(navController = navController) | |
} | |
}) { paddingValues -> | |
Box( | |
modifier = Modifier.padding(paddingValues) | |
) { | |
// For multiple back stack nav host | |
RootMultipleBackStackNavHost( | |
isAuthenticated, | |
rootNavHostController = navController | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment