Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
moved navArguments to Screen class constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sahilsk3333 committed Nov 17, 2023
1 parent 7a5ed9a commit 84c29e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun SunFlowerNavHost(
HomeScreen(
onPlantClick = {
navController.navigate(
Screen.PlantDetail.passPlantId(
Screen.PlantDetail.createRoute(
plantId = it.plantId
)
)
Expand All @@ -59,7 +59,7 @@ fun SunFlowerNavHost(
}
composable(
route = Screen.PlantDetail.route,
arguments = Screen.PlantDetail.arguments
arguments = Screen.PlantDetail.navArguments
) {
PlantDetailsScreen(
onBackClick = { navController.navigateUp() },
Expand All @@ -68,7 +68,7 @@ fun SunFlowerNavHost(
},
onGalleryClick = {
navController.navigate(
Screen.Gallery.passPlantName(
Screen.Gallery.createRoute(
plantName = it.name
)
)
Expand All @@ -77,7 +77,7 @@ fun SunFlowerNavHost(
}
composable(
route = Screen.Gallery.route,
arguments = Screen.Gallery.arguments
arguments = Screen.Gallery.navArguments
) {
GalleryScreen(
onPhotoClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,32 @@

package com.google.samples.apps.sunflower.utilities

import androidx.navigation.NamedNavArgument
import androidx.navigation.NavType
import androidx.navigation.navArgument

sealed class Screen(val route: String) {
sealed class Screen(
val route: String,
val navArguments: List<NamedNavArgument> = emptyList()
) {
data object Home : Screen("home")
data object PlantDetail : Screen("plantDetail/{plantId}") {
fun passPlantId(plantId: String) = "plantDetail/${plantId}"
val arguments = listOf(navArgument("plantId") {

data object PlantDetail : Screen(
route = "plantDetail/{plantId}",
navArguments = listOf(navArgument("plantId") {
type = NavType.StringType
})

) {
fun createRoute(plantId: String) = "plantDetail/${plantId}"
}

data object Gallery : Screen("gallery/{plantName}") {
fun passPlantName(plantName: String) = "gallery/${plantName}"
val arguments = listOf(navArgument("plantName") {
data object Gallery : Screen(
route = "gallery/{plantName}",
navArguments = listOf(navArgument("plantName") {
type = NavType.StringType
})
) {
fun createRoute(plantName: String) = "gallery/${plantName}"

}
}

0 comments on commit 84c29e0

Please sign in to comment.