@momo-kits/native-kits 0.169.5-beta.1 → 0.169.5-beta.1-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 (139) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +198 -0
  3. package/compose/compose.podspec +47 -0
  4. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1071 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +195 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +363 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +308 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +207 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +236 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +17 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +293 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +316 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -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 +104 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -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 +393 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +113 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +205 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +422 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +739 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +239 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +423 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +94 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +203 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +108 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +456 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +399 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +204 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +114 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +22 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  123. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  124. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +219 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +144 -0
  131. package/gradle/libs.versions.toml +69 -0
  132. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  133. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  134. package/gradle.properties +24 -0
  135. package/gradlew +252 -0
  136. package/gradlew.bat +94 -0
  137. package/ios-demo/README.md +120 -0
  138. package/package.json +1 -1
  139. package/settings.gradle.kts +64 -0
@@ -0,0 +1,423 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.runtime.getValue
4
+ import androidx.compose.animation.animateColorAsState
5
+ import androidx.compose.animation.core.Animatable
6
+ import androidx.compose.animation.core.animateFloatAsState
7
+ import androidx.compose.animation.core.tween
8
+ import androidx.compose.foundation.clickable
9
+ import androidx.compose.foundation.interaction.MutableInteractionSource
10
+ import androidx.compose.foundation.interaction.collectIsPressedAsState
11
+ import androidx.compose.runtime.LaunchedEffect
12
+ import androidx.compose.runtime.mutableStateMapOf
13
+ import androidx.compose.ui.draw.clip
14
+ import androidx.compose.ui.draw.dropShadow
15
+ import androidx.compose.ui.draw.innerShadow
16
+ import androidx.compose.ui.graphics.Shape
17
+ import androidx.compose.ui.graphics.graphicsLayer
18
+ import androidx.compose.ui.layout.onPlaced
19
+ import androidx.compose.ui.layout.positionInParent
20
+ import androidx.compose.ui.platform.LocalDensity
21
+ import androidx.compose.ui.semantics.Role
22
+ import androidx.compose.ui.semantics.contentDescription
23
+ import androidx.compose.ui.semantics.role
24
+ import androidx.compose.ui.semantics.selected
25
+ import androidx.compose.ui.semantics.semantics
26
+ import androidx.compose.foundation.background
27
+ import androidx.compose.foundation.border
28
+ import androidx.compose.foundation.layout.*
29
+ import androidx.compose.foundation.shape.CircleShape
30
+ import androidx.compose.foundation.shape.RoundedCornerShape
31
+ import androidx.compose.runtime.Composable
32
+ import androidx.compose.runtime.CompositionLocalProvider
33
+ import androidx.compose.runtime.remember
34
+ import androidx.compose.ui.Alignment
35
+ import androidx.compose.ui.Modifier
36
+ import androidx.compose.ui.text.style.TextAlign
37
+ import androidx.compose.ui.text.style.TextOverflow
38
+ import androidx.compose.ui.unit.dp
39
+ import vn.momo.kits.application.IsShowBaseLineDebug
40
+ import vn.momo.kits.application.LocalContext
41
+ import vn.momo.kits.application.MiniAppContext
42
+ import vn.momo.kits.components.*
43
+ import vn.momo.kits.const.*
44
+ import vn.momo.kits.layout.getScreenLayout
45
+ import vn.momo.kits.modifier.InternalApi
46
+ import vn.momo.kits.modifier.activeOpacityClickable
47
+ import vn.momo.kits.modifier.conditional
48
+ import vn.momo.kits.modifier.setAutomationId
49
+
50
+ @InternalApi
51
+ const val BOTTOM_TAB_BAR_HEIGHT = 68
52
+
53
+ // Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
54
+ @Composable
55
+ internal fun BottomTabBar(
56
+ items: List<BottomTabItem>,
57
+ floatingButton: BottomTabFloatingButton? = null,
58
+ selectedIndex: Int,
59
+ onTabSelected: (Int) -> Unit,
60
+ ) {
61
+ val layout = getScreenLayout()
62
+ Box(
63
+ modifier = Modifier
64
+ .fillMaxWidth()
65
+ .padding(bottom = tabBarBottomGap(layout.insetBottom)),
66
+ contentAlignment = Alignment.BottomCenter,
67
+ ) {
68
+ HorizontalTabBar(
69
+ items = items,
70
+ floatingButton = floatingButton,
71
+ selectedIndex = selectedIndex,
72
+ onTabSelected = onTabSelected,
73
+ fixedFontScale = true,
74
+ modifier = Modifier
75
+ .offset(x = (layout.insetLeft - layout.insetRight) / 2)
76
+ .width(horizontalBarWidth(layout.width, layout.height, layout.insetLeft, layout.insetRight)),
77
+ )
78
+ }
79
+ }
80
+
81
+ // Horizontal navigation bar: floating container, items split evenly; Special type puts the center
82
+ // action in a notch in the middle, rising ctaLift above the container. One active indicator slides
83
+ // behind the selected item.
84
+ @Composable
85
+ internal fun HorizontalTabBar(
86
+ items: List<BottomTabItem>,
87
+ floatingButton: BottomTabFloatingButton?,
88
+ selectedIndex: Int,
89
+ onTabSelected: (Int) -> Unit,
90
+ modifier: Modifier = Modifier,
91
+ fixedFontScale: Boolean = false,
92
+ ) {
93
+ val cta = floatingButton?.takeIf { hasCenterAction(it, items.size) }
94
+ val mid = items.size / 2
95
+ val density = LocalDensity.current
96
+ val itemBounds = remember(items.size) { mutableStateMapOf<Int, Pair<Float, Float>>() }
97
+
98
+ BoxWithConstraints(modifier = modifier) {
99
+ val shape = remember(maxWidth, cta != null) {
100
+ NotchedBarShape(TabBarMetrics.height / 2, if (cta != null) maxWidth / 2 else null)
101
+ }
102
+ Box(
103
+ modifier = Modifier
104
+ .padding(top = if (cta != null) TabBarMetrics.ctaLift else 0.dp)
105
+ .fillMaxWidth()
106
+ .height(TabBarMetrics.height)
107
+ .tabBarContainer(shape)
108
+ .padding(horizontal = TabBarMetrics.paddingHorizontal, vertical = TabBarMetrics.paddingVertical)
109
+ .setAutomationId("bottom_tab_bar"),
110
+ ) {
111
+ itemBounds[selectedIndex]?.let { (x, width) ->
112
+ ActiveIndicator(
113
+ offset = x,
114
+ modifier = Modifier
115
+ .width(with(density) { width.toDp() })
116
+ .height(TabBarMetrics.indicatorHeight),
117
+ shape = RoundedCornerShape(TabBarMetrics.indicatorRadius),
118
+ axisX = true,
119
+ )
120
+ }
121
+ Row(
122
+ modifier = Modifier.fillMaxSize(),
123
+ horizontalArrangement = Arrangement.spacedBy(TabBarMetrics.itemGap),
124
+ verticalAlignment = Alignment.CenterVertically,
125
+ ) {
126
+ items.forEachIndexed { index, item ->
127
+ if (cta != null && index == mid) {
128
+ Spacer(Modifier.width(TabBarMetrics.ctaSlotWidth))
129
+ }
130
+ TabBarItem(
131
+ item = item,
132
+ selected = index == selectedIndex,
133
+ fixedFontScale = fixedFontScale,
134
+ modifier = Modifier.onPlaced {
135
+ itemBounds[index] = it.positionInParent().x to it.size.width.toFloat()
136
+ },
137
+ onClick = { onTabSelected(index) },
138
+ )
139
+ }
140
+ }
141
+ }
142
+ cta?.let { CenterAction(it, fixedFontScale, Modifier.align(Alignment.TopCenter)) }
143
+ }
144
+ }
145
+
146
+ // One active indicator per bar (Background/tonal with its inner shadows) sliding to the selected item
147
+ // along x (horizontal bar) or y (rail); it lands in place on the first measure and slides from then on.
148
+ @Composable
149
+ internal fun ActiveIndicator(offset: Float, modifier: Modifier, shape: Shape, axisX: Boolean) {
150
+ val colors = AppTheme.current.colors
151
+ val position = remember { Animatable(offset) }
152
+ LaunchedEffect(offset) {
153
+ if (position.value != offset) position.animateTo(offset, TabBarMotion.indicator)
154
+ }
155
+ Box(
156
+ modifier
157
+ .graphicsLayer {
158
+ if (axisX) translationX = position.value else translationY = position.value
159
+ }
160
+ .background(colors.background.tonal, shape)
161
+ .then(
162
+ indicatorInnerShadows(colors.primary).fold(Modifier as Modifier) { acc, shadow ->
163
+ acc.innerShadow(shape, shadow)
164
+ }
165
+ )
166
+ )
167
+ }
168
+
169
+ @Composable
170
+ private fun RowScope.TabBarItem(
171
+ item: BottomTabItem,
172
+ selected: Boolean,
173
+ fixedFontScale: Boolean,
174
+ modifier: Modifier,
175
+ onClick: () -> Unit,
176
+ ) {
177
+ Column(
178
+ modifier = modifier
179
+ .weight(1f)
180
+ .conditional(IsShowBaseLineDebug) {
181
+ border(1.dp, Colors.blue_03)
182
+ }
183
+ .activeOpacityClickable { onClick() }
184
+ .semantics {
185
+ role = Role.Tab
186
+ this.selected = selected
187
+ contentDescription = item.label
188
+ },
189
+ horizontalAlignment = Alignment.CenterHorizontally,
190
+ verticalArrangement = Arrangement.spacedBy(Spacing.XXS),
191
+ ) {
192
+ TabItemContent(item, selected, fixedFontScale = fixedFontScale)
193
+ }
194
+ }
195
+
196
+ // Icon in its indicator slot, label under it. The bar slides one shared active indicator behind the
197
+ // slots; the icon and label tint cross-fade on focus.
198
+ @Composable
199
+ internal fun ColumnScope.TabItemContent(
200
+ item: BottomTabItem,
201
+ selected: Boolean,
202
+ vertical: Boolean = false,
203
+ showLabel: Boolean = true,
204
+ fixedFontScale: Boolean = false,
205
+ ) {
206
+ val colors = AppTheme.current.colors
207
+ val tint by animateColorAsState(
208
+ if (selected) colors.primary else colors.text.secondary,
209
+ tween(TabBarMotion.TINT_MILLIS, easing = inOutQuad),
210
+ label = "TabTint",
211
+ )
212
+
213
+ Box(
214
+ modifier = Modifier
215
+ .then(if (vertical) Modifier else Modifier.fillMaxWidth())
216
+ .height(if (vertical) TabBarMetrics.railIndicatorHeight else TabBarMetrics.indicatorHeight)
217
+ .padding(horizontal = TabBarMetrics.indicatorPaddingHorizontal),
218
+ contentAlignment = Alignment.Center,
219
+ ) {
220
+ TabIcon(item, tint, vertical)
221
+ }
222
+ if (showLabel) {
223
+ val label = @Composable {
224
+ Text(
225
+ text = item.label,
226
+ color = tint,
227
+ style = if (vertical) Typography.labelXsMedium else Typography.labelSMedium,
228
+ textAlign = TextAlign.Center,
229
+ maxLines = 1,
230
+ overflow = TextOverflow.Ellipsis,
231
+ modifier = (if (vertical) Modifier else Modifier.fillMaxWidth())
232
+ .wrapContentHeight(Alignment.Top, unbounded = true),
233
+ )
234
+ }
235
+ // fixed slot so a capped-scale label overflows downward and the icon above it stays put
236
+ Box(
237
+ modifier = Modifier.height(
238
+ if (vertical) TabBarMetrics.railLabelHeight else TabBarMetrics.labelHeight
239
+ ),
240
+ contentAlignment = Alignment.TopCenter,
241
+ ) {
242
+ if (fixedFontScale) CappedFontScale(label) else label()
243
+ }
244
+ }
245
+ }
246
+
247
+ // Like the system tab bar the label keeps its design size; Text grows it up to 5pt on the wide Duo displays.
248
+ @Composable
249
+ internal fun FixedFontScale(content: @Composable () -> Unit) {
250
+ val context = LocalContext.current
251
+ val fixedScale = remember(context) {
252
+ (context ?: MiniAppContext()).copy(userScaleRate = 1f, useOSScaleRate = false)
253
+ }
254
+ CompositionLocalProvider(LocalContext provides fixedScale, content = content)
255
+ }
256
+
257
+ // Tab labels follow the OS/host font scale but never grow past this, so the fixed-height container
258
+ // and the notch stay aligned.
259
+ private const val TAB_LABEL_MAX_SCALE = 1.2f
260
+
261
+ // Caps the label scale at TAB_LABEL_MAX_SCALE: it keeps following the host/OS font scale but stops
262
+ // growing past 1.2× so it fits the fixed bar geometry.
263
+ @Composable
264
+ internal fun CappedFontScale(content: @Composable () -> Unit) {
265
+ val context = LocalContext.current
266
+ val capped = remember(context) {
267
+ (context ?: MiniAppContext()).copy(scaleSizeMaxRate = TAB_LABEL_MAX_SCALE)
268
+ }
269
+ CompositionLocalProvider(LocalContext provides capped, content = content)
270
+ }
271
+
272
+ // Badge value shown on a tab: null hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
273
+ internal fun tabBadgeLabel(item: BottomTabItem): String? {
274
+ val label = item.badgeLabel ?: return if (item.showDot) "" else null
275
+ if (label.isEmpty()) return ""
276
+ if (label.all { it in '0'..'9' }) {
277
+ val value = label.toLongOrNull() ?: Long.MAX_VALUE
278
+ if (value == 0L) return if (item.showDot) "" else null
279
+ return if (value > 99) "99+" else label
280
+ }
281
+ return label
282
+ }
283
+
284
+ // 24 icon; badges hang off it unclipped: dot at 16/-2, label badge at 12/-7 growing right, or
285
+ // centered over the icon at -10 on the rail.
286
+ @Composable
287
+ internal fun TabIcon(item: BottomTabItem, tint: androidx.compose.ui.graphics.Color, vertical: Boolean) {
288
+ val badge = tabBadgeLabel(item)
289
+ Box(Modifier.size(TabBarMetrics.iconSize)) {
290
+ Icon(source = item.icon, size = TabBarMetrics.iconSize, color = tint)
291
+ when {
292
+ badge == null -> Unit
293
+ badge.isEmpty() -> BadgeDot(
294
+ size = DotSize.Small,
295
+ modifier = Modifier.offset(x = 16.dp, y = -Spacing.XXS),
296
+ )
297
+ vertical -> TabBadge(
298
+ badge,
299
+ Modifier.matchParentSize()
300
+ .wrapContentSize(Alignment.TopCenter, unbounded = true)
301
+ .offset(y = (-10).dp),
302
+ )
303
+ else -> TabBadge(
304
+ badge,
305
+ Modifier.matchParentSize()
306
+ .wrapContentSize(Alignment.TopStart, unbounded = true)
307
+ .offset(x = Spacing.M, y = (-7).dp),
308
+ )
309
+ }
310
+ }
311
+ }
312
+
313
+ // Numbers use the error color, text the warning color (Figma Badge round numeric / text); the text keeps
314
+ // its design size so it fits the 16 height on the Duo displays too.
315
+ @Composable
316
+ private fun TabBadge(label: String, modifier: Modifier) {
317
+ val colors = AppTheme.current.colors
318
+ val isNumber = label.trimEnd('+').let { it.isNotEmpty() && it.all { c -> c in '0'..'9' } }
319
+ Box(
320
+ modifier = modifier
321
+ .height(16.dp)
322
+ .widthIn(min = 16.dp, max = TabBarMetrics.badgeMaxWidth)
323
+ .background(if (isNumber) colors.error.primary else colors.warning.primary, CircleShape)
324
+ .border(1.dp, colors.background.surface, CircleShape)
325
+ .padding(horizontal = Spacing.XS),
326
+ contentAlignment = Alignment.Center,
327
+ ) {
328
+ FixedFontScale {
329
+ Text(
330
+ text = label,
331
+ style = Typography.actionXxsBold,
332
+ color = Colors.black_01,
333
+ maxLines = 1,
334
+ overflow = TextOverflow.Ellipsis,
335
+ )
336
+ }
337
+ }
338
+ }
339
+
340
+ // Center action press: the button shrinks while held; the label stays plain text.
341
+ @Composable
342
+ internal fun rememberCenterActionPress(): Pair<MutableInteractionSource, Boolean> {
343
+ val interactionSource = remember { MutableInteractionSource() }
344
+ val pressed by interactionSource.collectIsPressedAsState()
345
+ return interactionSource to pressed
346
+ }
347
+
348
+ @Composable
349
+ internal fun Modifier.centerActionPressScale(pressed: Boolean): Modifier {
350
+ val scale by animateFloatAsState(
351
+ if (pressed) TabBarMotion.CTA_PRESSED_SCALE else 1f,
352
+ tween(TabBarMotion.CTA_PRESS_MILLIS, easing = inOutQuad),
353
+ label = "CenterActionPress",
354
+ )
355
+ return graphicsLayer {
356
+ scaleX = scale
357
+ scaleY = scale
358
+ }
359
+ }
360
+
361
+ @Composable
362
+ internal fun Modifier.centerActionButton(size: androidx.compose.ui.unit.Dp, pressed: Boolean): Modifier {
363
+ return centerActionPressScale(pressed)
364
+ .size(size)
365
+ .then(CtaShadows.fold(Modifier as Modifier) { acc, shadow -> acc.spreadShadow(CircleShape, shadow) })
366
+ .background(AppTheme.current.colors.primary, CircleShape)
367
+ }
368
+
369
+ @Composable
370
+ internal fun CenterActionLabel(label: String, overlay: (@Composable () -> Unit)?, vertical: Boolean, fixedFontScale: Boolean) {
371
+ val colors = AppTheme.current.colors
372
+ val text = @Composable {
373
+ Text(
374
+ text = label,
375
+ style = if (vertical) Typography.labelXsMedium else Typography.labelSMedium,
376
+ color = colors.text.secondary,
377
+ textAlign = TextAlign.Center,
378
+ maxLines = 1,
379
+ overflow = TextOverflow.Ellipsis,
380
+ )
381
+ }
382
+ Box(
383
+ modifier = Modifier
384
+ .then(if (vertical) Modifier else Modifier.heightIn(min = TabBarMetrics.ctaLabelHeight))
385
+ .padding(horizontal = if (vertical) Spacing.XS else Spacing.XXS),
386
+ contentAlignment = Alignment.Center,
387
+ ) {
388
+ if (fixedFontScale) CappedFontScale(text) else text()
389
+ overlay?.let {
390
+ Box(Modifier.matchParentSize().wrapContentSize(Alignment.Center, unbounded = true)) { it() }
391
+ }
392
+ }
393
+ }
394
+
395
+ // Center action (.Nav/CTA): button rising out of the notch, label under it.
396
+ @Composable
397
+ private fun CenterAction(data: BottomTabFloatingButton, fixedFontScale: Boolean, modifier: Modifier) {
398
+ val (interactionSource, pressed) = rememberCenterActionPress()
399
+ Column(
400
+ modifier = modifier
401
+ .width(TabBarMetrics.ctaSlotWidth)
402
+ .conditional(IsShowBaseLineDebug) {
403
+ border(1.dp, Colors.blue_03)
404
+ }
405
+ .clickable(interactionSource = interactionSource, indication = null, onClick = data.onPress)
406
+ .setAutomationId(data.label),
407
+ horizontalAlignment = Alignment.CenterHorizontally,
408
+ verticalArrangement = Arrangement.spacedBy(TabBarMetrics.ctaLabelGap),
409
+ ) {
410
+ Box(Modifier.centerActionButton(TabBarMetrics.ctaSize, pressed), contentAlignment = Alignment.Center) {
411
+ val iconContent = data.iconContent
412
+ if (iconContent != null) {
413
+ // custom content (e.g. an oversized Lottie) is clipped to the round button
414
+ Box(Modifier.size(TabBarMetrics.ctaSize).clip(CircleShape), contentAlignment = Alignment.Center) {
415
+ iconContent()
416
+ }
417
+ } else {
418
+ Icon(source = data.icon, color = Colors.black_01, size = TabBarMetrics.ctaIconSize)
419
+ }
420
+ }
421
+ CenterActionLabel(data.label, data.labelContent, vertical = false, fixedFontScale = fixedFontScale)
422
+ }
423
+ }
@@ -0,0 +1,94 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.ui.Modifier
4
+ import androidx.compose.ui.draw.dropShadow
5
+ import androidx.compose.ui.geometry.Rect
6
+ import androidx.compose.ui.geometry.RoundRect
7
+ import androidx.compose.ui.geometry.Size
8
+ import androidx.compose.ui.geometry.CornerRadius
9
+ import androidx.compose.ui.geometry.Offset
10
+ import androidx.compose.ui.graphics.addOutline
11
+ import androidx.compose.ui.graphics.Color
12
+ import androidx.compose.ui.graphics.Outline
13
+ import androidx.compose.ui.graphics.Path
14
+ import androidx.compose.ui.graphics.Shape
15
+ import androidx.compose.ui.graphics.shadow.Shadow
16
+ import androidx.compose.ui.unit.Density
17
+ import androidx.compose.ui.unit.Dp
18
+ import androidx.compose.ui.unit.DpOffset
19
+ import androidx.compose.ui.unit.LayoutDirection
20
+ import androidx.compose.ui.unit.dp
21
+ import androidx.compose.foundation.background
22
+ import androidx.compose.runtime.Composable
23
+ import vn.momo.kits.const.AppTheme
24
+
25
+ // Rounded container, with the notch dipped into the top edge around `notchCenterX` (from the left).
26
+ internal class NotchedBarShape(
27
+ private val radius: Dp,
28
+ private val notchCenterX: Dp? = null,
29
+ ) : Shape {
30
+ override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
31
+ val r = minOf(with(density) { radius.toPx() }, size.height / 2, size.width / 2)
32
+ val path = Path()
33
+ if (notchCenterX == null) {
34
+ path.addRoundRect(RoundRect(Rect(0f, 0f, size.width, size.height), CornerRadius(r)))
35
+ return Outline.Generic(path)
36
+ }
37
+ val cx = with(density) { notchCenterX.toPx() }
38
+ val unit = density.density
39
+ path.apply {
40
+ moveTo(r, 0f)
41
+ lineTo(cx - NOTCH_HALF_WIDTH * unit, 0f)
42
+ NOTCH_CURVES.forEach { (c1, c2, end) ->
43
+ cubicTo(
44
+ cx + c1.first * unit, c1.second * unit,
45
+ cx + c2.first * unit, c2.second * unit,
46
+ cx + end.first * unit, end.second * unit,
47
+ )
48
+ }
49
+ lineTo(size.width - r, 0f)
50
+ arcTo(Rect(size.width - 2 * r, 0f, size.width, 2 * r), -90f, 90f, false)
51
+ lineTo(size.width, size.height - r)
52
+ arcTo(Rect(size.width - 2 * r, size.height - 2 * r, size.width, size.height), 0f, 90f, false)
53
+ lineTo(r, size.height)
54
+ arcTo(Rect(0f, size.height - 2 * r, 2 * r, size.height), 90f, 90f, false)
55
+ lineTo(0f, r)
56
+ arcTo(Rect(0f, 0f, 2 * r, 2 * r), 180f, 90f, false)
57
+ close()
58
+ }
59
+ return Outline.Generic(path)
60
+ }
61
+ }
62
+
63
+ // The shape shrunk by `inset` on every side. A shadow cast from it with no spread is a shadow of the
64
+ // shape with spread -inset; dropShadow's own negative spread clips the blur of path outlines.
65
+ internal class InsetShape(private val shape: Shape, private val inset: Dp) : Shape {
66
+ override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
67
+ val insetPx = with(density) { inset.toPx() }
68
+ val inner = Size((size.width - 2 * insetPx).coerceAtLeast(0f), (size.height - 2 * insetPx).coerceAtLeast(0f))
69
+ val path = Path().apply {
70
+ addOutline(shape.createOutline(inner, layoutDirection, density))
71
+ translate(Offset(insetPx, insetPx))
72
+ }
73
+ return Outline.Generic(path)
74
+ }
75
+ }
76
+
77
+ // Shadow with a negative spread, cast from the shrunk shape.
78
+ internal fun Modifier.spreadShadow(shape: Shape, shadow: Shadow): Modifier =
79
+ if (shadow.spread < 0.dp) dropShadow(
80
+ InsetShape(shape, -shadow.spread),
81
+ Shadow(radius = shadow.radius, color = shadow.color, offset = shadow.offset, alpha = shadow.alpha),
82
+ )
83
+ else dropShadow(shape, shadow)
84
+
85
+ // Navigation bar container: surface fill with the floating shadow following the shape (Figma
86
+ // Shadow/floating: 12% blur 24, 4% y12 blur 32 spread -16).
87
+ @Composable
88
+ internal fun Modifier.tabBarContainer(shape: Shape): Modifier =
89
+ dropShadow(shape, Shadow(radius = 24.dp, color = Color.Black, alpha = 0.12f))
90
+ .spreadShadow(
91
+ shape,
92
+ Shadow(radius = 32.dp, spread = (-16).dp, color = Color.Black, alpha = 0.04f, offset = DpOffset(0.dp, 12.dp)),
93
+ )
94
+ .background(AppTheme.current.colors.background.surface, shape)
@@ -0,0 +1,97 @@
1
+ package vn.momo.kits.navigation.bottomtab
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.Stable
5
+ import androidx.compose.runtime.compositionLocalOf
6
+ import androidx.compose.runtime.getValue
7
+ import androidx.compose.runtime.mutableStateOf
8
+ import androidx.compose.runtime.remember
9
+ import androidx.compose.runtime.setValue
10
+ import androidx.compose.ui.unit.Dp
11
+ import vn.momo.kits.const.Spacing
12
+ import vn.momo.kits.layout.DuoMetrics
13
+ import vn.momo.kits.layout.ScreenLayout
14
+
15
+ // iPhone Duo: which side bar bar starts compressed when the strip cannot hold both whole.
16
+ enum class DuoBarCompressionBehavior { TOOLBAR, TAB_BAR }
17
+
18
+ private enum class DuoBar { TOOLBAR, TAB_BAR }
19
+
20
+ @Stable
21
+ internal class DuoBarCompression(
22
+ val toolbarCompressed: Boolean = false,
23
+ val tabBarCompressed: Boolean = false,
24
+ // the open rail needs the toolbar button slot too: only Back stays
25
+ val toolbarHidden: Boolean = false,
26
+ val expandToolbar: () -> Unit = {},
27
+ val expandTabBar: () -> Unit = {},
28
+ // a rail opened from the compressed state closes once a tab is picked
29
+ val onTabSelected: () -> Unit = {},
30
+ // side bar columns report their full height so the tab bar knows what is left
31
+ val setToolbarHeight: (Dp) -> Unit = {},
32
+ )
33
+
34
+ internal val LocalDuoBarCompression = compositionLocalOf { DuoBarCompression() }
35
+
36
+ // space kept between the top and the bottom groups (HIG Vertical controls)
37
+ internal val DUO_GROUP_GAP = Spacing.M
38
+ // Back, then the right toolkit: help + home capsule
39
+ private val DEFAULT_TOOLBAR_HEIGHT = DuoMetrics.controlSize + Spacing.M + DuoMetrics.itemPitch * 2
40
+ // Back, then the single button the toolbar folds into
41
+ private val COMPRESSED_TOOLBAR_HEIGHT = DuoMetrics.controlSize * 2 + Spacing.M
42
+
43
+ // Port of RN DuoBarCompression (HIG, Designing for iPhone Duo: Vertical controls):
44
+ // - both fit: both stay whole
45
+ // - one fits whole beside the other compressed: one is compressed, tapping it swaps them
46
+ // - otherwise both rest compressed; tapping one opens it for a moment (the rail closes
47
+ // again once a tab is picked)
48
+ @Composable
49
+ internal fun rememberDuoBarCompression(
50
+ behavior: DuoBarCompressionBehavior,
51
+ tabCount: Int,
52
+ hasQr: Boolean,
53
+ layout: ScreenLayout,
54
+ ): DuoBarCompression {
55
+ var toolbarHeight by remember { mutableStateOf(DEFAULT_TOOLBAR_HEIGHT) }
56
+ var expanded by remember(behavior) {
57
+ mutableStateOf(if (behavior == DuoBarCompressionBehavior.TOOLBAR) DuoBar.TAB_BAR else DuoBar.TOOLBAR)
58
+ }
59
+ var opened by remember { mutableStateOf<DuoBar?>(null) }
60
+ val setToolbarHeight = remember { { height: Dp -> toolbarHeight = height } }
61
+ val sideBar = layout.sideBar
62
+
63
+ return remember(sideBar, layout.height, tabCount, hasQr, toolbarHeight, expanded, opened) {
64
+ if (sideBar == null) return@remember DuoBarCompression()
65
+ val room = layout.height - sideBar.bottom - sideBar.top - DUO_GROUP_GAP
66
+ val tabBar = duoRailHeight(tabCount, hasQr)
67
+ val compressedTabBar = duoRailHeight(1, hasQr, compressed = true)
68
+ fun fits(toolbar: Dp, tabs: Dp) = toolbar + tabs <= room
69
+
70
+ when {
71
+ fits(toolbarHeight, tabBar) -> DuoBarCompression(setToolbarHeight = setToolbarHeight)
72
+ fits(COMPRESSED_TOOLBAR_HEIGHT, tabBar) && fits(toolbarHeight, compressedTabBar) -> DuoBarCompression(
73
+ toolbarCompressed = expanded == DuoBar.TAB_BAR,
74
+ tabBarCompressed = expanded == DuoBar.TOOLBAR,
75
+ expandToolbar = { expanded = DuoBar.TOOLBAR },
76
+ expandTabBar = { expanded = DuoBar.TAB_BAR },
77
+ setToolbarHeight = setToolbarHeight,
78
+ )
79
+ // an opened rail always shows, even when only the group gap is short: it closes once a tab is picked
80
+ opened == DuoBar.TAB_BAR -> DuoBarCompression(
81
+ toolbarCompressed = true,
82
+ toolbarHidden = true,
83
+ expandToolbar = { opened = DuoBar.TOOLBAR },
84
+ expandTabBar = { opened = DuoBar.TAB_BAR },
85
+ onTabSelected = { opened = null },
86
+ setToolbarHeight = setToolbarHeight,
87
+ )
88
+ else -> DuoBarCompression(
89
+ toolbarCompressed = opened != DuoBar.TOOLBAR,
90
+ tabBarCompressed = true,
91
+ expandToolbar = { opened = DuoBar.TOOLBAR },
92
+ expandTabBar = { opened = DuoBar.TAB_BAR },
93
+ setToolbarHeight = setToolbarHeight,
94
+ )
95
+ }
96
+ }
97
+ }