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