@momo-kits/native-kits 0.168.1-beta.4-debug → 0.168.1-beta.40-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 (100) hide show
  1. package/CLAUDE.md +15 -10
  2. package/README.md +2 -10
  3. package/build.gradle.kts +1 -3
  4. package/compose/build.gradle.kts +20 -19
  5. package/compose/build.gradle.kts.backup +19 -18
  6. package/compose/compose.podspec +1 -1
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +4 -3
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
  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 +1 -1
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -14
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +14 -23
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +21 -15
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +84 -82
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -3
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +2 -1
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +18 -14
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +20 -13
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +117 -62
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +22 -6
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +16 -26
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +54 -36
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +1 -6
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +35 -29
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +321 -149
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +2 -3
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +89 -198
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +1 -1
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +3 -1
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +30 -44
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +2 -2
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +32 -40
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +12 -3
  43. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +3 -1
  44. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +2 -6
  45. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +12 -10
  46. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  47. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +60 -10
  48. package/gradle/libs.versions.toml +4 -11
  49. package/gradle/wrapper/gradle-wrapper.properties +1 -3
  50. package/gradle.properties +3 -3
  51. package/ios/Application/ApplicationEnvironment.swift +7 -6
  52. package/ios/Application/DesignSystemKits.swift +163 -0
  53. package/ios/Application/DesignSystemKitsPayload.swift +68 -0
  54. package/ios/Badge/BadgeRibbon.swift +8 -1
  55. package/ios/Extensions/Color++.swift +2 -4
  56. package/ios/Input/Input.swift +16 -4
  57. package/ios/Input/InputPhoneNumber.swift +1 -3
  58. package/ios/Input/InputSearch.swift +1 -2
  59. package/ios/Input/InputTextArea.swift +8 -4
  60. package/ios/InputMoney/InputMoney.swift +6 -7
  61. package/ios/Layout/ModalLayout.swift +152 -0
  62. package/ios/Layout/ScreenLayout.swift +77 -18
  63. package/ios/Navigation/BottomSheet.swift +56 -53
  64. package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
  65. package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
  66. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  67. package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
  68. package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
  69. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  70. package/ios/Navigation/Component/HeaderBackground.swift +22 -1
  71. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  72. package/ios/Navigation/Component/SnackBar.swift +4 -0
  73. package/ios/Navigation/ModalScreen.swift +20 -5
  74. package/ios/Navigation/StackScreen.swift +6 -8
  75. package/ios/Popup/PopupDisplay.swift +6 -4
  76. package/ios/Popup/PopupInput.swift +6 -4
  77. package/ios/Popup/PopupLayout.swift +17 -11
  78. package/ios/Popup/PopupNotify.swift +32 -25
  79. package/ios/Stepper/Stepper.swift +1 -2
  80. package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
  81. package/ios/Typography/FontScale.swift +29 -15
  82. package/ios/Typography/Text.swift +88 -14
  83. package/ios/Typography/Typography.swift +2 -2
  84. package/ios/native-kits.podspec +1 -1
  85. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  86. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  87. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  88. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  89. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  90. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  91. package/package.json +1 -1
  92. package/publish.sh +2 -33
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitDesignSystem.kt +0 -18
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +0 -37
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +0 -41
  97. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +0 -44
  98. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +0 -62
  99. package/ios/Typography/FontScaleStore.swift +0 -58
  100. package/ios/Typography/KitDesignSystem.swift +0 -17
@@ -1,40 +1,55 @@
1
1
  package vn.momo.kits.navigation.bottomtab
2
2
 
3
+ import androidx.compose.runtime.getValue
4
+ import androidx.compose.animation.animateColorAsState
3
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.dropShadow
14
+ import androidx.compose.ui.draw.innerShadow
15
+ import androidx.compose.ui.graphics.Shape
16
+ import androidx.compose.ui.graphics.graphicsLayer
17
+ import androidx.compose.ui.layout.onPlaced
18
+ import androidx.compose.ui.layout.positionInParent
19
+ import androidx.compose.ui.platform.LocalDensity
20
+ import androidx.compose.ui.semantics.Role
21
+ import androidx.compose.ui.semantics.contentDescription
22
+ import androidx.compose.ui.semantics.role
23
+ import androidx.compose.ui.semantics.selected
24
+ import androidx.compose.ui.semantics.semantics
4
25
  import androidx.compose.foundation.background
5
26
  import androidx.compose.foundation.border
6
27
  import androidx.compose.foundation.layout.*
7
28
  import androidx.compose.foundation.shape.CircleShape
8
29
  import androidx.compose.foundation.shape.RoundedCornerShape
9
30
  import androidx.compose.runtime.Composable
10
- import androidx.compose.runtime.LaunchedEffect
11
- import androidx.compose.runtime.getValue
12
- import androidx.compose.runtime.mutableIntStateOf
31
+ import androidx.compose.runtime.CompositionLocalProvider
13
32
  import androidx.compose.runtime.remember
14
- import androidx.compose.runtime.saveable.rememberSaveable
15
- import androidx.compose.runtime.setValue
16
33
  import androidx.compose.ui.Alignment
17
34
  import androidx.compose.ui.Modifier
18
- import androidx.compose.ui.draw.clip
19
- import androidx.compose.ui.graphics.Brush
20
- import androidx.compose.ui.graphics.Color
21
35
  import androidx.compose.ui.text.style.TextAlign
22
36
  import androidx.compose.ui.text.style.TextOverflow
23
- import androidx.compose.ui.unit.Dp
24
- import androidx.compose.ui.unit.IntOffset
25
37
  import androidx.compose.ui.unit.dp
26
38
  import vn.momo.kits.application.IsShowBaseLineDebug
39
+ import vn.momo.kits.application.LocalContext
40
+ import vn.momo.kits.application.MiniAppContext
27
41
  import vn.momo.kits.components.*
28
42
  import vn.momo.kits.const.*
43
+ import vn.momo.kits.layout.getScreenLayout
29
44
  import vn.momo.kits.modifier.InternalApi
30
- import vn.momo.kits.modifier.conditional
31
45
  import vn.momo.kits.modifier.activeOpacityClickable
32
- import vn.momo.kits.layout.getScreenLayout
33
- import vn.momo.kits.utils.horizontalSafeAreaPadding
46
+ import vn.momo.kits.modifier.conditional
47
+ import vn.momo.kits.modifier.setAutomationId
34
48
 
35
49
  @InternalApi
36
- const val BOTTOM_TAB_BAR_HEIGHT = 64
50
+ const val BOTTOM_TAB_BAR_HEIGHT = 68
37
51
 
52
+ // Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
38
53
  @Composable
39
54
  internal fun BottomTabBar(
40
55
  items: List<BottomTabItem>,
@@ -42,176 +57,333 @@ internal fun BottomTabBar(
42
57
  selectedIndex: Int,
43
58
  onTabSelected: (Int) -> Unit,
44
59
  ) {
45
-
46
60
  val layout = getScreenLayout()
47
- val mid = items.size / 2
48
-
49
- val floating = floatingButton?.takeIf { items.size % 2 == 0 }
50
- val slotWidth = layout.contentWidth / (items.size + if (floating != null) 1 else 0)
51
- fun slotOf(index: Int) = if (floating != null && index >= mid) index + 1 else index
52
-
53
- var indicatorSlot by rememberSaveable { mutableIntStateOf(0) }
54
- val indicatorX = remember { Animatable(indicatorSlot.toFloat()) }
55
- LaunchedEffect(selectedIndex) {
56
- val target = slotOf(selectedIndex)
57
- indicatorSlot = target
58
- indicatorX.animateTo(target.toFloat(), tabTimingSpec)
59
- }
60
-
61
61
  Box(
62
- contentAlignment = Alignment.BottomCenter
62
+ modifier = Modifier
63
+ .fillMaxWidth()
64
+ .padding(bottom = tabBarBottomGap(layout.insetBottom)),
65
+ contentAlignment = Alignment.BottomCenter,
63
66
  ) {
64
- Row(
67
+ HorizontalTabBar(
68
+ items = items,
69
+ floatingButton = floatingButton,
70
+ selectedIndex = selectedIndex,
71
+ onTabSelected = onTabSelected,
65
72
  modifier = Modifier
73
+ .offset(x = (layout.insetLeft - layout.insetRight) / 2)
74
+ .width(horizontalBarWidth(layout.width, layout.height, layout.insetLeft, layout.insetRight)),
75
+ )
76
+ }
77
+ }
78
+
79
+ // Horizontal navigation bar: floating container, items split evenly; Special type puts the center
80
+ // action in a notch in the middle, rising ctaLift above the container. One active indicator slides
81
+ // behind the selected item.
82
+ @Composable
83
+ internal fun HorizontalTabBar(
84
+ items: List<BottomTabItem>,
85
+ floatingButton: BottomTabFloatingButton?,
86
+ selectedIndex: Int,
87
+ onTabSelected: (Int) -> Unit,
88
+ modifier: Modifier = Modifier,
89
+ fixedFontScale: Boolean = false,
90
+ ) {
91
+ val cta = floatingButton?.takeIf { hasCenterAction(it, items.size) }
92
+ val mid = items.size / 2
93
+ val density = LocalDensity.current
94
+ val itemBounds = remember(items.size) { mutableStateMapOf<Int, Pair<Float, Float>>() }
95
+
96
+ BoxWithConstraints(modifier = modifier) {
97
+ val shape = remember(maxWidth, cta != null) {
98
+ NotchedBarShape(TabBarMetrics.height / 2, if (cta != null) maxWidth / 2 else null)
99
+ }
100
+ Box(
101
+ modifier = Modifier
102
+ .padding(top = if (cta != null) TabBarMetrics.ctaLift else 0.dp)
66
103
  .fillMaxWidth()
67
- .height(BOTTOM_TAB_BAR_HEIGHT.dp)
68
- .background(AppTheme.current.colors.background.surface)
69
- .conditional(IsShowBaseLineDebug) {
70
- border(1.dp, Colors.blue_03)
71
- }
72
- .horizontalSafeAreaPadding(),
73
- horizontalArrangement = Arrangement.SpaceAround,
104
+ .height(TabBarMetrics.height)
105
+ .tabBarContainer(shape)
106
+ .padding(horizontal = TabBarMetrics.paddingHorizontal, vertical = TabBarMetrics.paddingVertical)
107
+ .setAutomationId("bottom_tab_bar"),
74
108
  ) {
75
- if (floating == null) {
76
- RenderTabBarItem(items, 0, items.size, selectedIndex, onTabSelected)
77
- } else {
78
- RenderTabBarItem(items, 0, mid, selectedIndex, onTabSelected)
79
- Spacer(modifier = Modifier.width(slotWidth))
80
- RenderTabBarItem(items, mid, items.size, selectedIndex, onTabSelected)
109
+ itemBounds[selectedIndex]?.let { (x, width) ->
110
+ ActiveIndicator(
111
+ offset = x,
112
+ modifier = Modifier
113
+ .width(with(density) { width.toDp() })
114
+ .height(TabBarMetrics.indicatorHeight),
115
+ shape = RoundedCornerShape(TabBarMetrics.indicatorRadius),
116
+ axisX = true,
117
+ )
118
+ }
119
+ Row(
120
+ modifier = Modifier.fillMaxSize(),
121
+ horizontalArrangement = Arrangement.spacedBy(TabBarMetrics.itemGap),
122
+ verticalAlignment = Alignment.CenterVertically,
123
+ ) {
124
+ items.forEachIndexed { index, item ->
125
+ if (cta != null && index == mid) {
126
+ Spacer(Modifier.width(TabBarMetrics.ctaSlotWidth))
127
+ }
128
+ TabBarItem(
129
+ item = item,
130
+ selected = index == selectedIndex,
131
+ fixedFontScale = fixedFontScale,
132
+ modifier = Modifier.onPlaced {
133
+ itemBounds[index] = it.positionInParent().x to it.size.width.toFloat()
134
+ },
135
+ onClick = { onTabSelected(index) },
136
+ )
137
+ }
81
138
  }
82
139
  }
140
+ cta?.let { CenterAction(it, fixedFontScale, Modifier.align(Alignment.TopCenter)) }
141
+ }
142
+ }
83
143
 
84
- Box(modifier = Modifier
85
- .offset { IntOffset((layout.insetLeft + slotWidth * (indicatorX.value + 0.5f) - layout.width / 2).roundToPx(), (-BOTTOM_TAB_BAR_HEIGHT + 2).dp.roundToPx()) }
86
- .height(2.dp)
87
- .width(44.dp)
88
- .background(
89
- color = AppTheme.current.colors.primary ,
90
- shape = RoundedCornerShape(bottomStart = 2.dp, bottomEnd = 2.dp)
144
+ // One active indicator per bar (Background/tonal with its inner shadows) sliding to the selected item
145
+ // along x (horizontal bar) or y (rail); it lands in place on the first measure and slides from then on.
146
+ @Composable
147
+ internal fun ActiveIndicator(offset: Float, modifier: Modifier, shape: Shape, axisX: Boolean) {
148
+ val colors = AppTheme.current.colors
149
+ val position = remember { Animatable(offset) }
150
+ LaunchedEffect(offset) {
151
+ if (position.value != offset) position.animateTo(offset, TabBarMotion.indicator)
152
+ }
153
+ Box(
154
+ modifier
155
+ .graphicsLayer {
156
+ if (axisX) translationX = position.value else translationY = position.value
157
+ }
158
+ .background(colors.background.tonal, shape)
159
+ .then(
160
+ indicatorInnerShadows(colors.primary).fold(Modifier as Modifier) { acc, shadow ->
161
+ acc.innerShadow(shape, shadow)
162
+ }
91
163
  )
92
- )
164
+ )
165
+ }
93
166
 
94
- Box(modifier = Modifier
95
- .fillMaxWidth()
96
- .height(6.dp)
97
- .offset(x = 0.dp, y = (-BOTTOM_TAB_BAR_HEIGHT).dp)
98
- .background(
99
- brush = Brush.verticalGradient(
100
- colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.05f))
101
- )
102
- )
103
- )
104
- floating?.let {
105
- Box(Modifier.offset(x = (layout.insetLeft - layout.insetRight) / 2)) {
106
- FloatingButton(it, slotWidth)
167
+ @Composable
168
+ private fun RowScope.TabBarItem(
169
+ item: BottomTabItem,
170
+ selected: Boolean,
171
+ fixedFontScale: Boolean,
172
+ modifier: Modifier,
173
+ onClick: () -> Unit,
174
+ ) {
175
+ Column(
176
+ modifier = modifier
177
+ .weight(1f)
178
+ .conditional(IsShowBaseLineDebug) {
179
+ border(1.dp, Colors.blue_03)
107
180
  }
108
- }
181
+ .activeOpacityClickable { onClick() }
182
+ .semantics {
183
+ role = Role.Tab
184
+ this.selected = selected
185
+ contentDescription = item.label
186
+ },
187
+ horizontalAlignment = Alignment.CenterHorizontally,
188
+ verticalArrangement = Arrangement.spacedBy(Spacing.XXS),
189
+ ) {
190
+ TabItemContent(item, selected, fixedFontScale = fixedFontScale)
109
191
  }
110
192
  }
111
193
 
194
+ // Icon in its indicator slot, label under it. The bar slides one shared active indicator behind the
195
+ // slots; the icon and label tint cross-fade on focus.
112
196
  @Composable
113
- internal fun RowScope.RenderTabBarItem(
114
- items: List<BottomTabItem>,
115
- fromIndex: Int,
116
- toIndex: Int,
117
- selectedIndex: Int,
118
- onTabSelected: (Int) -> Unit
119
- ){
120
- for (index in fromIndex until toIndex) {
121
- Box(modifier = Modifier.weight(1f)) {
122
- TabBarItem(
123
- item = items[index],
124
- selected = index == selectedIndex,
125
- onClick = { onTabSelected(index) }
197
+ internal fun ColumnScope.TabItemContent(
198
+ item: BottomTabItem,
199
+ selected: Boolean,
200
+ vertical: Boolean = false,
201
+ showLabel: Boolean = true,
202
+ fixedFontScale: Boolean = false,
203
+ ) {
204
+ val colors = AppTheme.current.colors
205
+ val tint by animateColorAsState(
206
+ if (selected) colors.primary else colors.text.secondary,
207
+ tween(TabBarMotion.TINT_MILLIS, easing = inOutQuad),
208
+ label = "TabTint",
209
+ )
210
+
211
+ Box(
212
+ modifier = Modifier
213
+ .then(if (vertical) Modifier else Modifier.fillMaxWidth())
214
+ .height(if (vertical) TabBarMetrics.railIndicatorHeight else TabBarMetrics.indicatorHeight)
215
+ .padding(horizontal = TabBarMetrics.indicatorPaddingHorizontal),
216
+ contentAlignment = Alignment.Center,
217
+ ) {
218
+ TabIcon(item, tint, vertical)
219
+ }
220
+ if (showLabel) {
221
+ val label = @Composable {
222
+ Text(
223
+ text = item.label,
224
+ color = tint,
225
+ style = if (vertical) Typography.labelXsMedium else Typography.labelSMedium,
226
+ textAlign = TextAlign.Center,
227
+ maxLines = 1,
228
+ overflow = TextOverflow.Ellipsis,
229
+ modifier = if (vertical) Modifier else Modifier.fillMaxWidth(),
126
230
  )
127
231
  }
232
+ if (fixedFontScale) FixedFontScale(label) else label()
128
233
  }
129
234
  }
130
235
 
236
+ // Like the system tab bar the label keeps its design size; Text grows it up to 5pt on the wide Duo displays.
131
237
  @Composable
132
- internal fun TabBarItem(item: BottomTabItem, selected: Boolean, onClick: () -> Unit) {
133
- // RN parity: "0" hides the badge, "" renders a dot.
134
- val badgeLabel = item.badgeLabel?.takeUnless { it.toIntOrNull() == 0 }
135
- val isNumber = badgeLabel?.toIntOrNull() != null
136
- val showDot = badgeLabel?.isEmpty() ?: item.showDot
137
-
138
- Box(modifier = Modifier
139
- .fillMaxSize()
140
- .padding(horizontal = Spacing.XXS)
141
- .conditional(IsShowBaseLineDebug) {
142
- border(1.dp, Colors.blue_03)
238
+ internal fun FixedFontScale(content: @Composable () -> Unit) {
239
+ val context = LocalContext.current
240
+ val fixedScale = remember(context) {
241
+ (context ?: MiniAppContext()).copy(userScaleRate = 1f, useOSScaleRate = false)
242
+ }
243
+ CompositionLocalProvider(LocalContext provides fixedScale, content = content)
244
+ }
245
+
246
+ // Badge value shown on a tab: null hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
247
+ internal fun tabBadgeLabel(item: BottomTabItem): String? {
248
+ val label = item.badgeLabel ?: return if (item.showDot) "" else null
249
+ if (label.isEmpty()) return ""
250
+ if (label.all { it in '0'..'9' }) {
251
+ val value = label.toLongOrNull() ?: Long.MAX_VALUE
252
+ if (value == 0L) return if (item.showDot) "" else null
253
+ return if (value > 99) "99+" else label
254
+ }
255
+ return label
256
+ }
257
+
258
+ // 24 icon; badges hang off it unclipped: dot at 16/-2, label badge at 12/-7 growing right, or
259
+ // centered over the icon at -10 on the rail.
260
+ @Composable
261
+ internal fun TabIcon(item: BottomTabItem, tint: androidx.compose.ui.graphics.Color, vertical: Boolean) {
262
+ val badge = tabBadgeLabel(item)
263
+ Box(Modifier.size(TabBarMetrics.iconSize)) {
264
+ Icon(source = item.icon, size = TabBarMetrics.iconSize, color = tint)
265
+ when {
266
+ badge == null -> Unit
267
+ badge.isEmpty() -> BadgeDot(
268
+ size = DotSize.Small,
269
+ modifier = Modifier.offset(x = 16.dp, y = -Spacing.XXS),
270
+ )
271
+ vertical -> TabBadge(
272
+ badge,
273
+ Modifier.matchParentSize()
274
+ .wrapContentSize(Alignment.TopCenter, unbounded = true)
275
+ .offset(y = (-10).dp),
276
+ )
277
+ else -> TabBadge(
278
+ badge,
279
+ Modifier.matchParentSize()
280
+ .wrapContentSize(Alignment.TopStart, unbounded = true)
281
+ .offset(x = Spacing.M, y = (-7).dp),
282
+ )
143
283
  }
144
- .activeOpacityClickable {
145
- onClick()
146
- },
147
- contentAlignment = Alignment.BottomStart
148
- ){
149
- Column(
150
- modifier = Modifier
151
- .fillMaxSize()
152
- .padding(horizontal = Spacing.S, vertical = Spacing.S),
153
- horizontalAlignment = Alignment.CenterHorizontally,
154
- verticalArrangement = Arrangement.Center
155
- ) {
156
- Box(modifier = Modifier.padding(Spacing.XS)) {
157
- Icon(
158
- source = item.icon,
159
- size = 28.dp,
160
- color = if (selected) AppTheme.current.colors.primary else AppTheme.current.colors.text.hint)
161
- val badgeAnchor = Modifier.matchParentSize().wrapContentSize(Alignment.TopEnd, unbounded = true)
162
- if (showDot) {
163
- BadgeDot(size = DotSize.Small, modifier = badgeAnchor.offset(x = 4.dp, y = (-4).dp))
164
- } else if (!badgeLabel.isNullOrEmpty()) {
165
- Badge(badgeLabel, modifier = badgeAnchor.offset(x = if (isNumber) 8.dp else 12.dp, y = (-8).dp))
166
- }
167
- }
284
+ }
285
+ }
286
+
287
+ // Numbers use the error color, text the warning color (Figma Badge round numeric / text); the text keeps
288
+ // its design size so it fits the 16 height on the Duo displays too.
289
+ @Composable
290
+ private fun TabBadge(label: String, modifier: Modifier) {
291
+ val colors = AppTheme.current.colors
292
+ val isNumber = label.trimEnd('+').let { it.isNotEmpty() && it.all { c -> c in '0'..'9' } }
293
+ Box(
294
+ modifier = modifier
295
+ .height(16.dp)
296
+ .widthIn(min = 16.dp, max = TabBarMetrics.badgeMaxWidth)
297
+ .background(if (isNumber) colors.error.primary else colors.warning.primary, CircleShape)
298
+ .border(1.dp, colors.background.surface, CircleShape)
299
+ .padding(horizontal = Spacing.XS),
300
+ contentAlignment = Alignment.Center,
301
+ ) {
302
+ FixedFontScale {
168
303
  Text(
169
- text = item.label,
170
- color = if (selected) AppTheme.current.colors.primary else AppTheme.current.colors.text.hint,
171
- style = if (selected) Typography.labelXsMedium else Typography.descriptionXsRegular,
304
+ text = label,
305
+ style = Typography.actionXxsBold,
306
+ color = Colors.black_01,
172
307
  maxLines = 1,
173
- overflow = TextOverflow.Ellipsis
308
+ overflow = TextOverflow.Ellipsis,
174
309
  )
175
310
  }
176
311
  }
177
312
  }
178
313
 
314
+ // Center action press: the button shrinks while held; the label stays plain text.
179
315
  @Composable
180
- internal fun FloatingButton(data: BottomTabFloatingButton, width: Dp) {
181
- Column(
316
+ internal fun rememberCenterActionPress(): Pair<MutableInteractionSource, Boolean> {
317
+ val interactionSource = remember { MutableInteractionSource() }
318
+ val pressed by interactionSource.collectIsPressedAsState()
319
+ return interactionSource to pressed
320
+ }
321
+
322
+ @Composable
323
+ internal fun Modifier.centerActionPressScale(pressed: Boolean): Modifier {
324
+ val scale by animateFloatAsState(
325
+ if (pressed) TabBarMotion.CTA_PRESSED_SCALE else 1f,
326
+ tween(TabBarMotion.CTA_PRESS_MILLIS, easing = inOutQuad),
327
+ label = "CenterActionPress",
328
+ )
329
+ return graphicsLayer {
330
+ scaleX = scale
331
+ scaleY = scale
332
+ }
333
+ }
334
+
335
+ @Composable
336
+ internal fun Modifier.centerActionButton(size: androidx.compose.ui.unit.Dp, pressed: Boolean): Modifier {
337
+ return centerActionPressScale(pressed)
338
+ .size(size)
339
+ .then(CtaShadows.fold(Modifier as Modifier) { acc, shadow -> acc.spreadShadow(CircleShape, shadow) })
340
+ .background(AppTheme.current.colors.primary, CircleShape)
341
+ }
342
+
343
+ @Composable
344
+ internal fun CenterActionLabel(label: String, overlay: (@Composable () -> Unit)?, vertical: Boolean, fixedFontScale: Boolean) {
345
+ val colors = AppTheme.current.colors
346
+ val text = @Composable {
347
+ Text(
348
+ text = label,
349
+ style = if (vertical) Typography.labelXsMedium else Typography.labelSMedium,
350
+ color = colors.text.secondary,
351
+ textAlign = TextAlign.Center,
352
+ maxLines = 1,
353
+ overflow = TextOverflow.Ellipsis,
354
+ )
355
+ }
356
+ Box(
182
357
  modifier = Modifier
183
- .width(width)
184
- .padding(horizontal = Spacing.XXS, vertical = Spacing.S)
358
+ .then(if (vertical) Modifier else Modifier.heightIn(min = TabBarMetrics.ctaLabelHeight))
359
+ .padding(horizontal = if (vertical) Spacing.XS else Spacing.XXS),
360
+ contentAlignment = Alignment.Center,
361
+ ) {
362
+ if (fixedFontScale) FixedFontScale(text) else text()
363
+ overlay?.let {
364
+ Box(Modifier.matchParentSize().wrapContentSize(Alignment.Center, unbounded = true)) { it() }
365
+ }
366
+ }
367
+ }
368
+
369
+ // Center action (.Nav/CTA): button rising out of the notch, label under it.
370
+ @Composable
371
+ private fun CenterAction(data: BottomTabFloatingButton, fixedFontScale: Boolean, modifier: Modifier) {
372
+ val (interactionSource, pressed) = rememberCenterActionPress()
373
+ Column(
374
+ modifier = modifier
375
+ .width(TabBarMetrics.ctaSlotWidth)
185
376
  .conditional(IsShowBaseLineDebug) {
186
377
  border(1.dp, Colors.blue_03)
187
378
  }
188
- .activeOpacityClickable {
189
- data.onPress()
190
- },
191
- verticalArrangement = Arrangement.Bottom,
192
- horizontalAlignment = Alignment.CenterHorizontally
193
-
194
- ){
195
- CurvedContainer()
196
- Box(
197
- modifier = Modifier
198
- .size(48.dp)
199
- .clip(CircleShape)
200
- .background(AppTheme.current.colors.primary),
201
- contentAlignment = Alignment.Center
202
- ) {
203
- Icon(source = data.icon, color = Color.White, size = 28.dp)
379
+ .clickable(interactionSource = interactionSource, indication = null, onClick = data.onPress)
380
+ .setAutomationId(data.label),
381
+ horizontalAlignment = Alignment.CenterHorizontally,
382
+ verticalArrangement = Arrangement.spacedBy(TabBarMetrics.ctaLabelGap),
383
+ ) {
384
+ Box(Modifier.centerActionButton(TabBarMetrics.ctaSize, pressed), contentAlignment = Alignment.Center) {
385
+ data.iconContent?.invoke() ?: Icon(source = data.icon, color = Colors.black_01, size = TabBarMetrics.ctaIconSize)
204
386
  }
205
- Spacer(modifier = Modifier.height(4.dp))
206
- Text(
207
- text = data.label,
208
- style = Typography.labelXsMedium,
209
- color = Colors.black_01,
210
- textAlign = TextAlign.Center,
211
- modifier = Modifier
212
- .height(14.dp)
213
- .fillMaxWidth()
214
- .background(AppTheme.current.colors.primary, shape = RoundedCornerShape(size = Radius.XL))
215
- )
387
+ CenterActionLabel(data.label, data.labelContent, vertical = false, fixedFontScale = fixedFontScale)
216
388
  }
217
389
  }