@momo-kits/native-kits 0.169.10-beta.1-debug → 0.169.10

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