Skip to content

Conversation

@DongChyeon
Copy link
Member

Related issue 🛠

closed #212

어떤 변경사항이 있었나요?

  • 🐞 BugFix Something isn't working
  • 🎨 Design Markup & styling
  • 📃 Docs Documentation writing and editing (README.md, etc.)
  • ✨ Feature Feature
  • 🔨 Refactor Code refactoring
  • ⚙️ Setting Development environment setup
  • ✅ Test Test related (Junit, etc.)

CheckPoint ✅

PR이 다음 요구 사항을 충족하는지 확인하세요.

  • PR 컨벤션에 맞게 작성했습니다. (필수)
  • merge할 브랜치의 위치를 확인해 주세요(main❌/develop⭕) (필수)
  • Approve된 PR은 assigner가 머지하고, 수정 요청이 온 경우 수정 후 다시 push를 합니다. (필수)
  • BugFix의 경우, 버그의 원인을 파악하였습니다. (선택)

Work Description ✏️

  1. 기존 String 기반 라우팅을 KClass 기반 라우팅으로 대체
  2. navigateTo 함수를 라우트별 명시적 라우팅 함수로 분리
fun OrbitNavigator.navigateTo(
    route: KClass<*>,
    popUpTo: KClass<*>? = null,
    inclusive: Boolean = false,
) {
    navController.navigate(route.routeName()) {
        popUpTo?.let {
            popUpTo(it.routeName()) { this.inclusive = inclusive }
        }
        launchSingleTop = true
        restoreState = true
    }
}

해당 함수로 변환해서 사용하려 했지만...

kotlinx.serialization.SerializationException: Serializer for class 'KClassImpl' is not found.

KClass는 기본적으로 직렬화가 불가능하기 때문에 해당 오류를 접했습니다...

따라서

fun navigateToOnboarding(navOptions: NavOptions? = null) {
    navController.navigate(OnboardingBaseRoute, navOptions)
}

fun navigateToOnboardingNextStep(currentStep: Int, navOptions: NavOptions? = null) {
    val nextRouteClass = OnboardingDestination.nextRoute(currentStep + 1) ?: return

    val nextRouteInstance = nextRouteClass.objectInstance
        ?: error("Cannot get object instance of route class: $nextRouteClass")

    navController.navigate(nextRouteInstance, navOptions)
}

fun navigateToAddAlarm(navOptions: NavOptions? = null) {
    navController.navigate(HomeDestination.AlarmAddEdit(-1), navOptions)
}
// ...

다음과 같이 라우트별로 명시적으로 이동하는 함수로 분리했습니다.

  1. 알람 그래프에서 첫 화면에서 알람 유무에 따라 분기
navigation(
    route = AlarmInteractionDestination.Route.route,
    startDestination = "${AlarmInteractionDestination.AlarmAction.route}/{alarm}",
)

기존에 String 기반 라우팅을 하면 startDestination에 alarm을 인자로 넘길 수 있는 반면

fun NavGraphBuilder.alarmInteractionNavGraph(
    navigator: OrbitNavigator,
    alarm: Alarm?,
) {
    navigation<AlarmInteractionBaseRoute>(
        startDestination = AlarmInteractionDestination.Route,
    ) {
        composable<AlarmInteractionDestination.Route> {
            LaunchedEffect(Unit) {
                alarm?.let {
                    navigator.navigateToAlarmAction(
                        it,
                        navOptions {
                            popUpTo(AlarmInteractionBaseRoute) {
                                inclusive = true
                            }
                        },
                    )
                } ?: run {
                    navigator.navigateToHome(
                        navOptions {
                            popUpTo(AlarmInteractionBaseRoute) {
                                inclusive = true
                            }
                        },
                    )
                }
            }
        }

        composable<AlarmInteractionDestination.AlarmAction>(
            typeMap = mapOf(typeOf<Alarm>() to AlarmArgType),
        ) {
            AlarmActionRoute(
                navigator = navigator,
            )
        }

        composable<AlarmInteractionDestination.AlarmSnoozeTimer>(
            typeMap = mapOf(typeOf<Alarm>() to AlarmArgType),
        ) {
            AlarmSnoozeTimerRoute(
                navigator = navigator,
            )
        }
    }
}

KClass 기반 라우팅으로 변경할 시 startDestination에 Alarm을 넘겨줄 수 없기 때문에
첫 화면인 AlarmDestination.Route 에서 화면 이동 분기 처리를 했습니다.

Uncompleted Tasks 😅

  • N/A

To Reviewers 📢

분량 테러 미안합니다!!!

@DongChyeon DongChyeon requested a review from MoonsuKang June 3, 2025 12:51
@DongChyeon DongChyeon self-assigned this Jun 3, 2025
@DongChyeon DongChyeon added the ♻️ REFACTOR 코드 리팩토링(전면 수정) label Jun 3, 2025
Copy link
Member

@MoonsuKang MoonsuKang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 대규모 공사를 하시다니... respect 합니다 선생님..!!
image

@DongChyeon
Copy link
Member Author

@MoonsuKang 수정했으요

Copy link
Member

@MoonsuKang MoonsuKang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다~

@DongChyeon DongChyeon merged commit ccc2e38 into develop Jun 8, 2025
1 check passed
@DongChyeon DongChyeon deleted the refactor/#212-navigation-kclass branch June 10, 2025 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

♻️ REFACTOR 코드 리팩토링(전면 수정)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REFACTOR] 네비게이션의 sealed class 기반 경로를 KClass 기반으로 리팩토링

3 participants