-
Notifications
You must be signed in to change notification settings - Fork 102
(FEAT)[#422] Router - 추가 적용 #520
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 17 commits
2619cf2
3bfb09a
13450c0
b50b367
eb61a5c
c582315
92b6515
d123c17
e98b684
08ded06
fb95ac2
b0723f1
40a0260
39b1776
a640a3b
eb67da0
22dd11e
f1a42d7
bcb2ddb
e68c283
e06ec15
96ee20a
e7fc219
da9e2d1
0522371
dd27ac3
6537d19
c7eddf6
e5653eb
471024a
35dc54e
ca458d9
bdc068f
7e0aae8
84c440d
e2fff12
c59f0a5
13315e5
644dda6
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 |
|---|---|---|
|
|
@@ -4,20 +4,13 @@ import androidx.compose.runtime.Composable | |
| import androidx.compose.runtime.remember | ||
| import androidx.navigation.NavDestination | ||
| import androidx.navigation.NavDestination.Companion.hasRoute | ||
| import androidx.navigation.NavGraph.Companion.findStartDestination | ||
| import androidx.navigation.NavHostController | ||
| import androidx.navigation.compose.currentBackStackEntryAsState | ||
| import androidx.navigation.compose.rememberNavController | ||
| import androidx.navigation.navOptions | ||
| import com.droidknights.app.core.navigation.MainTabRoute | ||
| import com.droidknights.app.core.navigation.Route | ||
| import com.droidknights.app.feature.bookmark.navigation.navigateBookmark | ||
| import com.droidknights.app.feature.home.navigation.navigateHome | ||
| import com.droidknights.app.feature.session.navigation.navigateSessionDetail | ||
| import com.droidknights.app.feature.setting.navigation.navigateSetting | ||
|
|
||
| internal class MainNavigator( | ||
| val navController: NavHostController, | ||
| private val onTabClick: (tab: MainTab, saveState: Boolean, launchSingleTop: Boolean) -> Unit, | ||
| ) { | ||
| private val currentDestination: NavDestination? | ||
| @Composable get() = navController | ||
|
|
@@ -30,49 +23,23 @@ internal class MainNavigator( | |
| currentDestination?.hasRoute(tab::class) == true | ||
| } | ||
|
|
||
| fun navigate(tab: MainTab) { | ||
| val navOptions = navOptions { | ||
| popUpTo(navController.graph.findStartDestination().id) { | ||
| saveState = true | ||
| } | ||
| launchSingleTop = true | ||
| restoreState = true | ||
| } | ||
|
|
||
| when (tab) { | ||
| MainTab.SETTING -> navController.navigateSetting(navOptions) | ||
| MainTab.HOME -> navController.navigateHome(navOptions) | ||
| MainTab.BOOKMARK -> navController.navigateBookmark(navOptions) | ||
| } | ||
| } | ||
|
|
||
| fun navigateSessionDetail(sessionId: String) { | ||
| navController.navigateSessionDetail(sessionId) | ||
| } | ||
|
|
||
| private fun popBackStack() { | ||
| navController.popBackStack() | ||
| } | ||
|
|
||
| fun popBackStackIfNotHome() { | ||
| if (!isSameCurrentDestination<MainTabRoute.Home>()) { | ||
| popBackStack() | ||
| } | ||
| } | ||
|
|
||
| private inline fun <reified T : Route> isSameCurrentDestination(): Boolean { | ||
| return navController.currentDestination?.hasRoute<T>() == true | ||
| } | ||
| fun navigate(tab: MainTab) = onTabClick(tab, SAVE_STATE, LAUNCH_SINGLE_TOP) | ||
|
|
||
| @Composable | ||
| fun shouldShowBottomBar() = MainTab.contains { | ||
| currentDestination?.hasRoute(it::class) == true | ||
| } | ||
|
|
||
| companion object { | ||
| private const val SAVE_STATE = true | ||
| private const val LAUNCH_SINGLE_TOP = true | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| internal fun rememberMainNavigator( | ||
| onTabClick: (tab: MainTab, saveState: Boolean, launchSingleTop: Boolean) -> Unit, | ||
| navController: NavHostController = rememberNavController(), | ||
| ): MainNavigator = remember(navController) { | ||
| MainNavigator(navController) | ||
| MainNavigator(navController, onTabClick) | ||
|
||
| } | ||
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.
👍