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