Skip to content

Commit ee90f2c

Browse files
committed
[REFACTOR/#212] 온보딩 단계 이동 함수 네이밍 개선 및 null 안전 처리 추가
1 parent 525b14b commit ee90f2c

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

core/common/src/main/java/com/yapp/common/navigation/OrbitNavigator.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.yapp.common.navigation
22

3+
import android.util.Log
34
import androidx.compose.runtime.Composable
45
import androidx.compose.runtime.remember
56
import androidx.navigation.NavHostController
@@ -28,12 +29,12 @@ class OrbitNavigator(
2829
}
2930

3031
fun navigateToOnboardingNextStep(currentStep: Int, navOptions: NavOptions? = null) {
31-
val nextRouteClass = OnboardingDestination.nextRoute(currentStep + 1) ?: return
32-
33-
val nextRouteInstance = nextRouteClass.objectInstance
34-
?: error("Cannot get object instance of route class: $nextRouteClass")
35-
36-
navController.navigate(nextRouteInstance, navOptions)
32+
val instance = OnboardingDestination.getNextRouteForStep(currentStep)?.objectInstance
33+
if (instance != null) {
34+
navController.navigate(instance, navOptions)
35+
} else {
36+
Log.e("Navigator", "Invalid route at step: $currentStep")
37+
}
3738
}
3839

3940
fun navigateToAddAlarm(navOptions: NavOptions? = null) {

core/common/src/main/java/com/yapp/common/navigation/route/OnboardingRoute.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ sealed class OnboardingDestination {
4747
Complete2::class,
4848
)
4949

50-
fun nextRoute(currentStep: Int): KClass<out OnboardingDestination>? {
51-
val nextRoute = routes.getOrNull(currentStep)
50+
fun getNextRouteForStep(currentStep: Int): KClass<out OnboardingDestination>? {
51+
val nextRoute = routes.getOrNull(currentStep + 1)
5252
return nextRoute
5353
}
5454
}

feature/onboarding/src/main/java/com/yapp/onboarding/OnboardingViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class OnboardingViewModel @Inject constructor(
9696
private fun moveToNextStep() {
9797
val currentStep = container.stateFlow.value.currentStep
9898
val nextStep = currentStep + 1
99-
val nextRoute = OnboardingDestination.nextRoute(currentStep)
99+
val nextRoute = OnboardingDestination.getNextRouteForStep(currentStep)
100100

101101
savedStateHandle["birthDate"] = currentState.birthDate
102102
savedStateHandle["birthType"] = currentState.birthType

0 commit comments

Comments
 (0)