Skip to content

Instantly share code, notes, and snippets.

@olshevski
Created February 4, 2022 10:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save olshevski/89ca6aadca3231ce94b0fac124653f60 to your computer and use it in GitHub Desktop.
For "Compose Navigation Reimagined" blogpost on Medium
@Composable
fun NavHostScreen() {
val navController = rememberNavController<Screen>(
startDestination = Screen.First,
)
NavBackHandler(navController)
NavHost(controller = navController) { screen ->
when (screen) {
Screen.First -> Column {
Text("First screen")
Button(onClick = {
navController.navigate(Screen.Second(id = 42))
}) {
Text("To Second screen")
}
}
is Screen.Second -> Column {
Text("Second screen: ${screen.id}")
Button(onClick = {
navController.navigate(Screen.Third(text = "Hello"))
}) {
Text("To Third screen")
}
}
is Screen.Third -> {
Text("Third screen: ${screen.text}")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment