@momo-kits/native-kits 0.164.1-beta.19-debug → 0.164.1-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/package.json +1 -1
  2. package/build.gradle.kts +0 -11
  3. package/compose/build.gradle.kts +0 -190
  4. package/compose/build.gradle.kts.backup +0 -190
  5. package/compose/compose.podspec +0 -47
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -14
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -150
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +0 -52
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -106
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +0 -183
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +0 -207
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +0 -39
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +0 -86
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +0 -76
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +0 -76
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +0 -293
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +0 -33
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -826
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -269
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +0 -110
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +0 -378
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +0 -69
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -82
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -356
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -113
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -128
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -542
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -23
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -76
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -231
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -134
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -475
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -114
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -214
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -240
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -216
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -259
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -182
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -343
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -41
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -84
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -40
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -328
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -97
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -310
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -90
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -323
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -217
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -473
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -199
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -91
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -470
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -88
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -131
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -203
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -175
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -234
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -188
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -16
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -188
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -263
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -52
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -38
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -39
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -52
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -299
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -129
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -103
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -191
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -395
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -595
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -157
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -39
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -177
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -225
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -169
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -320
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -81
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -309
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -34
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -360
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -132
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -18
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -91
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -9
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -69
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -105
  124. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -40
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -127
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -40
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -66
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -220
  130. package/gradle/libs.versions.toml +0 -69
  131. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  132. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  133. package/gradle.properties +0 -26
  134. package/gradlew +0 -252
  135. package/gradlew.bat +0 -94
  136. package/ios-demo/README.md +0 -120
  137. package/local.properties +0 -8
  138. package/settings.gradle.kts +0 -64
@@ -1,191 +0,0 @@
1
- package vn.momo.kits.navigation
2
-
3
- import androidx.compose.animation.core.tween
4
- import androidx.compose.animation.fadeIn
5
- import androidx.compose.animation.slideInVertically
6
- import androidx.compose.animation.slideOutVertically
7
- import androidx.compose.runtime.Composable
8
- import androidx.compose.runtime.CompositionLocalProvider
9
- import androidx.compose.runtime.DisposableEffect
10
- import androidx.compose.runtime.LaunchedEffect
11
- import androidx.compose.runtime.mutableStateOf
12
- import androidx.compose.runtime.remember
13
- import androidx.compose.runtime.saveable.rememberSaveable
14
- import androidx.compose.runtime.staticCompositionLocalOf
15
- import androidx.compose.ui.unit.Dp
16
- import androidx.navigation.compose.NavHost
17
- import androidx.navigation.compose.composable
18
- import androidx.navigation.compose.rememberNavController
19
- import androidx.navigation.toRoute
20
- import kotlinx.coroutines.delay
21
- import kotlinx.coroutines.flow.collectLatest
22
- import vn.momo.kits.application.LocalContext
23
- import vn.momo.kits.application.LocalLocalize
24
- import vn.momo.kits.application.Localize
25
- import vn.momo.kits.application.MiniAppContext
26
- import vn.momo.kits.const.AppNavigationBar
27
- import vn.momo.kits.const.AppStatusBar
28
- import vn.momo.kits.const.AppTheme
29
- import vn.momo.kits.const.Theme
30
- import vn.momo.kits.const.defaultTheme
31
- import vn.momo.kits.platform.ProvideNavigationEventDispatcherOwner
32
- import vn.momo.kits.platform.ProvideOsFontScale
33
- import vn.momo.kits.utils.getAppStatusBarHeight
34
- import vn.momo.kits.utils.getNavigationBarHeight
35
- import vn.momo.maxapi.IMaxApi
36
- import kotlin.time.Duration.Companion.milliseconds
37
-
38
- @Composable
39
- fun NavigationContainer(
40
- initialScreenName: String,
41
- initialScreen: @Composable () -> Unit,
42
- options: NavigationOptions? = null,
43
- initialTheme: Theme = defaultTheme,
44
- miniAppContext: MiniAppContext? = null,
45
- maxApi: IMaxApi? = null,
46
- setNavigator: ((Navigator) -> Unit)? = null,
47
- statusBarHeight: Dp? = null,
48
- localize: Localize? = null,
49
- ) {
50
- val navController = rememberNavController()
51
- val registry = remember { DynamicScreenRegistry() }
52
- val navigator = remember { Navigator(navController = navController, maxApi = maxApi, registry = registry) }
53
- val statusBarHeight = statusBarHeight ?: getAppStatusBarHeight()
54
- val navigationBarHeight = getNavigationBarHeight()
55
-
56
- val parentContext = LocalContext.current
57
- val mergedContext = MiniAppContext.merge(parentContext, miniAppContext)
58
-
59
- val stackTransition = remember { StackTransitionCoordinator() }
60
- val theme = remember { mutableStateOf(initialTheme) }
61
- val fallbackLocalize = remember { Localize() }
62
-
63
- val resolvedLocalize = localize ?: fallbackLocalize
64
-
65
- LaunchedEffect(maxApi, resolvedLocalize) {
66
- val api = maxApi ?: return@LaunchedEffect
67
- runCatching {
68
- api.getLanguage(callback = { data ->
69
- if (parseLanguage(data) == Localize.EN) {
70
- resolvedLocalize.changeLanguage(Localize.EN)
71
- }
72
- })
73
- }
74
- }
75
-
76
- val screenId = rememberSaveable { registry.nextId() }
77
- registry.bind(screenId, initialScreenName, initialScreen, options)
78
- val startDestination = remember(screenId) { DynamicScreenRoute(screenId) }
79
-
80
- ProvideOsFontScale {
81
- ProvideNavigationEventDispatcherOwner {
82
- CompositionLocalProvider(
83
- LocalNavigator provides navigator,
84
- LocalDynamicScreenRegistry provides registry,
85
- LocalMaxApi provides maxApi,
86
- AppTheme provides theme.value,
87
- AppStatusBar provides statusBarHeight,
88
- AppNavigationBar provides navigationBarHeight,
89
- LocalContext provides mergedContext,
90
- LocalLocalize provides resolvedLocalize,
91
- LocalStackTransition provides stackTransition,
92
- ) {
93
- LaunchedEffect(Unit) {
94
- setNavigator?.invoke(navigator)
95
- }
96
-
97
- SwipeBackHaptic(maxApi)
98
-
99
- // Gesture pops never reach Navigator.dismissScreen(), so prune the registry from
100
- // the back stack itself. collectLatest lets a rapid re-push cancel a pending prune.
101
- LaunchedEffect(navController, registry) {
102
- navController.currentBackStack.collectLatest { entries ->
103
- delay(STACK_TRANSITION_DURATION.milliseconds)
104
- val aliveIds = entries.mapNotNullTo(mutableSetOf()) { entry ->
105
- runCatching { entry.toRoute<DynamicScreenRoute>().id }.getOrNull()
106
- ?: runCatching { entry.toRoute<DynamicDialogRoute>().id }.getOrNull()
107
- }
108
- aliveIds.add(screenId)
109
- registry.retainOnly(aliveIds)
110
- }
111
- }
112
-
113
- // The transitions must live on the NavHost call site, not on the destinations:
114
- // NavHost.uikit computes isDefaultTransition from these arguments alone, and while
115
- // it is true the library paints its own hard-coded black iOS blackout that would
116
- // sit over the pink scrim.
117
- NavHost(
118
- navController,
119
- startDestination = startDestination,
120
- enterTransition = { stackEnter() },
121
- exitTransition = { stackExit() },
122
- popEnterTransition = { stackPopEnter() },
123
- popExitTransition = { stackPopExit() },
124
- ) {
125
- composable<DynamicScreenRoute> { backStackEntry ->
126
- val route = backStackEntry.toRoute<DynamicScreenRoute>()
127
- val screen = registry.getScreen(route.id)
128
-
129
- if (screen != null) {
130
- StackTransitionDecor(id = route.id, isStackRoute = true) {
131
- StackScreen(
132
- id = route.id,
133
- name = screen.name,
134
- content = screen.content,
135
- navigationOptions = screen.options
136
- )
137
- }
138
- }
139
- }
140
-
141
- composable<DynamicDialogRoute>(
142
- enterTransition = {
143
- slideInVertically(
144
- animationSpec = tween(300),
145
- initialOffsetY = { it }
146
- )
147
- },
148
- exitTransition = null,
149
- popEnterTransition = { fadeIn(animationSpec = tween(0)) },
150
- popExitTransition = {
151
- slideOutVertically(
152
- animationSpec = tween(300),
153
- targetOffsetY = { it }
154
- )
155
- }
156
- ) { backStackEntry ->
157
- val route = backStackEntry.toRoute<DynamicDialogRoute>()
158
- val screen = registry.getScreen(route.id)
159
-
160
- if (screen != null) {
161
- StackTransitionDecor(id = route.id, isStackRoute = false) {
162
- StackScreen(
163
- id = route.id,
164
- name = screen.name,
165
- content = screen.content,
166
- navigationOptions = screen.options
167
- )
168
- }
169
- }
170
- }
171
- }
172
- }
173
- }
174
- }
175
-
176
- DisposableEffect(Unit) {
177
- onDispose {
178
- navigator.dispose()
179
- registry.unregisterScreen(screenId)
180
- }
181
- }
182
- }
183
-
184
- val LocalMaxApi = staticCompositionLocalOf<IMaxApi?> { null }
185
-
186
- private fun parseLanguage(raw: Map<String, Any?>?): String? {
187
- val code = (raw?.get("response") as? String)?.trim()?.lowercase()
188
- if (code.isNullOrEmpty()) return null
189
- return if (code.startsWith(Localize.EN)) Localize.EN else Localize.VI
190
- }
191
-
@@ -1,395 +0,0 @@
1
- package vn.momo.kits.navigation
2
-
3
- import androidx.compose.foundation.layout.Box
4
- import androidx.compose.foundation.layout.fillMaxSize
5
- import androidx.compose.runtime.Composable
6
- import androidx.compose.runtime.MutableState
7
- import androidx.compose.runtime.mutableStateOf
8
- import androidx.compose.runtime.staticCompositionLocalOf
9
- import androidx.compose.ui.Alignment
10
- import androidx.compose.ui.Modifier
11
- import androidx.navigation.NavController
12
- import androidx.navigation.toRoute
13
- import kotlinx.coroutines.CoroutineScope
14
- import kotlinx.coroutines.Dispatchers
15
- import kotlinx.coroutines.SupervisorJob
16
- import kotlinx.coroutines.cancel
17
- import kotlinx.coroutines.delay
18
- import kotlinx.coroutines.launch
19
- import kotlinx.serialization.Serializable
20
- import vn.momo.kits.components.PopupAction
21
- import vn.momo.kits.components.PopupNotify
22
- import vn.momo.kits.navigation.BottomHeader.*
23
- import vn.momo.kits.navigation.component.SnackBar
24
- import vn.momo.maxapi.IMaxApi
25
- import kotlin.time.Duration.Companion.milliseconds
26
-
27
- class Navigator(
28
- private val navController: NavController,
29
- private val maxApi: IMaxApi?,
30
- private val registry: DynamicScreenRegistry
31
- ) {
32
- private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
33
-
34
- // Set by BottomTab while a tab other than the first is showing. currentScreen() reads the root
35
- // back stack, so it never sees the nested tab NavHost — without this every back path except the
36
- // header button pops the whole BottomTab screen instead of returning to the first tab.
37
- internal var tabBackHandler: (() -> Unit)? = null
38
-
39
- private fun currentScreen(): DynamicScreen? {
40
- val entry = navController.currentBackStackEntry ?: return null
41
- val id = runCatching { entry.toRoute<DynamicScreenRoute>().id }.getOrNull()
42
- ?: runCatching { entry.toRoute<DynamicDialogRoute>().id }.getOrNull()
43
- ?: return null
44
- return registry.getScreen(id)
45
- }
46
-
47
- fun push(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
48
- val route = registry.register(screenName, content, options)
49
- navController.navigate(DynamicScreenRoute(route.id))
50
- }
51
-
52
- fun replace(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
53
- val replacedScreen = currentScreen()
54
- replacedScreen?.let { registry.unregisterScreen(it.id) }
55
- navController.popBackStack()
56
- push(screenName, content, options)
57
- }
58
-
59
- fun onBackSafe(callBack: (() -> Unit)? = null) {
60
- tabBackHandler?.let {
61
- it()
62
- return
63
- }
64
- val currentScreen = currentScreen()
65
- val options = currentScreen?.options
66
- if (options?.onBackHandler != null) {
67
- options.onBackHandler.invoke()
68
- return
69
- }
70
- val preventBack = options?.headerBackProps?.preventBack
71
- if (preventBack != null) {
72
- showModal(
73
- content = {
74
- PopupNotify(preventBack.copy(
75
- primary = PopupAction(
76
- title = preventBack.primary?.title ?: "",
77
- onPress = {
78
- preventBack.primary?.onPress?.invoke()
79
- pop(2, callBack) // close popup notify, then close the screen
80
- }
81
- )
82
- ))
83
- }
84
- )
85
- } else {
86
- pop(1, callBack)
87
- }
88
- }
89
-
90
- // The swipe-back opt-out predicate in StackScreen needs this: the root screen must keep custom
91
- // back handling so it still reaches maxApi.dismiss.
92
- // Public: the iOS host asks this to decide whether the kit owns the swipe on this screen.
93
- fun canPop(): Boolean = navController.previousBackStackEntry != null
94
-
95
- fun pop(count: Int = 1, callBack: (() -> Unit)? = null) {
96
- scope.launch {
97
- repeat(count) {
98
- if (OverplayComponentRegistry.getOverplayType() == OverplayComponentType.SNACK_BAR){
99
- dismissScreen()
100
- OverplayComponentRegistry.hardClearAfterDismiss()
101
- }
102
- else if (OverplayComponentRegistry.isOverplayShowing()){
103
- dismissOverplay()
104
- } else {
105
- dismissScreen()
106
- }
107
- }
108
- callBack?.invoke()
109
- }
110
- }
111
- private suspend fun dismissOverplay(isDelay: Boolean = true) {
112
- OverplayComponentRegistry.clear()
113
- if (isDelay) delay(300L.milliseconds)
114
- OverplayComponentRegistry.hardClearAfterDismiss()
115
- }
116
-
117
- private suspend fun dismissScreen() {
118
- if (navController.previousBackStackEntry != null){
119
- val dismissing = currentScreen()
120
- navController.popBackStack()
121
- delay(STACK_TRANSITION_DURATION.milliseconds)
122
- dismissing?.let { registry.unregisterScreen(it.id) }
123
- } else {
124
- maxApi?.dismiss { }
125
- }
126
- }
127
-
128
- fun present(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
129
- val route = registry.register(screenName, content, options)
130
- navController.navigate(DynamicDialogRoute(route.id))
131
- }
132
-
133
- fun reset(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
134
- registry.unregisterAll()
135
-
136
- val route = registry.register(screenName, content, options)
137
- navController.navigate(DynamicScreenRoute(route.id)) {
138
- popUpTo(0) { inclusive = true }
139
- }
140
- }
141
-
142
- fun showModal(
143
- content: @Composable () -> Unit,
144
- barrierDismissible: Boolean = true,
145
- onDismiss: (() -> Unit)? = null
146
- ){
147
- val id = currentScreen()?.id ?: -1
148
- OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.MODAL, false, barrierDismissible, onDismiss)
149
- }
150
-
151
- fun showBottomSheet(
152
- content: @Composable () -> Unit,
153
- isSurface: Boolean = false,
154
- barrierDismissible: Boolean = true,
155
- onDismiss: (() -> Unit)? = null,
156
- bottomSheetHeader: BottomHeader? = null,
157
- draggable: Boolean = true,
158
- useBottomInset: Boolean = true,
159
- footerComponent: (@Composable () -> Unit)? = null
160
- ){
161
- val id = currentScreen()?.id ?: -1
162
- OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.BOTTOM_SHEET, isSurface, barrierDismissible, onDismiss, bottomSheetHeader, draggable, useBottomInset, footerComponent)
163
- }
164
-
165
- fun showSnackBar(snackBar: SnackBar, onDismiss: (() -> Unit)? = null) {
166
- val id = currentScreen()?.id ?: -1
167
- scope.launch {
168
- OverplayComponentRegistry.registerOverplay(
169
- id = id,
170
- content = {
171
- SnackBar(snackBar, onDismiss)
172
- },
173
- type = OverplayComponentType.SNACK_BAR,
174
- onDismiss = onDismiss
175
- )
176
- }
177
- }
178
-
179
- fun hideSnackBar() {
180
- scope.launch {
181
- OverplayComponentRegistry.clear()
182
- delay(250L.milliseconds)
183
- OverplayComponentRegistry.hardClearAfterDismiss()
184
- }
185
- }
186
-
187
- fun dispose(){
188
- scope.cancel()
189
- }
190
- }
191
-
192
- val LocalNavigator = staticCompositionLocalOf<Navigator> {
193
- error("No NavigationStack provided")
194
- }
195
-
196
- @Serializable
197
- data class DynamicScreenRoute(val id: Int)
198
-
199
- @Serializable
200
- data class DynamicDialogRoute(val id: Int)
201
-
202
- data class DynamicScreen(
203
- val id: Int,
204
- val name: String,
205
- val content: @Composable () -> Unit,
206
- var options: NavigationOptions? = null
207
- )
208
-
209
- class DynamicScreenRegistry {
210
- private val screens = mutableMapOf<Int, DynamicScreen>()
211
-
212
- fun register(screenName: String, content: @Composable () -> Unit, options: NavigationOptions?): DynamicScreenRoute {
213
- val id = nextGlobalId()
214
- screens[id] = DynamicScreen(
215
- id = id,
216
- name = screenName,
217
- content = content,
218
- options = options
219
- )
220
- return DynamicScreenRoute(id)
221
- }
222
-
223
- fun nextId(): Int = nextGlobalId()
224
-
225
- fun bind(id: Int, screenName: String, content: @Composable () -> Unit, options: NavigationOptions?) {
226
- screens[id] = DynamicScreen(
227
- id = id,
228
- name = screenName,
229
- content = content,
230
- options = options
231
- )
232
- advanceGlobalIdPast(id) // keep counter ahead after process-death restore
233
- }
234
-
235
- fun unregisterScreen(id: Int) {
236
- screens.remove(id)
237
- }
238
-
239
- // Gesture pops go through composeNavigator.popBackStack() inside NavHost and never reach
240
- // Navigator.dismissScreen(), so screens would leak without a stack-driven prune.
241
- fun retainOnly(ids: Set<Int>) {
242
- val stale = screens.keys.filter { it !in ids }
243
- for (id in stale) {
244
- screens.remove(id)
245
- }
246
- }
247
-
248
- fun unregisterAll(){
249
- val ids = screens.keys.toList()
250
- for (id in ids) {
251
- unregisterScreen(id)
252
- }
253
- }
254
-
255
- fun getScreen(id: Int): DynamicScreen? = screens[id]
256
-
257
- fun setOptions(id: Int, options: NavigationOptions){
258
- screens[id]?.options = options
259
- }
260
-
261
- companion object {
262
- private var globalIdCounter = 1
263
-
264
- private fun nextGlobalId(): Int = globalIdCounter++
265
-
266
- private fun advanceGlobalIdPast(id: Int) {
267
- if (id >= globalIdCounter) globalIdCounter = id + 1
268
- }
269
- }
270
- }
271
-
272
- val LocalDynamicScreenRegistry = staticCompositionLocalOf<DynamicScreenRegistry?> { null }
273
-
274
-
275
- sealed class OverplayComponentParams {
276
- class Modal(
277
- val onDismiss: (() -> Unit)? = null,
278
- val barrierDismissible: Boolean = true
279
- ) : OverplayComponentParams()
280
-
281
- class BottomSheet(
282
- val isSurface: Boolean = false,
283
- val onDismiss: (() -> Unit)? = null,
284
- val barrierDismissible: Boolean = true,
285
- val bottomSheetHeader: BottomHeader? = null,
286
- val draggable: Boolean = true,
287
- val useBottomInset: Boolean = true,
288
- val footerComponent: (@Composable () -> Unit)? = null,
289
- ) : OverplayComponentParams()
290
-
291
- class SnackBar : OverplayComponentParams()
292
- }
293
-
294
- data class OverplayComponent(
295
- val id: Int,
296
- val type: OverplayComponentType? = null,
297
- val content: @Composable () -> Unit,
298
- val params: OverplayComponentParams? = null
299
- )
300
-
301
- enum class OverplayComponentType {
302
- MODAL, BOTTOM_SHEET, SNACK_BAR
303
- }
304
-
305
- object OverplayComponentRegistry {
306
- private var currentOverlayComponent : MutableState<OverplayComponent?> = mutableStateOf(null)
307
- private var requestClose: (() -> Unit)? = null
308
- internal fun bindClose(handler: (() -> Unit)?) {
309
- requestClose = handler
310
- }
311
-
312
- fun registerOverplay(
313
- id: Int,
314
- content: @Composable () -> Unit,
315
- type: OverplayComponentType,
316
- isSurface: Boolean = false,
317
- barrierDismissible: Boolean = true,
318
- onDismiss: (() -> Unit)?,
319
- bottomSheetHeader: BottomHeader? = null,
320
- draggable: Boolean = true,
321
- useBottomInset: Boolean = true,
322
- footerComponent: (@Composable () -> Unit)? = null,
323
- ){
324
- val params = when(type){
325
- OverplayComponentType.MODAL -> OverplayComponentParams.Modal(onDismiss, barrierDismissible)
326
- OverplayComponentType.BOTTOM_SHEET -> OverplayComponentParams.BottomSheet(isSurface, onDismiss, barrierDismissible, bottomSheetHeader, draggable, useBottomInset, footerComponent)
327
- OverplayComponentType.SNACK_BAR -> OverplayComponentParams.SnackBar()
328
- }
329
-
330
- currentOverlayComponent.value = OverplayComponent(
331
- id = id,
332
- type = type,
333
- content = content,
334
- params = params
335
- )
336
- }
337
-
338
- fun isOverplayShowing(): Boolean = currentOverlayComponent.value != null
339
-
340
- fun getOverplayType(): OverplayComponentType? = currentOverlayComponent.value?.type
341
-
342
- fun currentRootId(): Int? = currentOverlayComponent.value?.id
343
-
344
- fun clear(){
345
- if (requestClose != null) {
346
- requestClose?.invoke()
347
- } else {
348
- currentOverlayComponent.value = null
349
- }
350
- }
351
-
352
- internal fun hardClearAfterDismiss() {
353
- currentOverlayComponent.value = null
354
- requestClose = null
355
- }
356
-
357
- @Composable
358
- internal fun OverlayComponent(){
359
- val overplay = currentOverlayComponent.value ?: return
360
-
361
- when (val params = overplay.params) {
362
- is OverplayComponentParams.BottomSheet -> {
363
- BottomSheet(
364
- content = overplay.content,
365
- header = params.bottomSheetHeader ?: Title(),
366
- isSurface = params.isSurface,
367
- barrierDismissible = params.barrierDismissible,
368
- draggable = params.draggable,
369
- useBottomInset = params.useBottomInset,
370
- footerComponent = params.footerComponent,
371
- onDismiss = params.onDismiss
372
- )
373
- }
374
-
375
- is OverplayComponentParams.Modal -> {
376
- ModalScreen(
377
- content = overplay.content,
378
- barrierDismissible = params.barrierDismissible,
379
- onDismiss = params.onDismiss
380
- )
381
- }
382
-
383
- is OverplayComponentParams.SnackBar -> {
384
- Box(
385
- modifier = Modifier.fillMaxSize(),
386
- contentAlignment = Alignment.BottomCenter
387
- ) {
388
- overplay.content()
389
- }
390
- }
391
-
392
- null -> {}
393
- }
394
- }
395
- }
@@ -1,8 +0,0 @@
1
- package vn.momo.kits.navigation
2
-
3
- import androidx.compose.runtime.Composable
4
-
5
- @Composable
6
- internal expect fun RegisterScrollToTop(callback: (() -> Unit)?)
7
-
8
-