Created
February 4, 2022 10:04
-
-
Save olshevski/89ca6aadca3231ce94b0fac124653f60 to your computer and use it in GitHub Desktop.
For "Compose Navigation Reimagined" blogpost on Medium
This file contains 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 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