Skip to content

Instantly share code, notes, and snippets.

@skydoves
Created April 19, 2024 06:38
Show Gist options
  • Save skydoves/7882360caa75b3ab196a1362636e81cb to your computer and use it in GitHub Desktop.
Save skydoves/7882360caa75b3ab196a1362636e81cb to your computer and use it in GitHub Desktop.
nav_sample_details
composable(
route = "details/{pokemon}",
arguments = listOf(navArgument("pokemon") { type = NavType.IntType })
) { backStackEntry ->
val pokemonId = backStackEntry.arguments?.getInt("pokemon")
val pokemon = pokemons[pokemonId!!]
Column(
Modifier
.fillMaxSize()
.clickable {
navController.navigate("home")
}) {
Image(
painterResource(id = pokemon.image),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.aspectRatio(1f)
.fillMaxWidth()
.sharedElement(
rememberSharedContentState(key = "image-$pokemonId"),
animatedVisibilityScope = this@composable,
boundsTransform = boundsTransform
)
)
Text(
pokemon.name, fontSize = 18.sp, modifier =
Modifier
.fillMaxWidth()
.sharedElement(
rememberSharedContentState(key = "text-$pokemonId"),
animatedVisibilityScope = this@composable,
boundsTransform = boundsTransform
)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment