-
Notifications
You must be signed in to change notification settings - Fork 1
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
[FEAT/YAF-000] 네비게이션 로직을 통합합니다. #44
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
08df6d6
[FEAT/#40] core:common 모듈에 공용 Routes 관리
DongChyeon 60ead79
[RENAME/#40] MainScreen -> OrbitNavHost
DongChyeon bc92de1
[RENAME/#40] MainBottomNavigationBar -> OrbitBottomNavigationBar
DongChyeon fb59e59
[RENAME/#40] MainNavTab -> TopLevelDestination
DongChyeon 7baf7a8
[RENAME/#40] MainNavigator -> OrbitNavigator
DongChyeon 068b29e
[FEAT/#40] navigator 모듈의 navigation 컴포넌트를 core:common의 navigation 패키지…
DongChyeon 6e67b67
[FEAT/#40] Home 라우팅 경로를 HomeDestination으로 관리
DongChyeon 4cc42c5
[FEAT/#40] SharedViewModel 확장함수 구현
DongChyeon eba7e4f
[FEAT/#40] Onboarding 그래프 NavGraph - Route 형태로 관리
DongChyeon 484765a
[REFACTOR/#40] 마이페이지 네비게이션을 단일 Composable에서 Navigation 그래프로 변경
DongChyeon ba4c55d
[REFACTOR/#40] Onboarding 네비게이션 컴포저블 등록 방식을 `routes.forEach` 기반으로 리팩토링
DongChyeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
core/common/src/main/java/com/yapp/common/navigation/OrbitNavigator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.yapp.common.navigation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.navigation.NavDestination | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.currentBackStackEntryAsState | ||
import androidx.navigation.compose.rememberNavController | ||
import androidx.navigation.navOptions | ||
import com.yapp.common.navigation.destination.OnboardingDestination | ||
import com.yapp.common.navigation.destination.TopLevelDestination | ||
|
||
class OrbitNavigator( | ||
val navController: NavHostController, | ||
) { | ||
val startDestination = OnboardingDestination.Route.route | ||
|
||
private val currentDestination: NavDestination? | ||
@Composable get() = navController | ||
.currentBackStackEntryAsState().value?.destination | ||
|
||
val currentTab: TopLevelDestination? | ||
@Composable get() = currentDestination | ||
?.route | ||
?.let(TopLevelDestination.Companion::find) | ||
|
||
fun navigateTo(route: String, popUpTo: String? = null, inclusive: Boolean = false) { | ||
navController.navigate(route) { | ||
popUpTo?.let { | ||
popUpTo(it) { this.inclusive = inclusive } | ||
} | ||
launchSingleTop = true | ||
restoreState = true | ||
} | ||
} | ||
|
||
fun navigateBack() { | ||
navController.popBackStack() | ||
} | ||
|
||
fun navigateToTopLevelDestination(tab: TopLevelDestination) { | ||
val navOptions = navOptions { | ||
popUpTo(Routes.Home.ROUTE) { | ||
saveState = true | ||
} | ||
launchSingleTop = true | ||
restoreState = true | ||
} | ||
|
||
when (tab) { | ||
TopLevelDestination.HOME -> navController.navigate(Routes.Home.ROUTE, navOptions) | ||
TopLevelDestination.MYPAGE -> navController.navigate(Routes.MyPage.ROUTE, navOptions) | ||
} | ||
} | ||
|
||
@Composable | ||
fun shouldShowBottomBar(): Boolean { | ||
val currentRoute = currentDestination?.route ?: return false | ||
return currentRoute in TopLevelDestination.entries.map { it.route } | ||
} | ||
} | ||
|
||
@Composable | ||
fun rememberOrbitNavigator( | ||
navController: NavHostController = rememberNavController(), | ||
): OrbitNavigator = remember(navController) { | ||
OrbitNavigator(navController) | ||
} |
27 changes: 27 additions & 0 deletions
27
core/common/src/main/java/com/yapp/common/navigation/Routes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.yapp.common.navigation | ||
|
||
object Routes { | ||
object Onboarding { | ||
const val ROUTE = "onboarding_route" | ||
const val EXPLAIN = "onboarding_explain" | ||
const val ALARM_TIME_SELECTION = "onboarding_alarm_time_selection" | ||
const val BIRTHDAY = "onboarding_birthday" | ||
const val TIME_OF_BIRTH = "onboarding_time_of_birth" | ||
const val NAME = "onboarding_name" | ||
const val GENDER = "onboarding_gender" | ||
const val ACCESS = "onboarding_access" | ||
const val COMPLETE_FIRST = "onboarding_complete_first" | ||
const val COMPLETE_SECOND = "onboarding_complete_second" | ||
} | ||
|
||
object Home { | ||
const val ROUTE = "home_route" | ||
const val HOME = "home" | ||
const val ALARM_ADD_EDIT = "alarm_add_edit" | ||
} | ||
|
||
object MyPage { | ||
const val ROUTE = "mypage_route" | ||
const val MYPAGE = "mypage" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
core/common/src/main/java/com/yapp/common/navigation/destination/HomeDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.yapp.common.navigation.destination | ||
|
||
import com.yapp.common.navigation.Routes | ||
|
||
sealed class HomeDestination(val route: String) { | ||
data object Route : HomeDestination(Routes.Home.ROUTE) | ||
data object Home : HomeDestination(Routes.Home.HOME) | ||
data object AlarmAddEdit : HomeDestination(Routes.Home.ALARM_ADD_EDIT) | ||
} |
8 changes: 8 additions & 0 deletions
8
core/common/src/main/java/com/yapp/common/navigation/destination/MyPageDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.yapp.common.navigation.destination | ||
|
||
import com.yapp.common.navigation.Routes | ||
|
||
sealed class MyPageDestination(val route: String) { | ||
data object Route : MyPageDestination(Routes.MyPage.ROUTE) | ||
data object MyPage : MyPageDestination(Routes.MyPage.MYPAGE) | ||
} |
24 changes: 24 additions & 0 deletions
24
core/common/src/main/java/com/yapp/common/navigation/destination/OnboardingDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.yapp.common.navigation.destination | ||
|
||
import com.yapp.common.navigation.Routes | ||
|
||
sealed class OnboardingDestination(val route: String) { | ||
data object Route : OnboardingDestination(Routes.Onboarding.ROUTE) | ||
data object Explain : OnboardingDestination(Routes.Onboarding.EXPLAIN) | ||
data object AlarmTimeSelection : OnboardingDestination(Routes.Onboarding.ALARM_TIME_SELECTION) | ||
data object Birthday : OnboardingDestination(Routes.Onboarding.BIRTHDAY) | ||
data object TimeOfBirth : OnboardingDestination(Routes.Onboarding.TIME_OF_BIRTH) | ||
data object Name : OnboardingDestination(Routes.Onboarding.NAME) | ||
data object Gender : OnboardingDestination(Routes.Onboarding.GENDER) | ||
data object Access : OnboardingDestination(Routes.Onboarding.ACCESS) | ||
data object Complete1 : OnboardingDestination(Routes.Onboarding.COMPLETE_FIRST) | ||
data object Complete2 : OnboardingDestination(Routes.Onboarding.COMPLETE_SECOND) | ||
|
||
companion object { | ||
val routes = listOf(Explain, AlarmTimeSelection, Birthday, TimeOfBirth, Name, Gender, Access, Complete1, Complete2) | ||
|
||
fun nextRoute(currentStep: Int): String? { | ||
return routes.getOrNull(currentStep)?.route | ||
} | ||
} | ||
} |
13 changes: 6 additions & 7 deletions
13
...m/yapp/navigator/navigation/MainNavTab.kt → ...gation/destination/TopLevelDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
package com.yapp.navigator.navigation | ||
package com.yapp.common.navigation.destination | ||
|
||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.StringRes | ||
import com.yapp.home.HomeRoute | ||
import com.yapp.mypage.MypageRoute | ||
import com.yapp.common.navigation.Routes | ||
|
||
enum class MainNavTab( | ||
enum class TopLevelDestination( | ||
@DrawableRes val iconId: Int, | ||
@StringRes val titleId: Int, | ||
val route: String, | ||
) { | ||
HOME( | ||
iconId = core.designsystem.R.drawable.ic_launcher_foreground, | ||
titleId = core.designsystem.R.string.app_name, | ||
route = HomeRoute.HOME, | ||
route = Routes.Home.ROUTE, | ||
), | ||
MYPAGE( | ||
iconId = core.designsystem.R.drawable.ic_launcher_foreground, | ||
titleId = core.designsystem.R.string.app_name, | ||
route = MypageRoute.MYPAGE, | ||
route = Routes.MyPage.MYPAGE, | ||
), | ||
; | ||
|
||
companion object { | ||
operator fun contains(route: String): Boolean = entries.any { it.route == route } | ||
fun find(route: String): MainNavTab? = entries.find { it.route == route } | ||
fun find(route: String): TopLevelDestination? = entries.find { it.route == route } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
core/common/src/main/java/com/yapp/common/navigation/extensions/SharedViewModelExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.yapp.common.navigation.extensions | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import androidx.navigation.NavBackStackEntry | ||
import androidx.navigation.NavController | ||
|
||
@Composable | ||
inline fun <reified T : ViewModel> NavBackStackEntry.sharedViewModel(navController: NavController): T { | ||
val navGraphRoute = destination.parent?.route ?: return viewModel() | ||
val parentEntry = remember(this) { | ||
navController.getBackStackEntry(navGraphRoute) | ||
} | ||
return viewModel(parentEntry) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.yapp.home | ||
|
||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.navigation | ||
import com.yapp.alarm.AlarmAddEditRoute | ||
import com.yapp.common.navigation.OrbitNavigator | ||
import com.yapp.common.navigation.destination.HomeDestination | ||
|
||
fun NavGraphBuilder.homeNavGraph( | ||
navigator: OrbitNavigator, | ||
) { | ||
navigation( | ||
route = HomeDestination.Route.route, | ||
startDestination = HomeDestination.Home.route, | ||
) { | ||
composable(route = HomeDestination.Home.route) { | ||
HomeRoute() | ||
} | ||
|
||
composable(route = HomeDestination.AlarmAddEdit.route) { | ||
AlarmAddEditRoute() | ||
} | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
feature/home/src/main/java/com/yapp/home/HomeNavigation.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,7 @@ plugins { | |
android { | ||
setNamespace("feature.myapge") | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.common) | ||
} |
20 changes: 20 additions & 0 deletions
20
feature/mypage/src/main/java/com/yapp/mypage/MyPageNavGraph.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.yapp.mypage | ||
|
||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.navigation | ||
import com.yapp.common.navigation.OrbitNavigator | ||
import com.yapp.common.navigation.destination.MyPageDestination | ||
|
||
fun NavGraphBuilder.myPageNavGraph( | ||
navigator: OrbitNavigator, | ||
) { | ||
navigation( | ||
route = MyPageDestination.Route.route, | ||
startDestination = MyPageDestination.MyPage.route, | ||
) { | ||
composable(route = MyPageDestination.MyPage.route) { | ||
MypageRoute() | ||
} | ||
} | ||
} |
14 changes: 0 additions & 14 deletions
14
feature/mypage/src/main/java/com/yapp/mypage/MyPageNavigation.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
feature/navigator/src/main/java/com/yapp/navigator/MainBottomNavigationBar.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
p4
단순궁금!
혹시 null 반환되면 어떤 동작이 일어나나요?
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.
null 이면
return viewmodel()
이 호출되서 해당 composable에 해당하는 뷰모델이 만들어지쥬