-
Notifications
You must be signed in to change notification settings - Fork 1
Navigation Base 로직 구현 #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package com.twix.navigation | ||
|
|
||
| import androidx.compose.animation.core.FastOutSlowInEasing | ||
| import androidx.compose.animation.core.tween | ||
| import androidx.compose.animation.slideInHorizontally | ||
| import androidx.compose.animation.slideOutHorizontally | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.navigation.compose.NavHost | ||
| import androidx.navigation.compose.rememberNavController | ||
| import com.twix.navigation.base.NavGraphContributor | ||
| import org.koin.compose.getKoin | ||
|
|
||
| @Composable | ||
| fun AppNavHost() { | ||
| val navController = rememberNavController() | ||
| val koin = getKoin() | ||
| val contributors = remember { | ||
| koin.getAll<NavGraphContributor>().sortedBy { it.priority } | ||
| } | ||
| val start = contributors | ||
| .firstOrNull { it.graphRoute == NavRoutes.LoginGraph } | ||
| ?.graphRoute | ||
| ?: error("해당 Graph를 찾을 수 없습니다.") | ||
| val duration = 300 | ||
|
|
||
| NavHost( | ||
| navController = navController, | ||
| startDestination = start.route, | ||
| enterTransition = { | ||
| slideInHorizontally( | ||
| initialOffsetX = { fullWidth -> fullWidth }, | ||
| animationSpec = tween(duration, easing = FastOutSlowInEasing) | ||
| ) | ||
| }, | ||
| exitTransition = { | ||
| slideOutHorizontally( | ||
| targetOffsetX = { fullWidth -> -fullWidth }, | ||
| animationSpec = tween(duration, easing = FastOutSlowInEasing) | ||
| ) | ||
| }, | ||
| popEnterTransition = { | ||
| slideInHorizontally( | ||
| initialOffsetX = { fullWidth -> -fullWidth }, | ||
| animationSpec = tween(duration, easing = FastOutSlowInEasing) | ||
| ) | ||
| }, | ||
| popExitTransition = { | ||
| slideOutHorizontally( | ||
| targetOffsetX = { fullWidth -> fullWidth }, | ||
| animationSpec = tween(duration, easing = FastOutSlowInEasing) | ||
| ) | ||
| }, | ||
| modifier = Modifier.fillMaxSize() | ||
| ) { | ||
| contributors.forEach { with(it) { registerGraph(navController) } } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.twix.navigation | ||
|
|
||
| /** | ||
| * 앱 전반에서 사용하는 Navigation Route를 여기에서 정의합니다. | ||
| * | ||
| * · 문자열 route를 직접 사용하지 않고 타입 안정성을 위해 sealed class를 활용합니다. | ||
| * · navigation argument가 필요한 경우 createRoute()를 통해 route를 생성합니다. | ||
| * · Graph의 경우 _graph로 네이밍하고 Screen의 경우에는 Composable명에서 Screen을 제외한 앞부분을 활용합니다. ex) HomeScreen -> home | ||
| * */ | ||
| sealed class NavRoutes(val route: String) { | ||
| object LoginGraph: NavRoutes("login_graph") | ||
| object Login: NavRoutes("login") | ||
|
|
||
| object HomeGraph: NavRoutes("home_graph") | ||
| object Home: NavRoutes("home") | ||
|
|
||
| object HomeDetail: NavRoutes("home_detail/{id}") { | ||
| fun createRoute(id: String) = "home_detail/$id" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.twix.navigation.base | ||
|
|
||
| import androidx.navigation.NavGraphBuilder | ||
| import androidx.navigation.NavHostController | ||
| import com.twix.navigation.NavRoutes | ||
|
|
||
| /** | ||
| * priority는 우선적으로 등록해야 하는 Graph에서 값을 낮춰 사용하면 됩니다. | ||
| * ex) SplashGraph는 앱 내에서 가장 먼저 실행되어야 하는 그래프이므로 priority를 낮춰주면 됩니다. | ||
| **/ | ||
| interface NavGraphContributor { | ||
| val graphRoute: NavRoutes | ||
| val startDestination: String | ||
| val priority: Int get() = 100 | ||
|
|
||
| fun NavGraphBuilder.registerGraph(navController: NavHostController) | ||
| } | ||
|
Comment on lines
+11
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: rg -n --type=kotlin -C 3 'startDestination'Repository: YAPP-Github/Twix-Android Length of output: 1528 🏁 Script executed: # AppNavHost.kt 상세 확인
cat -n core/navigation/src/main/java/com/twix/navigation/AppNavHost.kt | sed -n '15,45p'Repository: YAPP-Github/Twix-Android Length of output: 1281 🏁 Script executed: # NavGraphContributor의 구현체 찾기
rg -n --type=kotlin 'class.*:.*NavGraphContributor'Repository: YAPP-Github/Twix-Android Length of output: 50 🏁 Script executed: # startDestination 프로퍼티 직접 사용처 검색 (contributor.startDestination 패턴)
rg -n --type=kotlin '\.startDestination'Repository: YAPP-Github/Twix-Android Length of output: 50 🏁 Script executed: # NavGraphContributor를 구현하는 모든 파일 찾기
rg -n --type=kotlin 'NavGraphContributor' -A 10 | head -50Repository: YAPP-Github/Twix-Android Length of output: 2681 🏁 Script executed: # startDestination에 대한 모든 언급 찾기 (주석 포함)
rg -n --type=kotlin --type-add='kt:include:*.kt' 'startDestination' -B 2 -A 2Repository: YAPP-Github/Twix-Android Length of output: 127 🏁 Script executed: # 간단하게 startDestination 모든 언급 찾기
grep -rn "startDestination" --include="*.kt" core/Repository: YAPP-Github/Twix-Android Length of output: 288
NavGraphContributor 인터페이스의 전반적인 설계는 우수합니다: ✅ 장점:
개선 방안:
🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :feature:*에서 NavGraphContributor 구현체를 만들 때 사용할 예정 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dogmania, 이해했습니다! 현재는 기본 인프라를 구축하는 단계이고, 실제 feature 모듈에서 이러한 설계는 합리적입니다. 각 feature의 navigation graph는 여러 화면으로 구성될 수 있고, 다만 향후 유지보수를 위해 KDoc에 사용 예시를 추가하는 것을 고려해보세요: /**
* Navigation Graph 등록을 위한 기본 인터페이스
*
* priority는 우선적으로 등록해야 하는 Graph에서 값을 낮춰 사용하면 됩니다.
* ex) SplashGraph는 앱 내에서 가장 먼저 실행되어야 하는 그래프이므로 priority를 낮춰주면 됩니다.
*
* @property graphRoute 전체 앱에서 해당 그래프를 식별하는 route
* @property startDestination 해당 그래프 내에서 시작 화면의 route
* @property priority 그래프 등록 우선순위 (낮을수록 먼저 등록)
*/ |
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 133
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 180
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
cat -n ./core/navigation/src/main/java/com/twix/navigation/AppNavHost.kt | head -35Repository: YAPP-Github/Twix-Android
Length of output: 1595
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 678
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 2335
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 1224
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 77
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 213
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 129
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 190
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 202
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 152
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 120
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 526
🏁 Script executed:
cat -n ./build-logic/convention/src/main/kotlin/com/twix/convention/KoinConventionPlugin.kt | head -50Repository: YAPP-Github/Twix-Android
Length of output: 444
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
# TwixApplication.kt 파일의 import 문을 포함한 전체 내용 cat -n ./app/src/main/java/com/yapp/twix/TwixApplication.ktRepository: YAPP-Github/Twix-Android
Length of output: 526
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 570
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 1269
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 1152
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 152
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 129
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 50
🏁 Script executed:
# 직접 전체 feature/login 디렉토리 구조 확인 find ./feature/login -type fRepository: YAPP-Github/Twix-Android
Length of output: 322
🏁 Script executed:
# LoginActivity.kt 내용 확인 cat -n ./feature/login/src/main/java/com/twix/login/LoginActivity.ktRepository: YAPP-Github/Twix-Android
Length of output: 382
🏁 Script executed:
Repository: YAPP-Github/Twix-Android
Length of output: 213
NavGraphContributor 구현체가 없어 현재 코드가 실행되지 않는 상태입니다.
코드베이스 전체를 검색한 결과,
NavGraphContributor인터페이스는 정의되어 있으나 이를 구현한 클래스가 존재하지 않습니다. 따라서koin.getAll<NavGraphContributor>()는 항상 빈 리스트를 반환하며, 결과적으로 23-26줄의error("해당 Graph를 찾을 수 없습니다.")가 필연적으로 실행됩니다.이를 해결하기 위해서는:
NavGraphContributor구현체 작성 - 각 feature(예: login, home 등)마다 해당 그래프를 등록하는 구현체 필요modules()함수 정의 및 각 feature의 Koin 모듈 연결🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이후에 :feature:*에서 구현할 예정
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dogmania, 네, feature 모듈에서 구현 예정이시군요! 이해했습니다.
추후 디버깅을 쉽게 하기 위해 다음과 같은 개선을 고려해보시면 좋을 것 같습니다 (선택 사항):
이렇게 하면:
하지만 현재 구조도 충분히 명확하므로, 선호하시는 방식으로 진행하셔도 됩니다! 👍