@momo-kits/native-kits 0.168.1-sizescale.1-debug → 0.169.1-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 +4 -3
- package/PUBLISH_GUIDE.md +29 -658
- package/compose/build.gradle.kts +2 -2
- package/compose/compose.podspec +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +4 -5
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +2 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +21 -15
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +76 -83
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +3 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +11 -14
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +3 -4
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +8 -13
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +57 -163
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +17 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +5 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +34 -23
- 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/DuoTabBar.kt +87 -261
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
- 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 +2 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +1 -2
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +3 -2
- 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 +9 -3
- package/gradle.properties +1 -3
- package/ios/Input/Input.swift +3 -1
- package/ios/Input/InputTextArea.swift +3 -1
- package/ios/Layout/ModalLayout.swift +152 -0
- package/ios/Layout/ScreenLayout.swift +28 -24
- package/ios/Navigation/BottomSheet.swift +29 -156
- 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/DuoTabBar.swift +62 -195
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/ModalScreen.swift +18 -7
- package/ios/Navigation/StackScreen.swift +3 -1
- package/ios/Popup/PopupDisplay.swift +4 -2
- package/ios/Popup/PopupInput.swift +4 -2
- package/ios/Popup/PopupLayout.swift +10 -9
- package/ios/Popup/PopupNotify.swift +32 -25
- package/ios/Typography/Text.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/local.properties +8 -0
- package/package.json +1 -1
- package/publish.sh +170 -513
- package/compose/build.gradle.kts.backup +0 -198
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitSizeScale.kt +0 -45
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
package vn.momo.kits.navigation.bottomtab
|
|
2
2
|
|
|
3
|
+
import androidx.compose.runtime.getValue
|
|
4
|
+
import androidx.compose.runtime.setValue
|
|
3
5
|
import androidx.compose.animation.core.Animatable
|
|
4
6
|
import androidx.compose.animation.core.AnimationVector1D
|
|
7
|
+
import androidx.compose.animation.core.CubicBezierEasing
|
|
5
8
|
import androidx.compose.animation.core.Easing
|
|
6
9
|
import androidx.compose.animation.core.tween
|
|
7
10
|
import androidx.compose.foundation.background
|
|
@@ -10,14 +13,12 @@ import androidx.compose.runtime.Composable
|
|
|
10
13
|
import androidx.compose.runtime.CompositionLocalProvider
|
|
11
14
|
import androidx.compose.runtime.DisposableEffect
|
|
12
15
|
import androidx.compose.runtime.LaunchedEffect
|
|
13
|
-
import androidx.compose.runtime.getValue
|
|
14
16
|
import androidx.compose.runtime.key
|
|
15
17
|
import androidx.compose.runtime.mutableIntStateOf
|
|
16
18
|
import androidx.compose.runtime.mutableStateOf
|
|
17
19
|
import androidx.compose.runtime.remember
|
|
18
20
|
import androidx.compose.runtime.saveable.rememberSaveable
|
|
19
21
|
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
|
|
20
|
-
import androidx.compose.runtime.setValue
|
|
21
22
|
import androidx.compose.runtime.staticCompositionLocalOf
|
|
22
23
|
import androidx.compose.ui.Alignment
|
|
23
24
|
import androidx.compose.ui.Modifier
|
|
@@ -25,9 +26,8 @@ import androidx.compose.ui.graphics.graphicsLayer
|
|
|
25
26
|
import androidx.compose.ui.layout.layout
|
|
26
27
|
import androidx.compose.ui.unit.dp
|
|
27
28
|
import androidx.compose.ui.zIndex
|
|
28
|
-
import
|
|
29
|
+
import kotlin.math.abs
|
|
29
30
|
import vn.momo.kits.const.AppTheme
|
|
30
|
-
import vn.momo.kits.const.Spacing
|
|
31
31
|
import vn.momo.kits.navigation.KeyboardOptions
|
|
32
32
|
import vn.momo.kits.navigation.LocalMaxApi
|
|
33
33
|
import vn.momo.kits.navigation.LocalNavigation
|
|
@@ -40,8 +40,12 @@ import vn.momo.kits.platform.reportFloatingArrowBack
|
|
|
40
40
|
import vn.momo.kits.layout.getScreenLayout
|
|
41
41
|
import kotlinx.coroutines.launch
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
internal val inOutQuad = Easing { t -> if (t < 0.5f) 2 * t * t else 1 - 2 * (1 - t) * (1 - t) }
|
|
44
|
+
// the tab screens slide in index order over 280ms, CSS `ease`
|
|
45
|
+
private val tabSwitchSpec = tween<Float>(durationMillis = 280, easing = CubicBezierEasing(0.25f, 0.1f, 0.25f, 1f))
|
|
46
|
+
|
|
47
|
+
// -1 for tabs before the selected one, 1 for tabs after it: they wait a full width off screen on their side
|
|
48
|
+
private fun tabPosition(index: Int, selected: Int) = (index - selected).coerceIn(-1, 1).toFloat()
|
|
45
49
|
|
|
46
50
|
internal val LocalBottomTabFocused = staticCompositionLocalOf { true }
|
|
47
51
|
|
|
@@ -105,14 +109,21 @@ fun BottomTab(
|
|
|
105
109
|
var lastFocusedIndex by rememberSaveable { mutableStateOf<Int?>(null) }
|
|
106
110
|
val tabProgress = remember { mutableMapOf<Int, Animatable<Float, AnimationVector1D>>() }
|
|
107
111
|
fun progressOf(index: Int) = tabProgress.getOrPut(index) {
|
|
108
|
-
Animatable(
|
|
112
|
+
Animatable(tabPosition(index, lastFocusedIndex ?: index))
|
|
109
113
|
}
|
|
110
114
|
LaunchedEffect(selectedIndex) {
|
|
115
|
+
val previousIndex = lastFocusedIndex
|
|
111
116
|
lastFocusedIndex = selectedIndex
|
|
112
117
|
tabProgress.forEach { (index, progress) ->
|
|
113
|
-
|
|
118
|
+
val target = tabPosition(index, selectedIndex)
|
|
119
|
+
launch {
|
|
120
|
+
if (index == selectedIndex || index == previousIndex) {
|
|
121
|
+
progress.animateTo(target, tabSwitchSpec)
|
|
122
|
+
} else {
|
|
123
|
+
progress.snapTo(target)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
114
126
|
}
|
|
115
|
-
progressOf(selectedIndex).animateTo(1f, tabTimingSpec)
|
|
116
127
|
}
|
|
117
128
|
|
|
118
129
|
DisposableEffect(isFirstTab) {
|
|
@@ -147,21 +158,20 @@ fun BottomTab(
|
|
|
147
158
|
CompositionLocalProvider(
|
|
148
159
|
LocalDuoRailReserve provides railReserve,
|
|
149
160
|
LocalDuoBarCompression provides compression,
|
|
161
|
+
LocalTabBarHasCenterAction provides hasCenterAction(floatingButton, items.size),
|
|
150
162
|
) {
|
|
151
163
|
loadedTabs.forEach { index ->
|
|
152
164
|
val item = items.getOrNull(index) ?: return@forEach
|
|
153
165
|
val focused = index == selectedIndex
|
|
154
166
|
val progress = progressOf(index)
|
|
167
|
+
// the leaving tab stays drawn until it has slid off screen
|
|
168
|
+
val visible = focused || abs(progress.value) < 1f
|
|
155
169
|
key(index) {
|
|
156
170
|
Box(
|
|
157
171
|
Modifier
|
|
158
172
|
.fillMaxSize()
|
|
159
173
|
.zIndex(if (focused) 0f else -1f)
|
|
160
|
-
.then(if (
|
|
161
|
-
alpha = 0.3f + 0.7f * progress.value
|
|
162
|
-
scaleX = 0.97f + 0.03f * progress.value
|
|
163
|
-
scaleY = scaleX
|
|
164
|
-
} else Hidden)
|
|
174
|
+
.then(if (visible) Modifier.graphicsLayer { translationX = progress.value * size.width } else Hidden)
|
|
165
175
|
) {
|
|
166
176
|
CompositionLocalProvider(LocalBottomTabFocused provides focused) {
|
|
167
177
|
tabStateHolder.SaveableStateProvider(index) {
|
|
@@ -197,15 +207,12 @@ fun BottomTab(
|
|
|
197
207
|
compression = compression,
|
|
198
208
|
)
|
|
199
209
|
} else {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
)
|
|
207
|
-
Spacer(modifier = Modifier.fillMaxWidth().height(AppNavigationBar.current + Spacing.S).background(AppTheme.current.colors.background.surface))
|
|
208
|
-
}
|
|
210
|
+
BottomTabBar(
|
|
211
|
+
items = items,
|
|
212
|
+
floatingButton = floatingButton,
|
|
213
|
+
selectedIndex = selectedIndex,
|
|
214
|
+
onTabSelected = onTabSelected,
|
|
215
|
+
)
|
|
209
216
|
}
|
|
210
217
|
}
|
|
211
218
|
}
|
|
@@ -225,4 +232,8 @@ data class BottomTabFloatingButton(
|
|
|
225
232
|
val icon: String,
|
|
226
233
|
val label: String,
|
|
227
234
|
val onPress: () -> Unit,
|
|
235
|
+
// replaces the icon inside the 48 button, e.g. the button part of a Lottie; centered, unclipped
|
|
236
|
+
val iconContent: (@Composable () -> Unit)? = null,
|
|
237
|
+
// drawn over the label text, which stays, e.g. the label part of a Lottie; centered, unclipped
|
|
238
|
+
val labelContent: (@Composable () -> Unit)? = null,
|
|
228
239
|
)
|
|
@@ -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
|
}
|