@momo-kits/native-kits 0.155.1-hello.2 → 0.155.1-hello.2-debug

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/.gitlab-ci.yml +15 -0
  2. package/.npmignore.backup +22 -0
  3. package/build.gradle.kts +11 -0
  4. package/compose/build.gradle.kts +180 -0
  5. package/compose/compose.podspec +54 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +113 -0
  7. package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
  8. package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
  9. package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
  10. package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
  11. package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
  12. package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
  13. package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
  14. package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
  15. package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
  16. package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
  17. package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
  18. package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
  19. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
  20. package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +57 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +95 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +201 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +222 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +48 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +305 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +715 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +121 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +405 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +85 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +35 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +343 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +353 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +98 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +138 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +543 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +23 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +78 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +151 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +190 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +119 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +447 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +175 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +244 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +233 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +233 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +257 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +240 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +364 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +59 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +44 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +95 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +43 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +355 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +106 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +72 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +17 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +99 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +99 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +95 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +132 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +217 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +180 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +208 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +239 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +191 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +306 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +13 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +189 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +285 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +2 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +35 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +2 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +59 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +68 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +15 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +50 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +241 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +122 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +98 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +163 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +331 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +499 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +162 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +233 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +190 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +277 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +80 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +306 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +31 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +370 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +135 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +42 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +62 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +88 -0
  107. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +152 -0
  108. package/gradle/libs.versions.toml +57 -0
  109. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  110. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  111. package/gradle.properties +26 -0
  112. package/gradlew +252 -0
  113. package/gradlew.bat +94 -0
  114. package/local.properties +8 -0
  115. package/package.json +1 -1
  116. package/publish_release.sh +103 -0
  117. package/settings.gradle.kts +52 -0
@@ -0,0 +1,499 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ import androidx.compose.animation.animateColorAsState
4
+ import androidx.compose.animation.core.animateDpAsState
5
+ import androidx.compose.foundation.ScrollState
6
+ import androidx.compose.foundation.background
7
+ import androidx.compose.foundation.border
8
+ import androidx.compose.foundation.gestures.ScrollableState
9
+ import androidx.compose.foundation.layout.Box
10
+ import androidx.compose.foundation.layout.Column
11
+ import androidx.compose.foundation.layout.ColumnScope
12
+ import androidx.compose.foundation.layout.Spacer
13
+ import androidx.compose.foundation.layout.WindowInsets
14
+ import androidx.compose.foundation.layout.aspectRatio
15
+ import androidx.compose.foundation.layout.fillMaxSize
16
+ import androidx.compose.foundation.layout.fillMaxWidth
17
+ import androidx.compose.foundation.layout.height
18
+ import androidx.compose.foundation.layout.ime
19
+ import androidx.compose.foundation.layout.imePadding
20
+ import androidx.compose.foundation.layout.offset
21
+ import androidx.compose.foundation.layout.padding
22
+ import androidx.compose.foundation.lazy.LazyListState
23
+ import androidx.compose.foundation.lazy.rememberLazyListState
24
+ import androidx.compose.foundation.rememberScrollState
25
+ import androidx.compose.foundation.verticalScroll
26
+ import androidx.compose.material.ExperimentalMaterialApi
27
+ import androidx.compose.runtime.Composable
28
+ import androidx.compose.runtime.CompositionLocalProvider
29
+ import androidx.compose.runtime.LaunchedEffect
30
+ import androidx.compose.runtime.getValue
31
+ import androidx.compose.runtime.mutableIntStateOf
32
+ import androidx.compose.runtime.mutableStateOf
33
+ import androidx.compose.runtime.remember
34
+ import androidx.compose.runtime.snapshotFlow
35
+ import androidx.compose.runtime.staticCompositionLocalOf
36
+ import androidx.compose.ui.Alignment
37
+ import androidx.compose.ui.Modifier
38
+ import androidx.compose.ui.graphics.Brush
39
+ import androidx.compose.ui.graphics.Color
40
+ import androidx.compose.ui.graphics.lerp
41
+ import androidx.compose.ui.layout.onGloballyPositioned
42
+ import androidx.compose.ui.platform.LocalDensity
43
+ import androidx.compose.ui.unit.Dp
44
+ import androidx.compose.ui.unit.dp
45
+ import androidx.compose.ui.unit.min
46
+ import androidx.compose.ui.zIndex
47
+ import vn.momo.kits.components.InputSearch
48
+ import vn.momo.kits.const.AppNavigationBar
49
+ import vn.momo.kits.const.AppStatusBar
50
+ import vn.momo.kits.const.AppTheme
51
+ import vn.momo.kits.application.ApplicationContext
52
+ import vn.momo.kits.application.MiniAppContext.Companion.isShowBaselineDebug
53
+ import vn.momo.kits.const.Colors
54
+ import vn.momo.kits.const.Spacing
55
+ import vn.momo.kits.modifier.conditional
56
+ import vn.momo.kits.modifier.hideKeyboardOnTap
57
+ import vn.momo.kits.navigation.component.FABPosition
58
+ import vn.momo.kits.navigation.component.FloatingButton
59
+ import vn.momo.kits.navigation.component.HEADER_HEIGHT
60
+ import vn.momo.kits.navigation.component.Header
61
+ import vn.momo.kits.navigation.component.HeaderBackground
62
+ import vn.momo.kits.navigation.component.HeaderRight
63
+ import vn.momo.kits.navigation.component.HeaderType
64
+ import vn.momo.kits.navigation.component.InputSearchType
65
+ import vn.momo.kits.platform.BackHandler
66
+ import vn.momo.kits.platform.getAndroidBuildVersion
67
+
68
+ internal val LocalFooterHeightPx = staticCompositionLocalOf { mutableIntStateOf(0) }
69
+ internal val LocalHeaderRightWidthPx = staticCompositionLocalOf { mutableIntStateOf(0) }
70
+
71
+ @OptIn(ExperimentalMaterialApi::class)
72
+ @Composable
73
+ internal fun StackScreen(
74
+ content: @Composable () -> Unit,
75
+ navigationOptions: NavigationOptions? = null,
76
+ id: Int = -1,
77
+ bottomTabIndex: Int = -1,
78
+ onBackHandler: (() -> Unit)? = null,
79
+ ) {
80
+ val navigator = LocalNavigator.current
81
+ val statusBar = AppStatusBar.current
82
+ val density = LocalDensity.current
83
+ val navigation = remember { Navigation(id = id, bottomTabIndex = bottomTabIndex, initOptions = navigationOptions) }
84
+
85
+ val options by navigation.currentOptions
86
+
87
+ val limit = with(density) {
88
+ (statusBar).toPx() + HEADER_HEIGHT
89
+ }.toInt()
90
+
91
+ val (scrollState, scrollInProcess) = if (options.scrollData.scrollState is LazyListState)
92
+ (options.scrollData.scrollState as? LazyListState ?: rememberLazyListState()).proxyScrollState(limit, 15)
93
+ else
94
+ (options.scrollData.scrollState as? ScrollState ?: rememberScrollState()).proxyLimitedScrollState(limit, 15)
95
+
96
+ val footerHeightPx = remember { mutableIntStateOf(0) }
97
+ val headerRightWidthPx = remember { mutableIntStateOf(0) }
98
+
99
+ BackHandler(true) { navigator.onBackSafe() }
100
+
101
+ CompositionLocalProvider(
102
+ StackScreenScrollableState provides options.scrollData.scrollState,
103
+ LocalNavigation provides navigation,
104
+ LocalScrollState provides scrollState,
105
+ LocalOptions provides options,
106
+ LocalFooterHeightPx provides footerHeightPx,
107
+ LocalHeaderRightWidthPx provides headerRightWidthPx
108
+ ) {
109
+ Box(Modifier
110
+ .fillMaxSize()
111
+ .background(options.backgroundColor ?: AppTheme.current.colors.background.default)
112
+ .conditional(options.keyboardOptions.keyboardShouldPersistTaps) {
113
+ hideKeyboardOnTap()
114
+ }
115
+ .conditional(options.keyboardOptions.useAvoidKeyboard && getAndroidBuildVersion() > 29) {
116
+ imePadding()
117
+ }
118
+ ) {
119
+ Box(Modifier.zIndex(1f)) {
120
+ HeaderBackground()
121
+ }
122
+
123
+ Box(Modifier.zIndex(5f)) {
124
+ Header(onBackHandler)
125
+ }
126
+
127
+ Column (Modifier.zIndex(6f)) {
128
+ SearchAnimated(isScrollInProgress = scrollInProcess)
129
+ }
130
+
131
+ Column(Modifier.zIndex(2f).fillMaxSize()) {
132
+ MainContent(content = content)
133
+ }
134
+
135
+ Box(Modifier.zIndex(4f).align(Alignment.BottomCenter)) {
136
+ FooterContent()
137
+ }
138
+
139
+ Box(Modifier.zIndex(7f)){
140
+ FloatingContent()
141
+ }
142
+
143
+ OverplayView(bottomTabIndex = bottomTabIndex, id = id)
144
+ }
145
+ }
146
+ }
147
+
148
+ @Composable
149
+ fun FloatingContent(){
150
+ val options = LocalOptions.current
151
+ val density = LocalDensity.current
152
+ val footerHeightPx = LocalFooterHeightPx.current
153
+ val scrollState = LocalScrollState.current
154
+
155
+ val fabProps = options.floatingButtonProps ?: return
156
+ val bottomPadding = fabProps.bottom ?:
157
+ (Spacing.M + if (options.footerComponent != null) with(density){ footerHeightPx.intValue.toDp() } else 0.dp)
158
+
159
+ FloatingButton(
160
+ scrollPosition = fabProps.scrollState?.value ?: scrollState.value,
161
+ onClick = fabProps.onClick,
162
+ containerColor = AppTheme.current.colors.primary,
163
+ bottom = bottomPadding,
164
+ icon = fabProps.icon,
165
+ iconColor = fabProps.iconColor,
166
+ text = fabProps.label,
167
+ size = fabProps.size,
168
+ position = fabProps.position ?: FABPosition.END,
169
+ )
170
+ }
171
+
172
+ @Composable
173
+ fun ColumnScope.MainContent(content: @Composable ()-> Unit){
174
+ val options = LocalOptions.current
175
+ val inputSearchType = getInputSearchType(options)
176
+ val density = LocalDensity.current
177
+ val scrollState = LocalScrollState.current
178
+
179
+ Spacer(Modifier.height(
180
+ if (options.headerType is HeaderType.DefaultOrExtended || (options.headerType is HeaderType.Transparent && !options.headerType.isFullScreenContent))
181
+ AppStatusBar.current + HEADER_HEIGHT.dp else 0.dp)
182
+ )
183
+ if (inputSearchType == InputSearchType.Animated){
184
+ val scrollDp = with(density) { scrollState.value.toDp() }
185
+
186
+ val animatedTopPadding by animateDpAsState(
187
+ targetValue = (HEADER_HEIGHT.dp - scrollDp).coerceIn(0.dp, HEADER_HEIGHT.dp),
188
+ label = "AnimatedTopPadding"
189
+ )
190
+ Spacer(Modifier.height(animatedTopPadding))
191
+ }
192
+ Column (Modifier
193
+ .fillMaxWidth()
194
+ .weight(1f)
195
+ .conditional(options.scrollData.scrollable && options.scrollData.scrollState is ScrollState) {
196
+ verticalScroll(scrollState)
197
+ }
198
+ ) {
199
+ ScreenContent(content = content)
200
+ }
201
+
202
+ if (options.footerComponent != null){
203
+ val footerHeight = LocalFooterHeightPx.current
204
+ val footerHeightDp = with(density) { footerHeight.value.toDp() }
205
+ Spacer(Modifier.height(footerHeightDp))
206
+ }
207
+ }
208
+
209
+ @Composable
210
+ fun ScreenContent(content: @Composable () -> Unit){
211
+ val scrollState = LocalScrollState.current
212
+ val options = LocalOptions.current
213
+
214
+ if (options.headerType is HeaderType.Animated){
215
+ val animatedHeader = options.headerType
216
+ Box {
217
+ Box(Modifier.fillMaxWidth().aspectRatio(animatedHeader.aspectRatio.value)){
218
+ animatedHeader.composable.invoke(scrollState.value)
219
+ }
220
+ Box(Modifier.offset(x = 0.dp, y = AppStatusBar.current + HEADER_HEIGHT.dp + animatedHeader.layoutOffSet)){
221
+ content()
222
+ }
223
+ }
224
+ } else {
225
+ content()
226
+ }
227
+ }
228
+
229
+ @Composable
230
+ fun FooterContent(){
231
+ val options = LocalOptions.current
232
+ if (options.footerComponent != null){
233
+ val ime = WindowInsets.ime
234
+ val density = LocalDensity.current
235
+ val imeBottom = ime.getBottom(density)
236
+ val thresholdPx = with(density) { 50.dp.toPx() }
237
+ val isKeyboardVisible = imeBottom > thresholdPx
238
+ val bottomPadding = min(AppNavigationBar.current, if (isKeyboardVisible) 0.dp else 21.dp)
239
+ Footer(footerComponent = options.footerComponent, bottomPadding = bottomPadding)
240
+ }
241
+ }
242
+
243
+ @Composable
244
+ fun OverplayView(bottomTabIndex: Int, id: Int){
245
+ val overplayType = OverplayComponentRegistry.getOverplayType()
246
+
247
+ if (overplayType != null) {
248
+ Box(Modifier.zIndex(if (overplayType == OverplayComponentType.SNACK_BAR) 3f else 8f).fillMaxSize()){
249
+ if (bottomTabIndex != -1) return@Box
250
+ if (OverplayComponentRegistry.currentRootId() != id) return@Box
251
+ OverplayComponentRegistry.OverlayComponent()
252
+ }
253
+ }
254
+ }
255
+
256
+ @Composable
257
+ fun Footer(footerComponent: @Composable (() -> Unit)?, bottomPadding: Dp) {
258
+ if (footerComponent == null) return
259
+
260
+ val footerHeightPx = LocalFooterHeightPx.current
261
+ val application = ApplicationContext.current
262
+
263
+ val shadowBrush = remember {
264
+ Brush.verticalGradient(
265
+ colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.05f))
266
+ )
267
+ }
268
+
269
+ Box(Modifier.onGloballyPositioned {
270
+ if (footerHeightPx.intValue != it.size.height) footerHeightPx.intValue = it.size.height
271
+ }) {
272
+ Box(Modifier
273
+ .fillMaxWidth()
274
+ .background(AppTheme.current.colors.background.surface)
275
+ .conditional(application.isShowBaselineDebug()) {
276
+ border(1.dp, Colors.blue_03)
277
+ }
278
+ .padding(top = Spacing.S, start = Spacing.M, end = Spacing.M, bottom = bottomPadding + Spacing.S)
279
+ ){
280
+ footerComponent.invoke()
281
+ }
282
+
283
+ Box(modifier = Modifier
284
+ .fillMaxWidth()
285
+ .height(6.dp)
286
+ .offset(x = 0.dp, y = (-6).dp)
287
+ .background(shadowBrush)
288
+ )
289
+ }
290
+ }
291
+
292
+ data class InputSearchLayoutParams(
293
+ val topPadding: Dp,
294
+ val startPadding: Dp,
295
+ val endPadding: Dp
296
+ )
297
+ @Composable
298
+ fun SearchAnimated(
299
+ isScrollInProgress: Boolean
300
+ ) {
301
+ val scrollState = LocalScrollState.current
302
+ val options = LocalOptions.current
303
+ val navigator = LocalNavigator.current
304
+ val density = LocalDensity.current
305
+
306
+ val scrollDp = with(density) { scrollState.value.toDp() }
307
+
308
+ val inputSearchType = getInputSearchType(options)
309
+ val headerRightWidthPx = LocalHeaderRightWidthPx.current
310
+ val headerRightWidthDp = with(density) { headerRightWidthPx.intValue.toDp() }
311
+
312
+ if (inputSearchType == InputSearchType.None) return
313
+ val inputSearchProps = (options.headerType as? HeaderType.DefaultOrExtended)?.inputSearchProps ?: return
314
+
315
+ val minTopPadding = AppStatusBar.current
316
+ val maxTopPadding = AppStatusBar.current + HEADER_HEIGHT.dp
317
+ val minStartPadding = Spacing.M
318
+ val maxStartPadding = if (options.hiddenBack) Spacing.M else 52.dp
319
+ val minEndPadding = Spacing.M
320
+ val maxEndPadding = headerRightWidthDp + if (options.headerRight is HeaderRight.None) Spacing.M else Spacing.M * 2
321
+
322
+ val targetColor = lerp(
323
+ AppTheme.current.colors.background.surface,
324
+ AppTheme.current.colors.background.default,
325
+ (scrollDp / minTopPadding).coerceIn(0f, 1f)
326
+ )
327
+ val animatedColor by animateColorAsState(targetValue = targetColor, label = "BackgroundColor")
328
+
329
+ val layoutParams = when (inputSearchType) {
330
+ InputSearchType.Header -> {
331
+ InputSearchLayoutParams(
332
+ topPadding = minTopPadding,
333
+ startPadding = maxStartPadding,
334
+ endPadding = maxEndPadding
335
+ )
336
+ }
337
+
338
+ InputSearchType.Animated -> {
339
+ val animatedTopPadding by animateDpAsState(
340
+ targetValue = (maxTopPadding - scrollDp).coerceIn(minTopPadding, maxTopPadding),
341
+ label = "AnimatedTopPadding"
342
+ )
343
+
344
+ val animatedStartPadding by animateDpAsState(
345
+ targetValue = (minStartPadding + scrollDp).coerceIn(minStartPadding, maxStartPadding),
346
+ label = "AnimatedStartPadding"
347
+ )
348
+
349
+ val animatedEndPadding by animateDpAsState(
350
+ targetValue = (minEndPadding + scrollDp).coerceIn(minEndPadding, maxEndPadding),
351
+ label = "AnimatedEndPadding"
352
+ )
353
+
354
+ val maxPadding = remember(maxTopPadding, maxStartPadding, maxEndPadding) {
355
+ maxOf(maxEndPadding, maxStartPadding, maxTopPadding)
356
+ }
357
+ val snapScrollValue = with(density) { maxPadding.toPx().toInt() }
358
+
359
+ LaunchedEffect(isScrollInProgress && scrollState.value != 0 && scrollState.value != snapScrollValue) {
360
+ if (scrollDp < maxPadding) {
361
+ if (!isScrollInProgress) {
362
+ val midpoint = (maxTopPadding - minTopPadding) / 2
363
+
364
+ if (scrollDp < midpoint) {
365
+ scrollState.animateScrollTo(0)
366
+ } else {
367
+ scrollState.animateScrollTo(snapScrollValue)
368
+ }
369
+ }
370
+ }
371
+ }
372
+
373
+ InputSearchLayoutParams(
374
+ topPadding = animatedTopPadding,
375
+ startPadding = animatedStartPadding,
376
+ endPadding = animatedEndPadding
377
+ )
378
+ }
379
+
380
+ InputSearchType.None -> return
381
+ }
382
+
383
+ Spacer(Modifier.height(layoutParams.topPadding))
384
+ Box(
385
+ modifier = Modifier
386
+ .height(HEADER_HEIGHT.dp)
387
+ .fillMaxWidth()
388
+ .padding(
389
+ start = layoutParams.startPadding,
390
+ end = layoutParams.endPadding
391
+ ),
392
+ contentAlignment = Alignment.Center
393
+ ) {
394
+ InputSearch(
395
+ inputSearchProps = inputSearchProps.copy(
396
+ backgroundColor = animatedColor,
397
+ onPressButtonText = {
398
+ navigator.pop()
399
+ }
400
+ )
401
+ )
402
+ }
403
+ }
404
+
405
+ @Composable
406
+ internal fun isKeyboardVisible(): Boolean {
407
+ val ime = WindowInsets.ime
408
+ val density = LocalDensity.current
409
+ return ime.getBottom(density) > 0
410
+ }
411
+ private fun quantize(value: Int, stepPx: Int): Int {
412
+ if (stepPx <= 1) return value
413
+ return (value / stepPx) * stepPx
414
+ }
415
+
416
+ @Composable
417
+ fun LazyListState.proxyScrollState(
418
+ thresholdPx: Int = 200,
419
+ stepPx: Int = 4
420
+ ): Pair<ScrollState, Boolean> {
421
+ val scrollState = rememberScrollState()
422
+ val locked = remember { mutableStateOf(false) }
423
+
424
+ LaunchedEffect(this, scrollState, thresholdPx, stepPx) {
425
+ snapshotFlow { firstVisibleItemIndex to firstVisibleItemScrollOffset }
426
+ .collect { (index, offset) ->
427
+ val rawTarget = if (index == 0) offset else SCROLLED_PAST_FIRST_ITEM_THRESHOLD
428
+ val shouldLock = rawTarget > thresholdPx
429
+ if (locked.value != shouldLock) locked.value = shouldLock
430
+
431
+ val desired = if (shouldLock) thresholdPx else quantize(rawTarget, stepPx)
432
+
433
+ if (scrollState.value != desired) {
434
+ scrollState.scrollTo(desired.coerceAtLeast(0))
435
+ }
436
+ }
437
+ }
438
+
439
+ val inProgress = remember { mutableStateOf(false) }
440
+ LaunchedEffect(this, thresholdPx) {
441
+ snapshotFlow { isScrollInProgress }
442
+ .collect { progressing ->
443
+ inProgress.value = if (locked.value) false else progressing
444
+ }
445
+ }
446
+
447
+ return scrollState to inProgress.value
448
+ }
449
+
450
+ @Composable
451
+ fun ScrollState.proxyLimitedScrollState(
452
+ thresholdPx: Int = 200,
453
+ stepPx: Int = 4
454
+ ): Pair<ScrollState, Boolean> {
455
+ val proxy = rememberScrollState()
456
+ val locked = remember { mutableStateOf(false) }
457
+
458
+ LaunchedEffect(this, proxy, thresholdPx, stepPx) {
459
+ snapshotFlow { value }
460
+ .collect { rawTarget ->
461
+ val shouldLock = rawTarget > thresholdPx
462
+ if (locked.value != shouldLock) locked.value = shouldLock
463
+
464
+ val desired = if (shouldLock) thresholdPx else quantize(rawTarget, stepPx)
465
+
466
+ if (proxy.value != desired) {
467
+ proxy.scrollTo(desired.coerceAtLeast(0))
468
+ }
469
+ }
470
+ }
471
+
472
+ val inProgress = remember { mutableStateOf(false) }
473
+ LaunchedEffect(this, thresholdPx) {
474
+ snapshotFlow { isScrollInProgress }
475
+ .collect { progressing ->
476
+ inProgress.value = if (locked.value) false else progressing
477
+ }
478
+ }
479
+
480
+ return proxy to inProgress.value
481
+ }
482
+
483
+ private const val SCROLLED_PAST_FIRST_ITEM_THRESHOLD = 10_000
484
+
485
+ internal val LocalScrollState = staticCompositionLocalOf<ScrollState> { error("No Scroll State provided") }
486
+ internal val LocalOptions = staticCompositionLocalOf<NavigationOptions> { error("No NavigationOptions provided") }
487
+
488
+ val StackScreenScrollableState = staticCompositionLocalOf<ScrollableState?> { null }
489
+
490
+ internal fun getInputSearchType(options: NavigationOptions): InputSearchType{
491
+ return when (val headerType = options.headerType) {
492
+ is HeaderType.DefaultOrExtended -> when {
493
+ headerType.inputSearchProps == null -> InputSearchType.None
494
+ headerType.useAnimated -> InputSearchType.Animated
495
+ else -> InputSearchType.Header
496
+ }
497
+ else -> InputSearchType.None
498
+ }
499
+ }
@@ -0,0 +1,162 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.animation.core.tween
4
+ import androidx.compose.animation.fadeIn
5
+ import androidx.compose.animation.fadeOut
6
+ import androidx.compose.animation.scaleIn
7
+ import androidx.compose.animation.scaleOut
8
+ import androidx.compose.foundation.background
9
+ import androidx.compose.foundation.layout.Box
10
+ import androidx.compose.foundation.layout.Column
11
+ import androidx.compose.foundation.layout.Spacer
12
+ import androidx.compose.foundation.layout.fillMaxSize
13
+ import androidx.compose.foundation.layout.fillMaxWidth
14
+ import androidx.compose.foundation.layout.height
15
+ import androidx.compose.foundation.layout.padding
16
+ import androidx.compose.runtime.Composable
17
+ import androidx.compose.runtime.LaunchedEffect
18
+ import androidx.compose.ui.Alignment
19
+ import androidx.compose.ui.Modifier
20
+ import androidx.compose.ui.unit.dp
21
+ import androidx.compose.ui.unit.min
22
+ import androidx.navigation.compose.NavHost
23
+ import androidx.navigation.compose.composable
24
+ import androidx.navigation.compose.rememberNavController
25
+ import vn.momo.kits.const.AppNavigationBar
26
+ import vn.momo.kits.const.AppTheme
27
+ import vn.momo.kits.const.Spacing
28
+ import vn.momo.kits.navigation.LocalNavigation
29
+ import vn.momo.kits.navigation.LocalNavigator
30
+ import vn.momo.kits.navigation.NavigationOptions
31
+ import vn.momo.kits.navigation.StackScreen
32
+ import vn.momo.kits.navigation.component.HeaderType
33
+ import vn.momo.kits.platform.getScreenHeight
34
+
35
+ private var bottomTabOptionItems : MutableList<NavigationOptions?> = mutableListOf()
36
+ fun setBottomTabOption(index: Int, options: NavigationOptions){
37
+ if (index in bottomTabOptionItems.indices) {
38
+ bottomTabOptionItems[index] = options
39
+ }
40
+ }
41
+ fun getBottomTabOption(index: Int): NavigationOptions? {
42
+ return if (index in bottomTabOptionItems.indices) {
43
+ bottomTabOptionItems[index]
44
+ } else null
45
+ }
46
+
47
+ @Composable
48
+ fun BottomTab(
49
+ items: List<BottomTabItem>,
50
+ floatingButton: BottomTabFloatingButton? = null
51
+ ) {
52
+ val navigation = LocalNavigation.current
53
+ val navigator = LocalNavigator.current
54
+ val navController = rememberNavController()
55
+
56
+ bottomTabOptionItems = items.mapIndexed { index, item ->
57
+ item.options ?: NavigationOptions()
58
+ }.toMutableList()
59
+
60
+
61
+ LaunchedEffect(Unit){
62
+ navigation.setOptions(
63
+ headerType = HeaderType.None
64
+ )
65
+ }
66
+
67
+ Box(modifier = Modifier.fillMaxWidth().height(getScreenHeight()), contentAlignment = Alignment.BottomCenter) {
68
+ Box(modifier = Modifier
69
+ .fillMaxSize()
70
+ .padding(bottom = BOTTOM_TAB_BAR_HEIGHT.dp + AppNavigationBar.current)
71
+ ) {
72
+ NavHost(
73
+ navController = navController,
74
+ startDestination = "option0"
75
+ ) {
76
+ items.forEachIndexed { index, item ->
77
+ composable(
78
+ route = "option$index",
79
+ enterTransition = {
80
+ fadeIn(animationSpec = tween(200)) +
81
+ scaleIn(
82
+ initialScale = 0.97f,
83
+ animationSpec = tween(200)
84
+ )
85
+ },
86
+ exitTransition = {
87
+ fadeOut(animationSpec = tween(200)) +
88
+ scaleOut(
89
+ targetScale = 0.97f,
90
+ animationSpec = tween(200)
91
+ )
92
+ },
93
+ popEnterTransition = {
94
+ fadeIn(animationSpec = tween(200)) +
95
+ scaleIn(
96
+ initialScale = 0.97f,
97
+ animationSpec = tween(200)
98
+ )
99
+ },
100
+ popExitTransition = {
101
+ fadeOut(animationSpec = tween(200)) +
102
+ scaleOut(
103
+ targetScale = 0.97f,
104
+ animationSpec = tween(200)
105
+ )
106
+ }
107
+ ) {
108
+ val option = getBottomTabOption(index)
109
+
110
+ StackScreen(
111
+ content = item.screen,
112
+ navigationOptions = option,
113
+ bottomTabIndex = index,
114
+ onBackHandler = {
115
+ if (index != 0) {
116
+ navController.popBackStack(
117
+ navController.graph.startDestinationRoute!!,
118
+ inclusive = false
119
+ )
120
+ } else {
121
+ navigator.pop()
122
+ }
123
+ }
124
+ )
125
+ }
126
+ }
127
+ }
128
+ }
129
+ Column {
130
+ BottomTabBar(
131
+ items = items,
132
+ floatingButton = floatingButton,
133
+ navController = navController,
134
+ onTabSelected = {
135
+ val currentRoute = navController.currentBackStackEntry?.destination?.route
136
+ val targetRoute = "option$it"
137
+ if (currentRoute != targetRoute){
138
+ navController.navigate(targetRoute)
139
+ }
140
+ }
141
+ )
142
+ Spacer(modifier = Modifier.fillMaxWidth().height(min(AppNavigationBar.current, 21.dp) + Spacing.S).background(AppTheme.current.colors.background.surface))
143
+ }
144
+ }
145
+ }
146
+
147
+ data class BottomTabItem(
148
+ val name: String,
149
+ val label: String,
150
+ val icon: String,
151
+ val showDot: Boolean = false,
152
+ val badgeLabel: String? = null,
153
+ val screen: @Composable () -> Unit,
154
+ val options: NavigationOptions? = null,
155
+ val initialParams: Any? = null
156
+ )
157
+
158
+ data class BottomTabFloatingButton(
159
+ val icon: String,
160
+ val label: String,
161
+ val onPress: () -> Unit,
162
+ )