@momo-kits/native-kits 0.164.1-beta.13-debug → 0.164.1-beta.13

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