@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.
- package/CLAUDE.md +15 -10
- package/README.md +2 -10
- package/build.gradle.kts +1 -3
- package/compose/build.gradle.kts +20 -19
- package/compose/build.gradle.kts.backup +19 -18
- package/compose/compose.podspec +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +4 -3
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
- 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 +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -14
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +14 -23
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +21 -15
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +84 -82
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +2 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +18 -14
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +20 -13
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +117 -62
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +22 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +16 -26
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +54 -36
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +1 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +35 -29
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +321 -149
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +2 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +89 -198
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +3 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +30 -44
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +2 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +32 -40
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +12 -3
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +3 -1
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +2 -6
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +12 -10
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +60 -10
- package/gradle/libs.versions.toml +4 -11
- package/gradle/wrapper/gradle-wrapper.properties +1 -3
- package/gradle.properties +3 -3
- package/ios/Application/ApplicationEnvironment.swift +7 -6
- package/ios/Application/DesignSystemKits.swift +163 -0
- package/ios/Application/DesignSystemKitsPayload.swift +68 -0
- package/ios/Badge/BadgeRibbon.swift +8 -1
- package/ios/Extensions/Color++.swift +2 -4
- package/ios/Input/Input.swift +16 -4
- package/ios/Input/InputPhoneNumber.swift +1 -3
- package/ios/Input/InputSearch.swift +1 -2
- package/ios/Input/InputTextArea.swift +8 -4
- package/ios/InputMoney/InputMoney.swift +6 -7
- package/ios/Layout/ModalLayout.swift +152 -0
- package/ios/Layout/ScreenLayout.swift +77 -18
- package/ios/Navigation/BottomSheet.swift +56 -53
- package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
- package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
- package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
- package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
- package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
- package/ios/Navigation/Component/HeaderBackground.swift +22 -1
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/Component/SnackBar.swift +4 -0
- package/ios/Navigation/ModalScreen.swift +20 -5
- package/ios/Navigation/StackScreen.swift +6 -8
- package/ios/Popup/PopupDisplay.swift +6 -4
- package/ios/Popup/PopupInput.swift +6 -4
- package/ios/Popup/PopupLayout.swift +17 -11
- package/ios/Popup/PopupNotify.swift +32 -25
- package/ios/Stepper/Stepper.swift +1 -2
- package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
- package/ios/Typography/FontScale.swift +29 -15
- package/ios/Typography/Text.swift +88 -14
- package/ios/Typography/Typography.swift +2 -2
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
- package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
- package/package.json +1 -1
- package/publish.sh +2 -33
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitDesignSystem.kt +0 -18
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +0 -37
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +0 -41
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +0 -44
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +0 -62
- package/ios/Typography/FontScaleStore.swift +0 -58
- 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.
|
|
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.
|
|
33
|
-
import vn.momo.kits.
|
|
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 =
|
|
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
|
-
|
|
62
|
+
modifier = Modifier
|
|
63
|
+
.fillMaxWidth()
|
|
64
|
+
.padding(bottom = tabBarBottomGap(layout.insetBottom)),
|
|
65
|
+
contentAlignment = Alignment.BottomCenter,
|
|
63
66
|
) {
|
|
64
|
-
|
|
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(
|
|
68
|
-
.
|
|
69
|
-
.
|
|
70
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
){
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
133
|
-
|
|
134
|
-
val
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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 =
|
|
170
|
-
|
|
171
|
-
|
|
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
|
|
181
|
-
|
|
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
|
-
.
|
|
184
|
-
.padding(horizontal = Spacing.
|
|
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
|
-
.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
verticalArrangement = Arrangement.
|
|
192
|
-
|
|
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
|
-
|
|
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
|
}
|