Skip to content

Instantly share code, notes, and snippets.

@raamcosta
Last active January 8, 2022 21:42
Embed
What would you like to do?
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