@momo-kits/native-kits 0.162.1-beta.2 → 0.162.1-beta.3-debug

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 (136) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +189 -0
  3. package/compose/build.gradle.kts.backup +189 -0
  4. package/compose/compose.podspec +47 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +123 -0
  7. package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
  8. package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
  9. package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
  10. package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
  11. package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
  12. package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
  13. package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
  14. package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
  15. package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
  16. package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
  17. package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
  18. package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
  19. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
  20. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +52 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +109 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +183 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +207 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +39 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +294 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +826 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +109 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +378 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +80 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +113 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +543 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +23 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +76 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +140 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +188 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +112 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +477 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +214 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +240 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +216 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +259 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +180 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +331 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +97 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +310 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +323 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +217 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +199 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +91 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +470 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +88 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +131 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +203 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +177 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +234 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +188 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +306 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +188 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +270 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +2 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +35 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +2 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +253 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +129 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +94 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +163 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationEvent.kt +53 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +399 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +557 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +155 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +223 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +319 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +81 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +309 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +34 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +360 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +132 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +128 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +70 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +58 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +105 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +184 -0
  128. package/gradle/libs.versions.toml +67 -0
  129. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  130. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  131. package/gradle.properties +26 -0
  132. package/gradlew +252 -0
  133. package/gradlew.bat +94 -0
  134. package/local.properties +8 -0
  135. package/package.json +1 -1
  136. package/settings.gradle.kts +64 -0
@@ -0,0 +1,399 @@
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
+ private val onNavigationEvent: ((NavigationEvent) -> Unit)? = null
32
+ ) {
33
+ private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
34
+
35
+ private fun emit(event: NavigationEvent) {
36
+ onNavigationEvent?.invoke(event)
37
+ }
38
+
39
+ /**
40
+ * The screen currently on top of THIS container's [navController] back stack.
41
+ *
42
+ * Use this instead of [DynamicScreenRegistry.getLatestScreen], which returns the globally
43
+ * last-registered screen across every NavigationContainer. With multiple containers sharing
44
+ * the single [DynamicScreenRegistry], the global "latest" is not guaranteed to belong to this
45
+ * navController, so back/dismiss/overlay logic could read the wrong options or unregister the
46
+ * wrong screen.
47
+ */
48
+ private fun currentScreen(): DynamicScreen? {
49
+ val entry = navController.currentBackStackEntry ?: return null
50
+ val id = runCatching { entry.toRoute<DynamicScreenRoute>().id }.getOrNull()
51
+ ?: runCatching { entry.toRoute<DynamicDialogRoute>().id }.getOrNull()
52
+ ?: return null
53
+ return registry.getScreen(id)
54
+ }
55
+
56
+ fun push(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
57
+ val route = registry.register(screenName, content, options)
58
+ emit(NavigationEvent.Push(screenName, route.id))
59
+ navController.navigate(DynamicScreenRoute(route.id))
60
+ }
61
+
62
+ fun replace(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
63
+ if (navController.previousBackStackEntry != null){
64
+ val replacedScreen = currentScreen()
65
+ emit(NavigationEvent.Replace(screenName, replacedScreen?.id ?: -1))
66
+ replacedScreen?.let { registry.unregisterScreen(it.id) }
67
+ navController.popBackStack()
68
+ push(screenName, content, options)
69
+ }
70
+ }
71
+
72
+ fun onBackSafe(callBack: (() -> Unit)? = null) {
73
+ val latestScreen = currentScreen()
74
+ val options = latestScreen?.options
75
+ if (options?.onBackHandler != null) {
76
+ options.onBackHandler.invoke()
77
+ return
78
+ }
79
+ val preventBack = options?.headerBackProps?.preventBack
80
+ if (preventBack != null) {
81
+ showModal(
82
+ content = {
83
+ PopupNotify(preventBack.copy(
84
+ primary = PopupAction(
85
+ title = preventBack.primary?.title ?: "",
86
+ onPress = {
87
+ preventBack.primary?.onPress?.invoke()
88
+ pop(2, callBack) // close popup notify, then close the screen
89
+ }
90
+ )
91
+ ))
92
+ }
93
+ )
94
+ } else {
95
+ pop(1, callBack)
96
+ }
97
+ }
98
+
99
+ fun pop(count: Int = 1, callBack: (() -> Unit)? = null) {
100
+ emit(NavigationEvent.Pop(count, OverplayComponentRegistry.getOverplayType()))
101
+ scope.launch {
102
+ repeat(count) {
103
+ if (OverplayComponentRegistry.getOverplayType() == OverplayComponentType.SNACK_BAR){
104
+ dismissScreen()
105
+ OverplayComponentRegistry.hardClearAfterDismiss()
106
+ }
107
+ else if (OverplayComponentRegistry.isOverplayShowing()){
108
+ dismissOverplay()
109
+ } else {
110
+ dismissScreen()
111
+ }
112
+ }
113
+ callBack?.invoke()
114
+ }
115
+ }
116
+ private suspend fun dismissOverplay(isDelay: Boolean = true) {
117
+ OverplayComponentRegistry.clear()
118
+ if (isDelay) delay(300L.milliseconds)
119
+ OverplayComponentRegistry.hardClearAfterDismiss()
120
+ }
121
+
122
+ private suspend fun dismissScreen() {
123
+ if (navController.previousBackStackEntry != null){
124
+ // Capture the screen being dismissed BEFORE popping; after popBackStack the current
125
+ // entry is the revealed screen, so reading it post-pop would unregister the wrong one.
126
+ val dismissing = currentScreen()
127
+ navController.popBackStack()
128
+ delay(300L.milliseconds)
129
+ dismissing?.let { registry.unregisterScreen(it.id) }
130
+ } else {
131
+ maxApi?.dismiss { }
132
+ }
133
+ }
134
+
135
+ fun present(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
136
+ val route = registry.register(screenName, content, options)
137
+ emit(NavigationEvent.Present(screenName, route.id))
138
+ navController.navigate(DynamicDialogRoute(route.id))
139
+ }
140
+
141
+ fun reset(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
142
+ registry.unregisterAll()
143
+
144
+ val route = registry.register(screenName, content, options)
145
+ emit(NavigationEvent.Reset(screenName, route.id))
146
+ navController.navigate(DynamicScreenRoute(route.id)) {
147
+ popUpTo(0) { inclusive = true }
148
+ }
149
+ }
150
+
151
+ fun showModal(
152
+ content: @Composable () -> Unit,
153
+ barrierDismissible: Boolean = true,
154
+ onDismiss: (() -> Unit)? = null
155
+ ){
156
+ val id = currentScreen()?.id ?: -1
157
+ emit(NavigationEvent.ShowModal(id, barrierDismissible))
158
+ OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.MODAL, false, barrierDismissible, onDismiss)
159
+ }
160
+
161
+ fun showBottomSheet(
162
+ content: @Composable () -> Unit,
163
+ isSurface: Boolean = false,
164
+ barrierDismissible: Boolean = true,
165
+ onDismiss: (() -> Unit)? = null,
166
+ bottomSheetHeader: BottomHeader? = null
167
+ ){
168
+ val id = currentScreen()?.id ?: -1
169
+ emit(NavigationEvent.ShowBottomSheet(id, barrierDismissible))
170
+ OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.BOTTOM_SHEET, isSurface, barrierDismissible, onDismiss, bottomSheetHeader)
171
+ }
172
+
173
+ fun showSnackBar(snackBar: SnackBar, onDismiss: (() -> Unit)? = null) {
174
+ val id = currentScreen()?.id ?: -1
175
+ emit(NavigationEvent.ShowSnackBar(id))
176
+ scope.launch {
177
+ OverplayComponentRegistry.registerOverplay(
178
+ id = id,
179
+ content = {
180
+ SnackBar(snackBar, onDismiss)
181
+ },
182
+ type = OverplayComponentType.SNACK_BAR,
183
+ onDismiss = onDismiss
184
+ )
185
+ }
186
+ }
187
+
188
+ fun hideSnackBar() {
189
+ scope.launch {
190
+ OverplayComponentRegistry.clear()
191
+ delay(250L.milliseconds)
192
+ OverplayComponentRegistry.hardClearAfterDismiss()
193
+ }
194
+ }
195
+
196
+ fun dispose(){
197
+ emit(NavigationEvent.Dispose)
198
+ scope.cancel()
199
+ }
200
+ }
201
+
202
+ val LocalNavigator = staticCompositionLocalOf<Navigator> {
203
+ error("No NavigationStack provided")
204
+ }
205
+
206
+ @Serializable
207
+ data class DynamicScreenRoute(val id: Int)
208
+
209
+ @Serializable
210
+ data class DynamicDialogRoute(val id: Int)
211
+
212
+ data class DynamicScreen(
213
+ val id: Int,
214
+ val name: String,
215
+ val content: @Composable () -> Unit,
216
+ var options: NavigationOptions? = null
217
+ )
218
+
219
+ /**
220
+ * Per-container store of dynamic screens. Each [NavigationContainer] owns its own instance, so the
221
+ * number of live containers no longer matters: `getLatestScreen`/`unregisterAll` only ever see the
222
+ * screens of their own container.
223
+ *
224
+ * Ids are still drawn from a process-wide counter so they stay globally unique — this keeps the
225
+ * still-global [OverplayComponentRegistry] (which keys overlays by screen id) collision-free.
226
+ */
227
+ class DynamicScreenRegistry {
228
+ private val screens = mutableMapOf<Int, DynamicScreen>()
229
+
230
+ fun register(screenName: String, content: @Composable () -> Unit, options: NavigationOptions?): DynamicScreenRoute {
231
+ val id = nextGlobalId()
232
+ screens[id] = DynamicScreen(
233
+ id = id,
234
+ name = screenName,
235
+ content = content,
236
+ options = options
237
+ )
238
+ return DynamicScreenRoute(id)
239
+ }
240
+
241
+ fun nextId(): Int = nextGlobalId()
242
+
243
+ fun bind(id: Int, screenName: String, content: @Composable () -> Unit, options: NavigationOptions?) {
244
+ screens[id] = DynamicScreen(
245
+ id = id,
246
+ name = screenName,
247
+ content = content,
248
+ options = options
249
+ )
250
+ advanceGlobalIdPast(id) // keep counter ahead after process-death restore
251
+ }
252
+
253
+ fun unregisterScreen(id: Int) {
254
+ screens.remove(id)
255
+ }
256
+
257
+ fun getLatestScreen(): DynamicScreen?{
258
+ return screens.entries.lastOrNull()?.value
259
+ }
260
+
261
+ fun unregisterAll(){
262
+ val ids = screens.keys.toList()
263
+ for (id in ids) {
264
+ unregisterScreen(id)
265
+ }
266
+ }
267
+
268
+ fun getScreen(id: Int): DynamicScreen? = screens[id]
269
+
270
+ fun setOptions(id: Int, options: NavigationOptions){
271
+ screens[id]?.options = options
272
+ }
273
+
274
+ companion object {
275
+ private var globalIdCounter = 1
276
+
277
+ private fun nextGlobalId(): Int = globalIdCounter++
278
+
279
+ private fun advanceGlobalIdPast(id: Int) {
280
+ if (id >= globalIdCounter) globalIdCounter = id + 1
281
+ }
282
+ }
283
+ }
284
+
285
+ val LocalDynamicScreenRegistry = staticCompositionLocalOf<DynamicScreenRegistry?> { null }
286
+
287
+
288
+ sealed class OverplayComponentParams {
289
+ class Modal(
290
+ val onDismiss: (() -> Unit)? = null,
291
+ val barrierDismissible: Boolean = true
292
+ ) : OverplayComponentParams()
293
+
294
+ class BottomSheet(
295
+ val isSurface: Boolean = false,
296
+ val onDismiss: (() -> Unit)? = null,
297
+ val barrierDismissible: Boolean = true,
298
+ val bottomSheetHeader: BottomHeader? = null,
299
+ ) : OverplayComponentParams()
300
+
301
+ class SnackBar : OverplayComponentParams()
302
+ }
303
+
304
+ data class OverplayComponent(
305
+ val id: Int,
306
+ val type: OverplayComponentType? = null,
307
+ val content: @Composable () -> Unit,
308
+ val params: OverplayComponentParams? = null
309
+ )
310
+
311
+ enum class OverplayComponentType {
312
+ MODAL, BOTTOM_SHEET, SNACK_BAR
313
+ }
314
+
315
+ object OverplayComponentRegistry {
316
+ private var currentOverlayComponent : MutableState<OverplayComponent?> = mutableStateOf(null)
317
+ private var requestClose: (() -> Unit)? = null
318
+ internal fun bindClose(handler: (() -> Unit)?) {
319
+ requestClose = handler
320
+ }
321
+
322
+ fun registerOverplay(
323
+ id: Int,
324
+ content: @Composable () -> Unit,
325
+ type: OverplayComponentType,
326
+ isSurface: Boolean = false,
327
+ barrierDismissible: Boolean = true,
328
+ onDismiss: (() -> Unit)?,
329
+ bottomSheetHeader: BottomHeader? = null,
330
+ ){
331
+ val params = when(type){
332
+ OverplayComponentType.MODAL -> OverplayComponentParams.Modal(onDismiss, barrierDismissible)
333
+ OverplayComponentType.BOTTOM_SHEET -> OverplayComponentParams.BottomSheet(isSurface, onDismiss, barrierDismissible, bottomSheetHeader)
334
+ OverplayComponentType.SNACK_BAR -> OverplayComponentParams.SnackBar()
335
+ }
336
+
337
+ currentOverlayComponent.value = OverplayComponent(
338
+ id = id,
339
+ type = type,
340
+ content = content,
341
+ params = params
342
+ )
343
+ }
344
+
345
+ fun isOverplayShowing(): Boolean = currentOverlayComponent.value != null
346
+
347
+ fun getOverplayType(): OverplayComponentType? = currentOverlayComponent.value?.type
348
+
349
+ fun currentRootId(): Int? = currentOverlayComponent.value?.id
350
+
351
+ fun clear(){
352
+ if (requestClose != null) {
353
+ requestClose?.invoke()
354
+ } else {
355
+ currentOverlayComponent.value = null
356
+ }
357
+ }
358
+
359
+ internal fun hardClearAfterDismiss() {
360
+ currentOverlayComponent.value = null
361
+ requestClose = null
362
+ }
363
+
364
+ @Composable
365
+ internal fun OverlayComponent(){
366
+ val overplay = currentOverlayComponent.value ?: return
367
+
368
+ when (val params = overplay.params) {
369
+ is OverplayComponentParams.BottomSheet -> {
370
+ BottomSheet(
371
+ content = overplay.content,
372
+ header = params.bottomSheetHeader ?: Title(),
373
+ isSurface = params.isSurface,
374
+ barrierDismissible = params.barrierDismissible,
375
+ onDismiss = params.onDismiss
376
+ )
377
+ }
378
+
379
+ is OverplayComponentParams.Modal -> {
380
+ ModalScreen(
381
+ content = overplay.content,
382
+ barrierDismissible = params.barrierDismissible,
383
+ onDismiss = params.onDismiss
384
+ )
385
+ }
386
+
387
+ is OverplayComponentParams.SnackBar -> {
388
+ Box(
389
+ modifier = Modifier.fillMaxSize(),
390
+ contentAlignment = Alignment.BottomCenter
391
+ ) {
392
+ overplay.content()
393
+ }
394
+ }
395
+
396
+ null -> {}
397
+ }
398
+ }
399
+ }
@@ -0,0 +1,8 @@
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
+