@momo-kits/native-kits 0.168.1-beta.37-debug → 0.168.1-beta.38-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 (47) hide show
  1. package/CLAUDE.md +2 -3
  2. package/compose/build.gradle.kts +1 -1
  3. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
  4. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +81 -72
  5. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +13 -8
  6. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +163 -54
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +12 -17
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +34 -27
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +319 -167
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +93 -326
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -2
  18. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +3 -2
  19. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +3 -9
  20. package/ios/Input/Input.swift +1 -3
  21. package/ios/Input/InputTextArea.swift +1 -3
  22. package/ios/Layout/ScreenLayout.swift +24 -28
  23. package/ios/Navigation/BottomSheet.swift +157 -29
  24. package/ios/Navigation/BottomTab/BottomTab.swift +48 -67
  25. package/ios/Navigation/BottomTab/BottomTabBar.swift +280 -132
  26. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  27. package/ios/Navigation/BottomTab/DuoTabBar.swift +72 -292
  28. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  29. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  30. package/ios/Navigation/ModalScreen.swift +7 -18
  31. package/ios/Navigation/StackScreen.swift +3 -1
  32. package/ios/Popup/PopupDisplay.swift +2 -4
  33. package/ios/Popup/PopupInput.swift +2 -4
  34. package/ios/Popup/PopupLayout.swift +9 -10
  35. package/ios/Popup/PopupNotify.swift +23 -26
  36. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  37. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  38. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  39. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +0 -103
  40. package/package.json +1 -1
  41. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -187
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +0 -380
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
  45. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
  46. package/ios/Layout/ModalLayout.swift +0 -152
  47. package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +0 -364
@@ -1,237 +1,389 @@
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
4
6
  import androidx.compose.animation.core.animateFloatAsState
5
- import androidx.compose.foundation.background
6
- import androidx.compose.foundation.border
7
- import androidx.compose.foundation.combinedClickable
7
+ import androidx.compose.animation.core.tween
8
+ import androidx.compose.foundation.clickable
8
9
  import androidx.compose.foundation.interaction.MutableInteractionSource
9
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
25
+ import androidx.compose.foundation.background
26
+ import androidx.compose.foundation.border
10
27
  import androidx.compose.foundation.layout.*
11
28
  import androidx.compose.foundation.shape.CircleShape
12
29
  import androidx.compose.foundation.shape.RoundedCornerShape
13
30
  import androidx.compose.runtime.Composable
14
- import androidx.compose.runtime.LaunchedEffect
15
- import androidx.compose.runtime.getValue
16
- import androidx.compose.runtime.mutableIntStateOf
31
+ import androidx.compose.runtime.CompositionLocalProvider
17
32
  import androidx.compose.runtime.remember
18
- import androidx.compose.runtime.saveable.rememberSaveable
19
- import androidx.compose.runtime.setValue
20
33
  import androidx.compose.ui.Alignment
21
34
  import androidx.compose.ui.Modifier
22
- import androidx.compose.ui.draw.clip
23
- import androidx.compose.ui.graphics.Brush
24
- import androidx.compose.ui.graphics.Color
25
- import androidx.compose.ui.graphics.graphicsLayer
26
- import androidx.compose.ui.semantics.Role
27
35
  import androidx.compose.ui.text.style.TextAlign
28
36
  import androidx.compose.ui.text.style.TextOverflow
29
- import androidx.compose.ui.unit.Dp
30
- import androidx.compose.ui.unit.IntOffset
31
37
  import androidx.compose.ui.unit.dp
32
38
  import vn.momo.kits.application.IsShowBaseLineDebug
39
+ import vn.momo.kits.application.LocalContext
40
+ import vn.momo.kits.application.MiniAppContext
33
41
  import vn.momo.kits.components.*
34
42
  import vn.momo.kits.const.*
43
+ import vn.momo.kits.layout.getScreenLayout
35
44
  import vn.momo.kits.modifier.InternalApi
36
- import vn.momo.kits.modifier.conditional
37
45
  import vn.momo.kits.modifier.activeOpacityClickable
38
- import vn.momo.kits.layout.getScreenLayout
39
- import vn.momo.kits.utils.horizontalSafeAreaPadding
46
+ import vn.momo.kits.modifier.conditional
47
+ import vn.momo.kits.modifier.setAutomationId
40
48
 
41
49
  @InternalApi
42
- const val BOTTOM_TAB_BAR_HEIGHT = 64
50
+ const val BOTTOM_TAB_BAR_HEIGHT = 68
43
51
 
52
+ // Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
44
53
  @Composable
45
54
  internal fun BottomTabBar(
46
55
  items: List<BottomTabItem>,
47
56
  floatingButton: BottomTabFloatingButton? = null,
48
57
  selectedIndex: Int,
49
58
  onTabSelected: (Int) -> Unit,
50
- onTabLongPress: ((Int) -> Unit)? = null,
51
59
  ) {
52
-
53
60
  val layout = getScreenLayout()
54
- val mid = items.size / 2
55
-
56
- val floating = floatingButton?.takeIf { items.size % 2 == 0 }
57
- val slotWidth = layout.contentWidth / (items.size + if (floating != null) 1 else 0)
58
- fun slotOf(index: Int) = if (floating != null && index >= mid) index + 1 else index
59
-
60
- var indicatorSlot by rememberSaveable { mutableIntStateOf(0) }
61
- val indicatorX = remember { Animatable(indicatorSlot.toFloat()) }
62
- LaunchedEffect(selectedIndex) {
63
- val target = slotOf(selectedIndex)
64
- indicatorSlot = target
65
- indicatorX.animateTo(target.toFloat(), tabTimingSpec)
66
- }
67
-
68
61
  Box(
69
- contentAlignment = Alignment.BottomCenter
62
+ modifier = Modifier
63
+ .fillMaxWidth()
64
+ .padding(bottom = tabBarBottomGap(layout.insetBottom)),
65
+ contentAlignment = Alignment.BottomCenter,
70
66
  ) {
71
- Row(
67
+ HorizontalTabBar(
68
+ items = items,
69
+ floatingButton = floatingButton,
70
+ selectedIndex = selectedIndex,
71
+ onTabSelected = onTabSelected,
72
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)
73
103
  .fillMaxWidth()
74
- .height(BOTTOM_TAB_BAR_HEIGHT.dp)
75
- .background(AppTheme.current.colors.background.surface)
76
- .conditional(IsShowBaseLineDebug) {
77
- border(1.dp, Colors.blue_03)
78
- }
79
- .horizontalSafeAreaPadding(),
80
- horizontalArrangement = Arrangement.SpaceAround,
104
+ .height(TabBarMetrics.height)
105
+ .tabBarContainer(shape)
106
+ .padding(horizontal = TabBarMetrics.paddingHorizontal, vertical = TabBarMetrics.paddingVertical)
107
+ .setAutomationId("bottom_tab_bar"),
81
108
  ) {
82
- if (floating == null) {
83
- RenderTabBarItem(items, 0, items.size, selectedIndex, onTabSelected, onTabLongPress)
84
- } else {
85
- RenderTabBarItem(items, 0, mid, selectedIndex, onTabSelected, onTabLongPress)
86
- Spacer(modifier = Modifier.width(slotWidth))
87
- RenderTabBarItem(items, mid, items.size, selectedIndex, onTabSelected, onTabLongPress)
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
+ }
88
138
  }
89
139
  }
140
+ cta?.let { CenterAction(it, fixedFontScale, Modifier.align(Alignment.TopCenter)) }
141
+ }
142
+ }
90
143
 
91
- Box(modifier = Modifier
92
- .offset { IntOffset((layout.insetLeft + slotWidth * (indicatorX.value + 0.5f) - layout.width / 2).roundToPx(), (-BOTTOM_TAB_BAR_HEIGHT + 2).dp.roundToPx()) }
93
- .height(2.dp)
94
- .width(44.dp)
95
- .background(
96
- color = AppTheme.current.colors.primary ,
97
- 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
+ }
98
163
  )
99
- )
164
+ )
165
+ }
100
166
 
101
- Box(modifier = Modifier
102
- .fillMaxWidth()
103
- .height(6.dp)
104
- .offset(x = 0.dp, y = (-BOTTOM_TAB_BAR_HEIGHT).dp)
105
- .background(
106
- brush = Brush.verticalGradient(
107
- colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.05f))
108
- )
109
- )
110
- )
111
- floating?.let {
112
- Box(Modifier.offset(x = (layout.insetLeft - layout.insetRight) / 2)) {
113
- 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)
114
180
  }
115
- }
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)
116
191
  }
117
192
  }
118
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.
119
196
  @Composable
120
- internal fun RowScope.RenderTabBarItem(
121
- items: List<BottomTabItem>,
122
- fromIndex: Int,
123
- toIndex: Int,
124
- selectedIndex: Int,
125
- onTabSelected: (Int) -> Unit,
126
- onTabLongPress: ((Int) -> Unit)? = null,
127
- ){
128
- for (index in fromIndex until toIndex) {
129
- Box(modifier = Modifier.weight(1f)) {
130
- TabBarItem(
131
- item = items[index],
132
- selected = index == selectedIndex,
133
- onClick = { onTabSelected(index) },
134
- onLongClick = onTabLongPress?.let { { it(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(),
135
230
  )
136
231
  }
232
+ if (fixedFontScale) FixedFontScale(label) else label()
137
233
  }
138
234
  }
139
235
 
236
+ // Like the system tab bar the label keeps its design size; Text grows it up to 5pt on the wide Duo displays.
140
237
  @Composable
141
- internal fun TabBarItem(item: BottomTabItem, selected: Boolean, onClick: () -> Unit, onLongClick: (() -> Unit)? = null) {
142
- // RN parity: "0" hides the badge, "" renders a dot.
143
- val badgeLabel = item.badgeLabel?.takeUnless { it.toIntOrNull() == 0 }
144
- val showDot = badgeLabel?.isEmpty() ?: item.showDot
145
- val interactionSource = remember { MutableInteractionSource() }
146
- val pressed by interactionSource.collectIsPressedAsState()
147
- val alpha by animateFloatAsState(if (pressed) 0.2f else 1f, label = "TabBarItemOpacity")
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
+ }
148
257
 
149
- BoxWithConstraints(modifier = Modifier
150
- .fillMaxSize()
151
- .padding(horizontal = Spacing.XXS)
152
- .conditional(IsShowBaseLineDebug) {
153
- border(1.dp, Colors.blue_03)
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
+ )
154
283
  }
155
- .graphicsLayer { this.alpha = alpha }
156
- .combinedClickable(
157
- interactionSource = interactionSource,
158
- indication = null,
159
- role = Role.Tab,
160
- onLongClick = onLongClick,
161
- onClick = onClick,
162
- ),
163
- contentAlignment = Alignment.BottomStart
164
- ){
165
- // from the icon's center to the cell's end edge
166
- val badgeMaxWidth = (maxWidth / 2 - Spacing.XXS).coerceAtLeast(0.dp)
167
- Column(
168
- modifier = Modifier
169
- .fillMaxSize()
170
- .padding(horizontal = Spacing.S, vertical = Spacing.S),
171
- horizontalAlignment = Alignment.CenterHorizontally,
172
- verticalArrangement = Arrangement.Center
173
- ) {
174
- Box(modifier = Modifier.padding(Spacing.XS)) {
175
- Icon(
176
- source = item.icon,
177
- size = 28.dp,
178
- color = if (selected) AppTheme.current.colors.primary else AppTheme.current.colors.text.hint)
179
- if (showDot) {
180
- val dotAnchor = Modifier.matchParentSize().wrapContentSize(Alignment.TopEnd, unbounded = true)
181
- BadgeDot(size = DotSize.Small, modifier = dotAnchor.offset(x = 4.dp, y = (-4).dp))
182
- } else if (!badgeLabel.isNullOrEmpty()) {
183
- // starts at the icon's center and grows toward the cell's end edge, ellipsized past it
184
- val badgeAnchor = Modifier.matchParentSize().wrapContentSize(Alignment.TopStart, unbounded = true)
185
- Badge(badgeLabel, modifier = badgeAnchor.offset(x = 14.dp, y = (-8).dp).widthIn(max = badgeMaxWidth))
186
- }
187
- }
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 {
188
303
  Text(
189
- text = item.label,
190
- color = if (selected) AppTheme.current.colors.primary else AppTheme.current.colors.text.hint,
191
- style = if (selected) Typography.labelXsMedium else Typography.descriptionXsRegular,
304
+ text = label,
305
+ style = Typography.actionXxsBold,
306
+ color = Colors.black_01,
192
307
  maxLines = 1,
193
- overflow = TextOverflow.Ellipsis
308
+ overflow = TextOverflow.Ellipsis,
194
309
  )
195
310
  }
196
311
  }
197
312
  }
198
313
 
314
+ // Center action press: the button shrinks while held; the label stays plain text.
199
315
  @Composable
200
- internal fun FloatingButton(data: BottomTabFloatingButton, width: Dp) {
201
- 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(
202
357
  modifier = Modifier
203
- .width(width)
204
- .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)
205
376
  .conditional(IsShowBaseLineDebug) {
206
377
  border(1.dp, Colors.blue_03)
207
378
  }
208
- .activeOpacityClickable {
209
- data.onPress()
210
- },
211
- verticalArrangement = Arrangement.Bottom,
212
- horizontalAlignment = Alignment.CenterHorizontally
213
-
214
- ){
215
- CurvedContainer()
216
- Box(
217
- modifier = Modifier
218
- .size(48.dp)
219
- .clip(CircleShape)
220
- .background(AppTheme.current.colors.primary),
221
- contentAlignment = Alignment.Center
222
- ) {
223
- 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)
224
386
  }
225
- Spacer(modifier = Modifier.height(4.dp))
226
- Text(
227
- text = data.label,
228
- style = Typography.labelXsMedium,
229
- color = Colors.black_01,
230
- textAlign = TextAlign.Center,
231
- modifier = Modifier
232
- .height(14.dp)
233
- .fillMaxWidth()
234
- .background(AppTheme.current.colors.primary, shape = RoundedCornerShape(size = Radius.XL))
235
- )
387
+ CenterActionLabel(data.label, data.labelContent, vertical = false, fixedFontScale = fixedFontScale)
236
388
  }
237
389
  }