Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 1. Create a destination
sealed class Destination : Parcelable { // parcelable so that it can be saved in a bundle.
object First : Destination()
data class Second(val name: String, val hobbies: List<String>) : Destination()
}
// 2. Setup the navigation
@Composable
fun MainScreen() {
// Create a NavController
val controller = rememberNavController<Destination>(
startDestination = Destination.First
)
NavBackHandler(controller) // Very important, otherwise system back action will not pop the backstack.
// Could be NavHost or etc.
AnimatedNavHost(
controller = controller,
transitionSpec = ...
) { destination ->
when(destination) {
Destination.First -> { /* composable content */ }
Destination.Second -> { /* composable content */ }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment