Skip to content

Instantly share code, notes, and snippets.

@raamcosta
Last active January 8, 2022 21:42
Show Gist options
  • Save raamcosta/7a77cfdb8fe66423c6c1a37043d69ad2 to your computer and use it in GitHub Desktop.
Save raamcosta/7a77cfdb8fe66423c6c1a37043d69ad2 to your computer and use it in GitHub Desktop.
val navController = rememberNavController()
NavHost(
navController = navController,
startDestination = Screens.Login.route
) {
composable(route = Screens.Login.route) {
LoginScreen(
navigateToHome = {
navController.navigate(Screens.Home.route)
}
)
}
composable(route = Screens.Home.route) {
HomeScreen(
navigateToProfile = { id, isEditable ->
navController.navigate("profile/$id?isEditable=$isEditable")
},
navigateToSearch = { query ->
navController.navigate("search?query=$query")
}
)
}
composable(
route = Screens.Profile.route,
arguments = listOf(
navArgument("id") {
type = NavType.StringType
},
navArgument("isEditable") {
type = NavType.BoolType
defaultValue = false
}
)
) {
ProfileScreen(
id = it.arguments?.getString("id")!!,
isEditable = it.arguments?.getBoolean("isEditable")!!
)
}
composable(
route = Screens.Search.route,
arguments = listOf(
navArgument("query") {
type = NavType.StringType
nullable = true
}
)
) {
SearchScreen(query = it.arguments?.getString("query"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment