From a9734b01a74337bf8fa26baf7d86a97d365c5ecc Mon Sep 17 00:00:00 2001 From: Dongmin Date: Tue, 24 Sep 2024 03:47:32 +0900 Subject: [PATCH] feature #866: separate navGraph --- .../official/feature/fortune/MainScreen.kt | 58 ++++++++----------- .../fortundDetail/FortuneDetailScreen.kt | 4 -- .../navigation/FortuneDetailNavGraph.kt | 25 ++++++++ .../fortuneAmulet/FortuneAmuletScreen.kt | 3 - .../navigation/FortuneAmuletNavGraph.kt | 22 +++++++ .../fortune/feature/home/HomeScreen.kt | 4 -- .../feature/home/navigation/HomeNavGraph.kt | 23 ++++++++ 7 files changed, 94 insertions(+), 45 deletions(-) create mode 100644 feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortundDetail/navigation/FortuneDetailNavGraph.kt create mode 100644 feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortuneAmulet/navigation/FortuneAmuletNavGraph.kt create mode 100644 feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/home/navigation/HomeNavGraph.kt diff --git a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/MainScreen.kt b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/MainScreen.kt index 256b87a5b..156b97ba8 100644 --- a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/MainScreen.kt +++ b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/MainScreen.kt @@ -34,17 +34,15 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost -import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController -import androidx.navigation.toRoute import org.sopt.official.designsystem.SoptTheme import org.sopt.official.feature.fortune.component.FortuneTopBar -import org.sopt.official.feature.fortune.feature.fortundDetail.FortuneDetail -import org.sopt.official.feature.fortune.feature.fortundDetail.FortuneDetailRoute -import org.sopt.official.feature.fortune.feature.fortuneAmulet.FortuneAmulet -import org.sopt.official.feature.fortune.feature.fortuneAmulet.FortuneAmuletRoute -import org.sopt.official.feature.fortune.feature.home.Home -import org.sopt.official.feature.fortune.feature.home.HomeRoute +import org.sopt.official.feature.fortune.feature.fortundDetail.navigation.FortuneDetail +import org.sopt.official.feature.fortune.feature.fortundDetail.navigation.fortuneDetailNavGraph +import org.sopt.official.feature.fortune.feature.fortuneAmulet.navigation.FortuneAmulet +import org.sopt.official.feature.fortune.feature.fortuneAmulet.navigation.fortuneAmuletNavGraph +import org.sopt.official.feature.fortune.feature.home.navigation.Home +import org.sopt.official.feature.fortune.feature.home.navigation.homeNavGraph @Composable fun MainScreen( @@ -68,34 +66,26 @@ fun MainScreen( navController = navController, startDestination = Home ) { - composable { - HomeRoute( - paddingValue = paddingValue, - navigateToFortuneDetail = { date -> - navController.navigate(FortuneDetail(date)) - } - ) - } + homeNavGraph( + paddingValue = paddingValue, + navigateToFortuneDetail = { date -> + navController.navigate(FortuneDetail(date)) + } + ) - composable { backStackEntry -> - val items = backStackEntry.toRoute() - FortuneDetailRoute( - paddingValue = paddingValue, - date = items.date, - navigateToFortuneAmulet = { - navController.navigate(FortuneAmulet) - } - ) - } + fortuneDetailNavGraph( + paddingValue = paddingValue, + navigateToFortuneAmulet = { + navController.navigate(FortuneAmulet) + } + ) - composable { - FortuneAmuletRoute( - paddingValue = paddingValue, - navigateToHome = { - // TODO: Navigate to Home - } - ) - } + fortuneAmuletNavGraph( + paddingValue = paddingValue, + navigateToHome = { + // TODO: Navigate to Home + } + ) } } } diff --git a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortundDetail/FortuneDetailScreen.kt b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortundDetail/FortuneDetailScreen.kt index a505c5be7..a66f60442 100644 --- a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortundDetail/FortuneDetailScreen.kt +++ b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortundDetail/FortuneDetailScreen.kt @@ -37,12 +37,8 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import kotlinx.serialization.Serializable import org.sopt.official.designsystem.SoptTheme -@Serializable -data class FortuneDetail(val date: String) - @Composable fun FortuneDetailRoute( paddingValue: PaddingValues, diff --git a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortundDetail/navigation/FortuneDetailNavGraph.kt b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortundDetail/navigation/FortuneDetailNavGraph.kt new file mode 100644 index 000000000..08c7266b1 --- /dev/null +++ b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortundDetail/navigation/FortuneDetailNavGraph.kt @@ -0,0 +1,25 @@ +package org.sopt.official.feature.fortune.feature.fortundDetail.navigation + +import androidx.compose.foundation.layout.PaddingValues +import androidx.navigation.NavGraphBuilder +import androidx.navigation.compose.composable +import androidx.navigation.toRoute +import kotlinx.serialization.Serializable +import org.sopt.official.feature.fortune.feature.fortundDetail.FortuneDetailRoute + +@Serializable +data class FortuneDetail(val date: String) + +fun NavGraphBuilder.fortuneDetailNavGraph( + paddingValue: PaddingValues, + navigateToFortuneAmulet: () -> Unit, +) { + composable { backStackEntry -> + val items = backStackEntry.toRoute() + FortuneDetailRoute( + paddingValue = paddingValue, + date = items.date, + navigateToFortuneAmulet = navigateToFortuneAmulet + ) + } +} diff --git a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortuneAmulet/FortuneAmuletScreen.kt b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortuneAmulet/FortuneAmuletScreen.kt index 2cb9346be..ca6fe50a5 100644 --- a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortuneAmulet/FortuneAmuletScreen.kt +++ b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortuneAmulet/FortuneAmuletScreen.kt @@ -46,9 +46,6 @@ import kotlinx.serialization.Serializable import org.sopt.official.designsystem.SoptTheme import org.sopt.official.feature.fortune.component.CircleShapeBorderButton -@Serializable -data object FortuneAmulet - @Composable internal fun FortuneAmuletRoute( paddingValue: PaddingValues, diff --git a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortuneAmulet/navigation/FortuneAmuletNavGraph.kt b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortuneAmulet/navigation/FortuneAmuletNavGraph.kt new file mode 100644 index 000000000..549bc1714 --- /dev/null +++ b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/fortuneAmulet/navigation/FortuneAmuletNavGraph.kt @@ -0,0 +1,22 @@ +package org.sopt.official.feature.fortune.feature.fortuneAmulet.navigation + +import androidx.compose.foundation.layout.PaddingValues +import androidx.navigation.NavGraphBuilder +import androidx.navigation.compose.composable +import kotlinx.serialization.Serializable +import org.sopt.official.feature.fortune.feature.fortuneAmulet.FortuneAmuletRoute + +@Serializable +data object FortuneAmulet + +fun NavGraphBuilder.fortuneAmuletNavGraph( + paddingValue: PaddingValues, + navigateToHome: () -> Unit, +) { + composable { + FortuneAmuletRoute( + paddingValue = paddingValue, + navigateToHome = navigateToHome + ) + } +} diff --git a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/home/HomeScreen.kt b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/home/HomeScreen.kt index 7fc0c3fec..c27100c91 100644 --- a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/home/HomeScreen.kt +++ b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/home/HomeScreen.kt @@ -46,7 +46,6 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.vectorResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import kotlinx.serialization.Serializable import org.sopt.official.designsystem.SoptTheme import org.sopt.official.feature.fortune.R import java.time.LocalDate @@ -54,9 +53,6 @@ import java.time.format.DateTimeFormatter import java.time.format.TextStyle import java.util.Locale -@Serializable -data object Home - @Composable internal fun HomeRoute( paddingValue: PaddingValues, diff --git a/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/home/navigation/HomeNavGraph.kt b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/home/navigation/HomeNavGraph.kt new file mode 100644 index 000000000..526a46886 --- /dev/null +++ b/feature/fortune/src/main/java/org/sopt/official/feature/fortune/feature/home/navigation/HomeNavGraph.kt @@ -0,0 +1,23 @@ +package org.sopt.official.feature.fortune.feature.home.navigation + +import androidx.compose.foundation.layout.PaddingValues +import androidx.navigation.NavGraphBuilder +import androidx.navigation.compose.composable +import kotlinx.serialization.Serializable +import org.sopt.official.feature.fortune.feature.fortuneAmulet.navigation.FortuneAmulet +import org.sopt.official.feature.fortune.feature.home.HomeRoute + +@Serializable +data object Home + +fun NavGraphBuilder.homeNavGraph( + paddingValue: PaddingValues, + navigateToFortuneDetail: (String) -> Unit, +) { + composable { + HomeRoute( + paddingValue = paddingValue, + navigateToFortuneDetail = navigateToFortuneDetail + ) + } +}