Skip to content

Instantly share code, notes, and snippets.

@skydoves
Last active September 19, 2024 16:40
Show Gist options
  • Save skydoves/0095b613bc9b3f4d5893a3e73fa9e2bb to your computer and use it in GitHub Desktop.
Save skydoves/0095b613bc9b3f4d5893a3e73fa9e2bb to your computer and use it in GitHub Desktop.
pokedex_navigation
sealed interface PokedexScreen {
@Serializable
data object Home : PokedexScreen
@Serializable
data class Details(val pokemon: Pokemon) : PokedexScreen {
companion object {
val typeMap = mapOf(typeOf<Pokemon>() to PokemonType)
}
}
}
fun NavGraphBuilder.pokedexNavigation() {
composable<PokedexScreen.Home> {
PokedexHome(this)
}
composable<PokedexScreen.Details>(
typeMap = PokedexScreen.Details.typeMap,
) { backStackEntry ->
val id = backStackEntry.savedStateHandle.get<String>("id")
PokedexDetails(this, id)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment