@momo-kits/native-kits 0.300.3-debug → 0.300.3

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 (143) hide show
  1. package/package.json +1 -1
  2. package/build.gradle.kts +0 -13
  3. package/compose/build.gradle.kts +0 -189
  4. package/compose/build.gradle.kts.backup +0 -189
  5. package/compose/compose.podspec +0 -49
  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 -12
  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 -151
  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 -124
  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 -831
  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 -65
  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 -49
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
  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 -189
  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 -266
  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 -223
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -264
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -185
  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 -220
  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 -552
  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 -125
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -207
  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 -176
  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/KitDesignSystem.kt +0 -18
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -282
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -51
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -52
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -299
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -129
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -106
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -211
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -398
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -595
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -148
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -40
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -184
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -225
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -169
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -357
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -83
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -75
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -326
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -364
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -132
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +0 -33
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -135
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -91
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -9
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -71
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -105
  129. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +0 -47
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -40
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -36
  133. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
  134. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -66
  135. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -213
  136. package/gradle/libs.versions.toml +0 -79
  137. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  138. package/gradle/wrapper/gradle-wrapper.properties +0 -10
  139. package/gradle.properties +0 -28
  140. package/gradlew +0 -252
  141. package/gradlew.bat +0 -94
  142. package/ios-demo/README.md +0 -120
  143. package/settings.gradle.kts +0 -64
@@ -1,398 +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
- // AI-GENERATED START: dismiss through the typed navigator target
26
- import vn.momo.maxapi.contract.navigation.model.DismissTarget
27
- // AI-GENERATED END: dismiss through the typed navigator target
28
- import kotlin.time.Duration.Companion.milliseconds
29
-
30
- class Navigator(
31
- private val navController: NavController,
32
- private val maxApi: IMaxApi?,
33
- private val registry: DynamicScreenRegistry
34
- ) {
35
- private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
36
-
37
- // currentScreen() reads the root back stack, so it never sees the nested tab NavHost.
38
- internal var tabBackHandler: (() -> Unit)? = null
39
-
40
- private fun currentScreen(): DynamicScreen? {
41
- val entry = navController.currentBackStackEntry ?: return null
42
- val id = runCatching { entry.toRoute<DynamicScreenRoute>().id }.getOrNull()
43
- ?: runCatching { entry.toRoute<DynamicDialogRoute>().id }.getOrNull()
44
- ?: return null
45
- return registry.getScreen(id)
46
- }
47
-
48
- fun push(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
49
- val route = registry.register(screenName, content, options)
50
- navController.navigate(DynamicScreenRoute(route.id))
51
- }
52
-
53
- fun replace(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
54
- val replacedScreen = currentScreen()
55
- replacedScreen?.let { registry.unregisterScreen(it.id) }
56
- navController.popBackStack()
57
- push(screenName, content, options)
58
- }
59
-
60
- fun onBackSafe(callBack: (() -> Unit)? = null) {
61
- tabBackHandler?.let {
62
- it()
63
- return
64
- }
65
- val currentScreen = currentScreen()
66
- val options = currentScreen?.options
67
- if (options?.onBackHandler != null) {
68
- options.onBackHandler.invoke()
69
- return
70
- }
71
- val preventBack = options?.headerBackProps?.preventBack
72
- if (preventBack != null) {
73
- showModal(
74
- content = {
75
- PopupNotify(preventBack.copy(
76
- primary = PopupAction(
77
- title = preventBack.primary?.title ?: "",
78
- onPress = {
79
- preventBack.primary?.onPress?.invoke()
80
- pop(2, callBack) // close popup notify, then close the screen
81
- }
82
- )
83
- ))
84
- }
85
- )
86
- } else {
87
- pop(1, callBack)
88
- }
89
- }
90
-
91
- // The swipe-back opt-out predicate in StackScreen needs this: the root screen must keep custom
92
- // back handling so it still reaches maxApi.dismiss.
93
- // Public: the iOS host asks this to decide whether the kit owns the swipe on this screen.
94
- fun canPop(): Boolean = navController.previousBackStackEntry != null
95
-
96
- fun pop(count: Int = 1, callBack: (() -> Unit)? = null) {
97
- scope.launch {
98
- repeat(count) {
99
- if (OverplayComponentRegistry.getOverplayType() == OverplayComponentType.SNACK_BAR){
100
- dismissScreen()
101
- OverplayComponentRegistry.hardClearAfterDismiss()
102
- }
103
- else if (OverplayComponentRegistry.isOverplayShowing()){
104
- dismissOverplay()
105
- } else {
106
- dismissScreen()
107
- }
108
- }
109
- callBack?.invoke()
110
- }
111
- }
112
- private suspend fun dismissOverplay(isDelay: Boolean = true) {
113
- OverplayComponentRegistry.clear()
114
- if (isDelay) delay(300L.milliseconds)
115
- OverplayComponentRegistry.hardClearAfterDismiss()
116
- }
117
-
118
- private suspend fun dismissScreen() {
119
- if (navController.previousBackStackEntry != null){
120
- val dismissing = currentScreen()
121
- navController.popBackStack()
122
- delay(STACK_TRANSITION_DURATION.milliseconds)
123
- dismissing?.let { registry.unregisterScreen(it.id) }
124
- } else {
125
- // AI-GENERATED START: preserve root-screen dismissal
126
- maxApi?.dismiss(DismissTarget.Current()) {}
127
- // AI-GENERATED END: preserve root-screen dismissal
128
- }
129
- }
130
-
131
- fun present(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
132
- val route = registry.register(screenName, content, options)
133
- navController.navigate(DynamicDialogRoute(route.id))
134
- }
135
-
136
- fun reset(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
137
- registry.unregisterAll()
138
-
139
- val route = registry.register(screenName, content, options)
140
- navController.navigate(DynamicScreenRoute(route.id)) {
141
- popUpTo(0) { inclusive = true }
142
- }
143
- }
144
-
145
- fun showModal(
146
- content: @Composable () -> Unit,
147
- barrierDismissible: Boolean = true,
148
- onDismiss: (() -> Unit)? = null
149
- ){
150
- val id = currentScreen()?.id ?: -1
151
- OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.MODAL, false, barrierDismissible, onDismiss)
152
- }
153
-
154
- fun showBottomSheet(
155
- content: @Composable () -> Unit,
156
- isSurface: Boolean = false,
157
- barrierDismissible: Boolean = true,
158
- onDismiss: (() -> Unit)? = null,
159
- bottomSheetHeader: BottomHeader? = null,
160
- draggable: Boolean = true,
161
- useBottomInset: Boolean = true,
162
- footerComponent: (@Composable () -> Unit)? = null
163
- ){
164
- val id = currentScreen()?.id ?: -1
165
- OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.BOTTOM_SHEET, isSurface, barrierDismissible, onDismiss, bottomSheetHeader, draggable, useBottomInset, footerComponent)
166
- }
167
-
168
- fun showSnackBar(snackBar: SnackBar, onDismiss: (() -> Unit)? = null) {
169
- val id = currentScreen()?.id ?: -1
170
- scope.launch {
171
- OverplayComponentRegistry.registerOverplay(
172
- id = id,
173
- content = {
174
- SnackBar(snackBar, onDismiss)
175
- },
176
- type = OverplayComponentType.SNACK_BAR,
177
- onDismiss = onDismiss
178
- )
179
- }
180
- }
181
-
182
- fun hideSnackBar() {
183
- scope.launch {
184
- OverplayComponentRegistry.clear()
185
- delay(250L.milliseconds)
186
- OverplayComponentRegistry.hardClearAfterDismiss()
187
- }
188
- }
189
-
190
- fun dispose(){
191
- scope.cancel()
192
- }
193
- }
194
-
195
- val LocalNavigator = staticCompositionLocalOf<Navigator> {
196
- error("No NavigationStack provided")
197
- }
198
-
199
- @Serializable
200
- data class DynamicScreenRoute(val id: Int)
201
-
202
- @Serializable
203
- data class DynamicDialogRoute(val id: Int)
204
-
205
- data class DynamicScreen(
206
- val id: Int,
207
- val name: String,
208
- val content: @Composable () -> Unit,
209
- var options: NavigationOptions? = null
210
- )
211
-
212
- class DynamicScreenRegistry {
213
- private val screens = mutableMapOf<Int, DynamicScreen>()
214
-
215
- fun register(screenName: String, content: @Composable () -> Unit, options: NavigationOptions?): DynamicScreenRoute {
216
- val id = nextGlobalId()
217
- screens[id] = DynamicScreen(
218
- id = id,
219
- name = screenName,
220
- content = content,
221
- options = options
222
- )
223
- return DynamicScreenRoute(id)
224
- }
225
-
226
- fun nextId(): Int = nextGlobalId()
227
-
228
- fun bind(id: Int, screenName: String, content: @Composable () -> Unit, options: NavigationOptions?) {
229
- screens[id] = DynamicScreen(
230
- id = id,
231
- name = screenName,
232
- content = content,
233
- options = options
234
- )
235
- advanceGlobalIdPast(id) // keep counter ahead after process-death restore
236
- }
237
-
238
- fun unregisterScreen(id: Int) {
239
- screens.remove(id)
240
- }
241
-
242
- // Gesture pops go through composeNavigator.popBackStack() inside NavHost and never reach
243
- // Navigator.dismissScreen(), so screens would leak without a stack-driven prune.
244
- fun retainOnly(ids: Set<Int>) {
245
- val stale = screens.keys.filter { it !in ids }
246
- for (id in stale) {
247
- screens.remove(id)
248
- }
249
- }
250
-
251
- fun unregisterAll(){
252
- val ids = screens.keys.toList()
253
- for (id in ids) {
254
- unregisterScreen(id)
255
- }
256
- }
257
-
258
- fun getScreen(id: Int): DynamicScreen? = screens[id]
259
-
260
- fun setOptions(id: Int, options: NavigationOptions){
261
- screens[id]?.options = options
262
- }
263
-
264
- companion object {
265
- private var globalIdCounter = 1
266
-
267
- private fun nextGlobalId(): Int = globalIdCounter++
268
-
269
- private fun advanceGlobalIdPast(id: Int) {
270
- if (id >= globalIdCounter) globalIdCounter = id + 1
271
- }
272
- }
273
- }
274
-
275
- val LocalDynamicScreenRegistry = staticCompositionLocalOf<DynamicScreenRegistry?> { null }
276
-
277
-
278
- sealed class OverplayComponentParams {
279
- class Modal(
280
- val onDismiss: (() -> Unit)? = null,
281
- val barrierDismissible: Boolean = true
282
- ) : OverplayComponentParams()
283
-
284
- class BottomSheet(
285
- val isSurface: Boolean = false,
286
- val onDismiss: (() -> Unit)? = null,
287
- val barrierDismissible: Boolean = true,
288
- val bottomSheetHeader: BottomHeader? = null,
289
- val draggable: Boolean = true,
290
- val useBottomInset: Boolean = true,
291
- val footerComponent: (@Composable () -> Unit)? = null,
292
- ) : OverplayComponentParams()
293
-
294
- class SnackBar : OverplayComponentParams()
295
- }
296
-
297
- data class OverplayComponent(
298
- val id: Int,
299
- val type: OverplayComponentType? = null,
300
- val content: @Composable () -> Unit,
301
- val params: OverplayComponentParams? = null
302
- )
303
-
304
- enum class OverplayComponentType {
305
- MODAL, BOTTOM_SHEET, SNACK_BAR
306
- }
307
-
308
- object OverplayComponentRegistry {
309
- private var currentOverlayComponent : MutableState<OverplayComponent?> = mutableStateOf(null)
310
- private var requestClose: (() -> Unit)? = null
311
- internal fun bindClose(handler: (() -> Unit)?) {
312
- requestClose = handler
313
- }
314
-
315
- fun registerOverplay(
316
- id: Int,
317
- content: @Composable () -> Unit,
318
- type: OverplayComponentType,
319
- isSurface: Boolean = false,
320
- barrierDismissible: Boolean = true,
321
- onDismiss: (() -> Unit)?,
322
- bottomSheetHeader: BottomHeader? = null,
323
- draggable: Boolean = true,
324
- useBottomInset: Boolean = true,
325
- footerComponent: (@Composable () -> Unit)? = null,
326
- ){
327
- val params = when(type){
328
- OverplayComponentType.MODAL -> OverplayComponentParams.Modal(onDismiss, barrierDismissible)
329
- OverplayComponentType.BOTTOM_SHEET -> OverplayComponentParams.BottomSheet(isSurface, onDismiss, barrierDismissible, bottomSheetHeader, draggable, useBottomInset, footerComponent)
330
- OverplayComponentType.SNACK_BAR -> OverplayComponentParams.SnackBar()
331
- }
332
-
333
- currentOverlayComponent.value = OverplayComponent(
334
- id = id,
335
- type = type,
336
- content = content,
337
- params = params
338
- )
339
- }
340
-
341
- fun isOverplayShowing(): Boolean = currentOverlayComponent.value != null
342
-
343
- fun getOverplayType(): OverplayComponentType? = currentOverlayComponent.value?.type
344
-
345
- fun currentRootId(): Int? = currentOverlayComponent.value?.id
346
-
347
- fun clear(){
348
- if (requestClose != null) {
349
- requestClose?.invoke()
350
- } else {
351
- currentOverlayComponent.value = null
352
- }
353
- }
354
-
355
- internal fun hardClearAfterDismiss() {
356
- currentOverlayComponent.value = null
357
- requestClose = null
358
- }
359
-
360
- @Composable
361
- internal fun OverlayComponent(){
362
- val overplay = currentOverlayComponent.value ?: return
363
-
364
- when (val params = overplay.params) {
365
- is OverplayComponentParams.BottomSheet -> {
366
- BottomSheet(
367
- content = overplay.content,
368
- header = params.bottomSheetHeader ?: Title(),
369
- isSurface = params.isSurface,
370
- barrierDismissible = params.barrierDismissible,
371
- draggable = params.draggable,
372
- useBottomInset = params.useBottomInset,
373
- footerComponent = params.footerComponent,
374
- onDismiss = params.onDismiss
375
- )
376
- }
377
-
378
- is OverplayComponentParams.Modal -> {
379
- ModalScreen(
380
- content = overplay.content,
381
- barrierDismissible = params.barrierDismissible,
382
- onDismiss = params.onDismiss
383
- )
384
- }
385
-
386
- is OverplayComponentParams.SnackBar -> {
387
- Box(
388
- modifier = Modifier.fillMaxSize(),
389
- contentAlignment = Alignment.BottomCenter
390
- ) {
391
- overplay.content()
392
- }
393
- }
394
-
395
- null -> {}
396
- }
397
- }
398
- }
@@ -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
-