@momo-kits/native-kits 0.167.1-beta.4-debug → 0.167.1-duo.1

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