@momo-kits/native-kits 0.168.1-beta.30-debug → 0.168.1-beta.31-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.
- package/CLAUDE.md +2 -1
- package/compose/build.gradle.kts +1 -1
- package/compose/compose.podspec +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +13 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +3 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +9 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +18 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +167 -313
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +71 -79
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +380 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +326 -93
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +2 -1
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
- package/gradle.properties +1 -1
- package/ios/Input/Input.swift +3 -1
- package/ios/Input/InputTextArea.swift +3 -1
- package/ios/Navigation/BottomTab/BottomTab.swift +33 -14
- package/ios/Navigation/BottomTab/BottomTabBar.swift +131 -254
- package/ios/Navigation/BottomTab/CurvedContainer.swift +47 -51
- package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +364 -0
- package/ios/Navigation/BottomTab/DuoTabBar.swift +292 -71
- package/ios/Navigation/StackScreen.swift +1 -3
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +59 -224
- package/package.json +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -106
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +0 -88
- package/local.properties +0 -9
|
@@ -1,383 +1,237 @@
|
|
|
1
1
|
package vn.momo.kits.navigation.bottomtab
|
|
2
2
|
|
|
3
|
-
import androidx.compose.runtime.getValue
|
|
4
|
-
import androidx.compose.animation.animateColorAsState
|
|
5
3
|
import androidx.compose.animation.core.Animatable
|
|
6
4
|
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
|
|
25
5
|
import androidx.compose.foundation.background
|
|
26
6
|
import androidx.compose.foundation.border
|
|
7
|
+
import androidx.compose.foundation.combinedClickable
|
|
8
|
+
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
9
|
+
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
|
27
10
|
import androidx.compose.foundation.layout.*
|
|
28
11
|
import androidx.compose.foundation.shape.CircleShape
|
|
29
12
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
30
13
|
import androidx.compose.runtime.Composable
|
|
31
|
-
import androidx.compose.runtime.
|
|
14
|
+
import androidx.compose.runtime.LaunchedEffect
|
|
15
|
+
import androidx.compose.runtime.getValue
|
|
16
|
+
import androidx.compose.runtime.mutableIntStateOf
|
|
32
17
|
import androidx.compose.runtime.remember
|
|
18
|
+
import androidx.compose.runtime.saveable.rememberSaveable
|
|
19
|
+
import androidx.compose.runtime.setValue
|
|
33
20
|
import androidx.compose.ui.Alignment
|
|
34
21
|
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
|
|
35
27
|
import androidx.compose.ui.text.style.TextAlign
|
|
36
28
|
import androidx.compose.ui.text.style.TextOverflow
|
|
29
|
+
import androidx.compose.ui.unit.Dp
|
|
30
|
+
import androidx.compose.ui.unit.IntOffset
|
|
37
31
|
import androidx.compose.ui.unit.dp
|
|
38
32
|
import vn.momo.kits.application.IsShowBaseLineDebug
|
|
39
|
-
import vn.momo.kits.application.LocalContext
|
|
40
|
-
import vn.momo.kits.application.MiniAppContext
|
|
41
33
|
import vn.momo.kits.components.*
|
|
42
34
|
import vn.momo.kits.const.*
|
|
43
|
-
import vn.momo.kits.layout.getScreenLayout
|
|
44
35
|
import vn.momo.kits.modifier.InternalApi
|
|
45
|
-
import vn.momo.kits.modifier.activeOpacityClickable
|
|
46
36
|
import vn.momo.kits.modifier.conditional
|
|
47
|
-
import vn.momo.kits.modifier.
|
|
37
|
+
import vn.momo.kits.modifier.activeOpacityClickable
|
|
38
|
+
import vn.momo.kits.layout.getScreenLayout
|
|
39
|
+
import vn.momo.kits.utils.horizontalSafeAreaPadding
|
|
48
40
|
|
|
49
41
|
@InternalApi
|
|
50
|
-
const val BOTTOM_TAB_BAR_HEIGHT =
|
|
42
|
+
const val BOTTOM_TAB_BAR_HEIGHT = 64
|
|
51
43
|
|
|
52
|
-
// Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
|
|
53
44
|
@Composable
|
|
54
45
|
internal fun BottomTabBar(
|
|
55
46
|
items: List<BottomTabItem>,
|
|
56
47
|
floatingButton: BottomTabFloatingButton? = null,
|
|
57
48
|
selectedIndex: Int,
|
|
58
49
|
onTabSelected: (Int) -> Unit,
|
|
50
|
+
onTabLongPress: ((Int) -> Unit)? = null,
|
|
59
51
|
) {
|
|
60
|
-
val layout = getScreenLayout()
|
|
61
|
-
Box(
|
|
62
|
-
modifier = Modifier
|
|
63
|
-
.fillMaxWidth()
|
|
64
|
-
.padding(bottom = tabBarBottomGap(layout.insetBottom)),
|
|
65
|
-
contentAlignment = Alignment.BottomCenter,
|
|
66
|
-
) {
|
|
67
|
-
HorizontalTabBar(
|
|
68
|
-
items = items,
|
|
69
|
-
floatingButton = floatingButton,
|
|
70
|
-
selectedIndex = selectedIndex,
|
|
71
|
-
onTabSelected = onTabSelected,
|
|
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
52
|
|
|
79
|
-
|
|
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) }
|
|
53
|
+
val layout = getScreenLayout()
|
|
92
54
|
val mid = items.size / 2
|
|
93
|
-
val density = LocalDensity.current
|
|
94
|
-
val itemBounds = remember(items.size) { mutableStateMapOf<Int, Pair<Float, Float>>() }
|
|
95
55
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
+
Box(
|
|
69
|
+
contentAlignment = Alignment.BottomCenter
|
|
70
|
+
) {
|
|
71
|
+
Row(
|
|
101
72
|
modifier = Modifier
|
|
102
|
-
.padding(top = if (cta != null) TabBarMetrics.ctaLift else 0.dp)
|
|
103
73
|
.fillMaxWidth()
|
|
104
|
-
.height(
|
|
105
|
-
.
|
|
106
|
-
.
|
|
107
|
-
|
|
108
|
-
) {
|
|
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
|
-
)
|
|
74
|
+
.height(BOTTOM_TAB_BAR_HEIGHT.dp)
|
|
75
|
+
.background(AppTheme.current.colors.background.surface)
|
|
76
|
+
.conditional(IsShowBaseLineDebug) {
|
|
77
|
+
border(1.dp, Colors.blue_03)
|
|
137
78
|
}
|
|
79
|
+
.horizontalSafeAreaPadding(),
|
|
80
|
+
horizontalArrangement = Arrangement.SpaceAround,
|
|
81
|
+
) {
|
|
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)
|
|
138
88
|
}
|
|
139
89
|
}
|
|
140
|
-
cta?.let { CenterAction(it, fixedFontScale, Modifier.align(Alignment.TopCenter)) }
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
90
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
+
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)
|
|
163
98
|
)
|
|
164
|
-
|
|
165
|
-
}
|
|
99
|
+
)
|
|
166
100
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
.
|
|
179
|
-
|
|
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)
|
|
180
114
|
}
|
|
181
|
-
|
|
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)
|
|
115
|
+
}
|
|
191
116
|
}
|
|
192
117
|
}
|
|
193
118
|
|
|
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.
|
|
196
119
|
@Composable
|
|
197
|
-
internal fun
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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(),
|
|
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) } },
|
|
230
135
|
)
|
|
231
136
|
}
|
|
232
|
-
if (fixedFontScale) FixedFontScale(label) else label()
|
|
233
137
|
}
|
|
234
138
|
}
|
|
235
139
|
|
|
236
|
-
// Like the system tab bar the label keeps its design size; Text grows it up to 5pt on the wide Duo displays.
|
|
237
140
|
@Composable
|
|
238
|
-
internal fun
|
|
239
|
-
|
|
240
|
-
val
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
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
|
-
}
|
|
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")
|
|
257
148
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
)
|
|
149
|
+
BoxWithConstraints(modifier = Modifier
|
|
150
|
+
.fillMaxSize()
|
|
151
|
+
.padding(horizontal = Spacing.XXS)
|
|
152
|
+
.conditional(IsShowBaseLineDebug) {
|
|
153
|
+
border(1.dp, Colors.blue_03)
|
|
283
154
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
+
}
|
|
303
188
|
Text(
|
|
304
|
-
text = label,
|
|
305
|
-
|
|
306
|
-
|
|
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,
|
|
307
192
|
maxLines = 1,
|
|
308
|
-
overflow = TextOverflow.Ellipsis
|
|
193
|
+
overflow = TextOverflow.Ellipsis
|
|
309
194
|
)
|
|
310
195
|
}
|
|
311
196
|
}
|
|
312
197
|
}
|
|
313
198
|
|
|
314
|
-
// Center action press: the button shrinks while held and its label turns active (label in a
|
|
315
|
-
// Background/primary pill, white text).
|
|
316
199
|
@Composable
|
|
317
|
-
internal fun
|
|
318
|
-
val interactionSource = remember { MutableInteractionSource() }
|
|
319
|
-
val pressed by interactionSource.collectIsPressedAsState()
|
|
320
|
-
return interactionSource to pressed
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
@Composable
|
|
324
|
-
internal fun Modifier.centerActionButton(size: androidx.compose.ui.unit.Dp, pressed: Boolean): Modifier {
|
|
325
|
-
val scale by animateFloatAsState(
|
|
326
|
-
if (pressed) TabBarMotion.CTA_PRESSED_SCALE else 1f,
|
|
327
|
-
tween(TabBarMotion.CTA_PRESS_MILLIS, easing = inOutQuad),
|
|
328
|
-
label = "CenterActionPress",
|
|
329
|
-
)
|
|
330
|
-
return graphicsLayer {
|
|
331
|
-
scaleX = scale
|
|
332
|
-
scaleY = scale
|
|
333
|
-
}
|
|
334
|
-
.size(size)
|
|
335
|
-
.then(CtaShadows.fold(Modifier as Modifier) { acc, shadow -> acc.spreadShadow(CircleShape, shadow) })
|
|
336
|
-
.background(AppTheme.current.colors.primary, CircleShape)
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
@Composable
|
|
340
|
-
internal fun CenterActionLabel(label: String, pressed: Boolean, vertical: Boolean, fixedFontScale: Boolean) {
|
|
341
|
-
val colors = AppTheme.current.colors
|
|
342
|
-
val text = @Composable {
|
|
343
|
-
Text(
|
|
344
|
-
text = label,
|
|
345
|
-
style = if (vertical) Typography.labelXsMedium else Typography.labelSMedium,
|
|
346
|
-
color = if (pressed) Colors.black_01 else colors.text.secondary,
|
|
347
|
-
textAlign = TextAlign.Center,
|
|
348
|
-
maxLines = 1,
|
|
349
|
-
overflow = TextOverflow.Ellipsis,
|
|
350
|
-
)
|
|
351
|
-
}
|
|
352
|
-
Box(
|
|
353
|
-
modifier = Modifier
|
|
354
|
-
.then(if (vertical) Modifier else Modifier.heightIn(min = TabBarMetrics.ctaLabelHeight))
|
|
355
|
-
.then(if (pressed) Modifier.background(colors.primary, RoundedCornerShape(Radius.XL)) else Modifier)
|
|
356
|
-
.padding(horizontal = if (vertical) Spacing.XS else Spacing.XXS),
|
|
357
|
-
contentAlignment = Alignment.Center,
|
|
358
|
-
) {
|
|
359
|
-
if (fixedFontScale) FixedFontScale(text) else text()
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// Center action (.Nav/CTA): button rising out of the notch, label under it.
|
|
364
|
-
@Composable
|
|
365
|
-
private fun CenterAction(data: BottomTabFloatingButton, fixedFontScale: Boolean, modifier: Modifier) {
|
|
366
|
-
val (interactionSource, pressed) = rememberCenterActionPress()
|
|
200
|
+
internal fun FloatingButton(data: BottomTabFloatingButton, width: Dp) {
|
|
367
201
|
Column(
|
|
368
|
-
modifier =
|
|
369
|
-
.width(
|
|
202
|
+
modifier = Modifier
|
|
203
|
+
.width(width)
|
|
204
|
+
.padding(horizontal = Spacing.XXS, vertical = Spacing.S)
|
|
370
205
|
.conditional(IsShowBaseLineDebug) {
|
|
371
206
|
border(1.dp, Colors.blue_03)
|
|
372
207
|
}
|
|
373
|
-
.
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
verticalArrangement = Arrangement.
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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)
|
|
380
224
|
}
|
|
381
|
-
|
|
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
|
+
)
|
|
382
236
|
}
|
|
383
237
|
}
|