Skip to content

Commit 167ddcc

Browse files
committed
✨ Feat: AppNavHost 구현
1 parent cd5a37b commit 167ddcc

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.twix.navigation
2+
3+
import androidx.compose.animation.core.FastOutSlowInEasing
4+
import androidx.compose.animation.core.tween
5+
import androidx.compose.animation.slideInHorizontally
6+
import androidx.compose.animation.slideOutHorizontally
7+
import androidx.compose.foundation.layout.fillMaxSize
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.runtime.remember
10+
import androidx.compose.ui.Modifier
11+
import androidx.navigation.compose.NavHost
12+
import androidx.navigation.compose.rememberNavController
13+
import com.twix.navigation.base.NavGraphContributor
14+
import org.koin.compose.getKoin
15+
16+
@Composable
17+
fun AppNavHost() {
18+
val navController = rememberNavController()
19+
val koin = getKoin()
20+
val contributors = remember {
21+
koin.getAll<NavGraphContributor>().sortedBy { it.priority }
22+
}
23+
val start = contributors
24+
.firstOrNull { it.graphRoute == NavRoutes.LoginGraph }
25+
?.graphRoute
26+
?: error("해당 Graph를 찾을 수 없습니다.")
27+
val duration = 300
28+
29+
NavHost(
30+
navController = navController,
31+
startDestination = start.route,
32+
enterTransition = {
33+
slideInHorizontally(
34+
initialOffsetX = { fullWidth -> fullWidth },
35+
animationSpec = tween(duration, easing = FastOutSlowInEasing)
36+
)
37+
},
38+
exitTransition = {
39+
slideOutHorizontally(
40+
targetOffsetX = { fullWidth -> -fullWidth },
41+
animationSpec = tween(duration, easing = FastOutSlowInEasing)
42+
)
43+
},
44+
popEnterTransition = {
45+
slideInHorizontally(
46+
initialOffsetX = { fullWidth -> -fullWidth },
47+
animationSpec = tween(duration, easing = FastOutSlowInEasing)
48+
)
49+
},
50+
popExitTransition = {
51+
slideOutHorizontally(
52+
targetOffsetX = { fullWidth -> fullWidth },
53+
animationSpec = tween(duration, easing = FastOutSlowInEasing)
54+
)
55+
},
56+
modifier = Modifier.fillMaxSize()
57+
) {
58+
contributors.forEach { with(it) { registerGraph(navController) } }
59+
}
60+
}

0 commit comments

Comments
 (0)