Skip to content

Instantly share code, notes, and snippets.

@zurche
Last active July 10, 2023 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zurche/1028f2c5e47834b245c954b1641e7385 to your computer and use it in GitHub Desktop.
Save zurche/1028f2c5e47834b245c954b1641e7385 to your computer and use it in GitHub Desktop.
Nav Host Update
NavHost(navController = navController, startDestination = MOVIE_LIST) {
composable(
route = MOVIE_LIST,
enterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
animationSpec = tween(700)
)
},
exitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
animationSpec = tween(700)
)
},
popEnterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
animationSpec = tween(700)
)
},
popExitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
animationSpec = tween(700)
)
}) {
MoviesListScreen(
onMovieDetails = { navController.navigate("$MOVIE_DETAIL/$it") },
movies = movies
)
}
composable(
route = "$MOVIE_DETAIL/{$MOVIE_ID}",
arguments = listOf(navArgument("movieId") { type = NavType.IntType }),
enterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
animationSpec = tween(700)
)
},
exitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Left,
animationSpec = tween(700)
)
},
popEnterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
animationSpec = tween(700)
)
},
popExitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Companion.Right,
animationSpec = tween(700)
)
}
) { backStackEntry ->
val selectedMovie =
movies.value.firstOrNull {
it.movieId == backStackEntry.arguments?.getInt(MOVIE_ID)
}
MovieDetailsScreen(selectedMovie = selectedMovie)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment