-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainNavigator.kt
More file actions
44 lines (38 loc) · 1.33 KB
/
MainNavigator.kt
File metadata and controls
44 lines (38 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.threegap.bitnagil
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hasRoute
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
class MainNavigator(
val navController: NavHostController,
) {
val startDestination = Route.Splash
private val currentDestination: NavDestination?
@Composable get() {
val currentEntry by navController.currentBackStackEntryAsState()
return currentEntry?.destination
}
internal fun navigateToHomeAndClearStack() =
navController.navigate(Route.Home) {
popUpTo(0) {
inclusive = true
}
}
@Composable
internal fun hasBottomNavigationBarRoute(): Boolean {
val destination = currentDestination
return when {
destination?.hasRoute<Route.Home>() == true -> true
else -> false
}
}
}
@Composable
fun rememberMainNavigator(navController: NavHostController = rememberNavController()): MainNavigator =
remember(navController) {
MainNavigator(navController)
}