Skip to content

Instantly share code, notes, and snippets.

@zurche
Last active July 10, 2023 12:55
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/1dcb5928f020030ae668d12d1458f31b to your computer and use it in GitHub Desktop.
Save zurche/1dcb5928f020030ae668d12d1458f31b to your computer and use it in GitHub Desktop.
Movies App Navigation
private const val MOVIE_LIST = "movieList"
private const val MOVIE_DETAIL = "movieDetail"
private const val MOVIE_ID = "movieId"
@Composable
fun MoviesAppNavigationView(
moviesState: StateFlow<List<MovieUI>>
) {
val movies = moviesState.collectAsStateWithLifecycle()
val navController = rememberNavController()
NavHost(navController = navController, startDestination = MOVIE_LIST) {
composable(route = MOVIE_LIST) {
MoviesListScreen(
onMovieDetails = { navController.navigate("$MOVIE_DETAIL/$it") },
movies = movies
)
}
composable(
route = "$MOVIE_DETAIL/{$MOVIE_ID}",
arguments = listOf(navArgument("movieId") { type = NavType.IntType })
) { 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