Skip to content

Instantly share code, notes, and snippets.

@victorbrndls
Last active October 19, 2021 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorbrndls/4fda3af5a2f78fa3b57581981c46d3a5 to your computer and use it in GitHub Desktop.
Save victorbrndls/4fda3af5a2f78fa3b57581981c46d3a5 to your computer and use it in GitHub Desktop.
val navController = rememberNavController()
val backstackEntry = navController.currentBackStackEntryAsState()
NavHost(navController = navController, startDestination = "profile") {
composable(
"profile/{userId}/?mode={mode}",
arguments = listOf(
navArgument("userId") { type = NavType.StringType },
navArgument("mode") { defaultValue = "lite" },
),
deepLinks = listOf(navDeepLink {
uriPattern = "rally://$accountsName/{name}"
})
) {
Profile(/*...*/)
}
loginGraph()
}
fun NavGraphBuilder.loginGraph(navController: NavController) {
navigation(startDestination = "username", route = "login") {
composable("username") { ... }
}
}
navController.navigate("friends") {
popUpTo("home") { inclusive = true }
}
navController.navigate(screen.route) {
// Pop up to the start destination of the graph to avoid building up a large stack
// of destinations on the back stack as users select items
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
// Avoid multiple copies of the same destination when reselecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
restoreState = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment