Skip to content

Commit

Permalink
[REFACTOR/#40] Onboarding 네비게이션 컴포저블 등록 방식을 routes.forEach 기반으로 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
DongChyeon committed Jan 17, 2025
1 parent 484765a commit ba4c55d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sealed class OnboardingDestination(val route: String) {
data object Complete2 : OnboardingDestination(Routes.Onboarding.COMPLETE_SECOND)

companion object {
private val routes = listOf(Explain, AlarmTimeSelection, Birthday, TimeOfBirth, Name, Gender, Access, Complete1, Complete2)
val routes = listOf(Explain, AlarmTimeSelection, Birthday, TimeOfBirth, Name, Gender, Access, Complete1, Complete2)

fun nextRoute(currentStep: Int): String? {
return routes.getOrNull(currentStep)?.route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,177 +16,46 @@ fun NavGraphBuilder.onboardingNavGraph(
route = OnboardingDestination.Route.route,
startDestination = OnboardingDestination.Explain.route,
) {
composable(OnboardingDestination.Explain.route) {
val viewModel = it.sharedViewModel<OnboardingViewModel>(navigator.navController)

LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
handleSideEffect(
sideEffect = sideEffect,
navigator = navigator,
viewModel = viewModel,
onFinishOnboarding = onFinishOnboarding,
)
}
}

OnboardingExplainRoute(
viewModel = viewModel,
)
}

composable(OnboardingDestination.AlarmTimeSelection.route) {
val viewModel = it.sharedViewModel<OnboardingViewModel>(navigator.navController)

LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
handleSideEffect(
sideEffect = sideEffect,
navigator = navigator,
viewModel = viewModel,
onFinishOnboarding = onFinishOnboarding,
)
}
}

OnboardingAlarmTimeSelectionRoute(
viewModel = viewModel,
)
}

composable(OnboardingDestination.Birthday.route) {
val viewModel = it.sharedViewModel<OnboardingViewModel>(navigator.navController)

LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
handleSideEffect(
sideEffect = sideEffect,
navigator = navigator,
viewModel = viewModel,
onFinishOnboarding = onFinishOnboarding,
)
}
}

OnboardingBirthdayRoute(
viewModel = viewModel,
)
}

composable(OnboardingDestination.TimeOfBirth.route) {
val viewModel = it.sharedViewModel<OnboardingViewModel>(navigator.navController)

LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
handleSideEffect(
sideEffect = sideEffect,
navigator = navigator,
viewModel = viewModel,
onFinishOnboarding = onFinishOnboarding,
)
}
}

OnboardingTimeOfBirthRoute(
viewModel = viewModel,
)
}

composable(OnboardingDestination.Name.route) {
val viewModel = it.sharedViewModel<OnboardingViewModel>(navigator.navController)

LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
handleSideEffect(
sideEffect = sideEffect,
navigator = navigator,
viewModel = viewModel,
onFinishOnboarding = onFinishOnboarding,
)
}
}

OnboardingNameRoute(
viewModel = viewModel,
)
}

composable(OnboardingDestination.Gender.route) {
val viewModel = it.sharedViewModel<OnboardingViewModel>(navigator.navController)

LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
handleSideEffect(
sideEffect = sideEffect,
navigator = navigator,
viewModel = viewModel,
onFinishOnboarding = onFinishOnboarding,
)
}
}

OnboardingGenderRoute(
viewModel = viewModel,
)
}

composable(OnboardingDestination.Access.route) {
val viewModel = it.sharedViewModel<OnboardingViewModel>(navigator.navController)

LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
handleSideEffect(
sideEffect = sideEffect,
navigator = navigator,
viewModel = viewModel,
onFinishOnboarding = onFinishOnboarding,
)
}
}

OnboardingAccessRoute(
navigator = navigator,
viewModel = viewModel,
)
}

composable(OnboardingDestination.Complete1.route) {
val viewModel = it.sharedViewModel<OnboardingViewModel>(navigator.navController)

LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
handleSideEffect(
sideEffect = sideEffect,
navigator = navigator,
viewModel = viewModel,
onFinishOnboarding = onFinishOnboarding,
)
OnboardingDestination.routes.forEach { destination ->
composable(destination.route) { backStackEntry ->
val viewModel = backStackEntry.sharedViewModel<OnboardingViewModel>(navigator.navController)

LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
handleSideEffect(sideEffect, navigator, viewModel, onFinishOnboarding)
}
}
}

OnboardingCompleteRoute(
viewModel = viewModel,
)
}

composable(OnboardingDestination.Complete2.route) {
val viewModel = it.sharedViewModel<OnboardingViewModel>(navigator.navController)

LaunchedEffect(viewModel) {
viewModel.container.sideEffectFlow.collect { sideEffect ->
handleSideEffect(
sideEffect = sideEffect,
navigator = navigator,
viewModel = viewModel,
onFinishOnboarding = onFinishOnboarding,
)
when (destination) {
OnboardingDestination.Route, OnboardingDestination.Explain -> {
OnboardingExplainRoute(viewModel)
}
OnboardingDestination.AlarmTimeSelection -> {
OnboardingAlarmTimeSelectionRoute(viewModel)
}
OnboardingDestination.Birthday -> {
OnboardingBirthdayRoute(viewModel)
}
OnboardingDestination.TimeOfBirth -> {
OnboardingTimeOfBirthRoute(viewModel)
}
OnboardingDestination.Name -> {
OnboardingNameRoute(viewModel)
}
OnboardingDestination.Gender -> {
OnboardingGenderRoute(viewModel)
}
OnboardingDestination.Access -> {
OnboardingAccessRoute(navigator, viewModel)
}
OnboardingDestination.Complete1 -> {
OnboardingCompleteRoute(viewModel)
}
OnboardingDestination.Complete2 -> {
OnboardingCompleteRoute2(viewModel, onFinishOnboarding)
}
}
}

OnboardingCompleteRoute2(
viewModel = viewModel,
onFinishOnboarding = onFinishOnboarding,
)
}
}
}
Expand Down

0 comments on commit ba4c55d

Please sign in to comment.