@momo-kits/native-kits 0.169.13-beta.1-debug → 0.169.13-beta.2

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