@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,86 +1,94 @@
|
|
|
1
1
|
package vn.momo.kits.navigation.bottomtab
|
|
2
2
|
|
|
3
|
-
import androidx.compose.foundation.Canvas
|
|
4
|
-
import androidx.compose.foundation.layout.Box
|
|
5
|
-
import androidx.compose.foundation.layout.height
|
|
6
|
-
import androidx.compose.foundation.layout.offset
|
|
7
|
-
import androidx.compose.foundation.layout.width
|
|
8
|
-
import androidx.compose.runtime.Composable
|
|
9
|
-
import androidx.compose.ui.Alignment
|
|
10
3
|
import androidx.compose.ui.Modifier
|
|
4
|
+
import androidx.compose.ui.draw.dropShadow
|
|
5
|
+
import androidx.compose.ui.geometry.Rect
|
|
6
|
+
import androidx.compose.ui.geometry.RoundRect
|
|
7
|
+
import androidx.compose.ui.geometry.Size
|
|
8
|
+
import androidx.compose.ui.geometry.CornerRadius
|
|
9
|
+
import androidx.compose.ui.geometry.Offset
|
|
10
|
+
import androidx.compose.ui.graphics.addOutline
|
|
11
|
+
import androidx.compose.ui.graphics.Color
|
|
12
|
+
import androidx.compose.ui.graphics.Outline
|
|
11
13
|
import androidx.compose.ui.graphics.Path
|
|
12
|
-
import androidx.compose.ui.
|
|
14
|
+
import androidx.compose.ui.graphics.Shape
|
|
15
|
+
import androidx.compose.ui.graphics.shadow.Shadow
|
|
16
|
+
import androidx.compose.ui.unit.Density
|
|
13
17
|
import androidx.compose.ui.unit.Dp
|
|
14
|
-
import androidx.compose.ui.unit.
|
|
18
|
+
import androidx.compose.ui.unit.DpOffset
|
|
19
|
+
import androidx.compose.ui.unit.LayoutDirection
|
|
15
20
|
import androidx.compose.ui.unit.dp
|
|
16
|
-
import androidx.compose.
|
|
21
|
+
import androidx.compose.foundation.background
|
|
22
|
+
import androidx.compose.runtime.Composable
|
|
17
23
|
import vn.momo.kits.const.AppTheme
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
internal
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
val circleSizePx = with(density) { circleSize.toPx() }
|
|
32
|
-
val tabBarItemIconSizePx = with(density) { tabBarItemIconSize.toPx() }
|
|
33
|
-
val circleOverSizePx = with(density) { circleOverSize.toPx() }
|
|
34
|
-
|
|
35
|
-
val circlePositionTop = circleSizePx - tabBarItemIconSizePx - 10f
|
|
36
|
-
val circleOverTop = circlePositionTop + circleOverSizePx
|
|
37
|
-
val circleR = circleSizePx / 2
|
|
38
|
-
val circleOverR = circleR + circleOverSizePx
|
|
39
|
-
|
|
40
|
-
val centerX = widthPx / 2
|
|
41
|
-
|
|
42
|
-
val curvedPath = getPath(
|
|
43
|
-
circleOverTop = circleOverTop,
|
|
44
|
-
centerX = centerX,
|
|
45
|
-
circleOverR = circleOverR,
|
|
46
|
-
widthPx = widthPx
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
Box(
|
|
50
|
-
contentAlignment = Alignment.BottomCenter
|
|
51
|
-
){
|
|
52
|
-
Canvas(
|
|
53
|
-
modifier = Modifier
|
|
54
|
-
.width(width)
|
|
55
|
-
.height(height)
|
|
56
|
-
.offset{ IntOffset(x = 0, y = 24) }
|
|
57
|
-
.zIndex(-1f)
|
|
58
|
-
) {
|
|
59
|
-
drawPath(path = curvedPath, color = theme.colors.background.surface)
|
|
25
|
+
// Rounded container, with the notch dipped into the top edge around `notchCenterX` (from the left).
|
|
26
|
+
internal class NotchedBarShape(
|
|
27
|
+
private val radius: Dp,
|
|
28
|
+
private val notchCenterX: Dp? = null,
|
|
29
|
+
) : Shape {
|
|
30
|
+
override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
|
|
31
|
+
val r = minOf(with(density) { radius.toPx() }, size.height / 2, size.width / 2)
|
|
32
|
+
val path = Path()
|
|
33
|
+
if (notchCenterX == null) {
|
|
34
|
+
path.addRoundRect(RoundRect(Rect(0f, 0f, size.width, size.height), CornerRadius(r)))
|
|
35
|
+
return Outline.Generic(path)
|
|
60
36
|
}
|
|
37
|
+
val cx = with(density) { notchCenterX.toPx() }
|
|
38
|
+
val unit = density.density
|
|
39
|
+
path.apply {
|
|
40
|
+
moveTo(r, 0f)
|
|
41
|
+
lineTo(cx - NOTCH_HALF_WIDTH * unit, 0f)
|
|
42
|
+
NOTCH_CURVES.forEach { (c1, c2, end) ->
|
|
43
|
+
cubicTo(
|
|
44
|
+
cx + c1.first * unit, c1.second * unit,
|
|
45
|
+
cx + c2.first * unit, c2.second * unit,
|
|
46
|
+
cx + end.first * unit, end.second * unit,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
lineTo(size.width - r, 0f)
|
|
50
|
+
arcTo(Rect(size.width - 2 * r, 0f, size.width, 2 * r), -90f, 90f, false)
|
|
51
|
+
lineTo(size.width, size.height - r)
|
|
52
|
+
arcTo(Rect(size.width - 2 * r, size.height - 2 * r, size.width, size.height), 0f, 90f, false)
|
|
53
|
+
lineTo(r, size.height)
|
|
54
|
+
arcTo(Rect(0f, size.height - 2 * r, 2 * r, size.height), 90f, 90f, false)
|
|
55
|
+
lineTo(0f, r)
|
|
56
|
+
arcTo(Rect(0f, 0f, 2 * r, 2 * r), 180f, 90f, false)
|
|
57
|
+
close()
|
|
58
|
+
}
|
|
59
|
+
return Outline.Generic(path)
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
// The shape shrunk by `inset` on every side. A shadow cast from it with no spread is a shadow of the
|
|
64
|
+
// shape with spread -inset; dropShadow's own negative spread clips the blur of path outlines.
|
|
65
|
+
internal class InsetShape(private val shape: Shape, private val inset: Dp) : Shape {
|
|
66
|
+
override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline {
|
|
67
|
+
val insetPx = with(density) { inset.toPx() }
|
|
68
|
+
val inner = Size((size.width - 2 * insetPx).coerceAtLeast(0f), (size.height - 2 * insetPx).coerceAtLeast(0f))
|
|
69
|
+
val path = Path().apply {
|
|
70
|
+
addOutline(shape.createOutline(inner, layoutDirection, density))
|
|
71
|
+
translate(Offset(insetPx, insetPx))
|
|
72
|
+
}
|
|
73
|
+
return Outline.Generic(path)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
68
76
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
77
|
+
// Shadow with a negative spread, cast from the shrunk shape.
|
|
78
|
+
internal fun Modifier.spreadShadow(shape: Shape, shadow: Shadow): Modifier =
|
|
79
|
+
if (shadow.spread < 0.dp) dropShadow(
|
|
80
|
+
InsetShape(shape, -shadow.spread),
|
|
81
|
+
Shadow(radius = shadow.radius, color = shadow.color, offset = shadow.offset, alpha = shadow.alpha),
|
|
82
|
+
)
|
|
83
|
+
else dropShadow(shape, shadow)
|
|
74
84
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
// Navigation bar container: surface fill with the floating shadow following the shape (Figma
|
|
86
|
+
// Shadow/floating: 12% blur 24, 4% y12 blur 32 spread -16).
|
|
87
|
+
@Composable
|
|
88
|
+
internal fun Modifier.tabBarContainer(shape: Shape): Modifier =
|
|
89
|
+
dropShadow(shape, Shadow(radius = 24.dp, color = Color.Black, alpha = 0.12f))
|
|
90
|
+
.spreadShadow(
|
|
91
|
+
shape,
|
|
92
|
+
Shadow(radius = 32.dp, spread = (-16).dp, color = Color.Black, alpha = 0.04f, offset = DpOffset(0.dp, 12.dp)),
|
|
79
93
|
)
|
|
80
|
-
|
|
81
|
-
lineTo(widthPx, circleOverTop)
|
|
82
|
-
lineTo(widthPx, 60f)
|
|
83
|
-
lineTo(0f, 60f)
|
|
84
|
-
close()
|
|
85
|
-
}
|
|
86
|
-
}
|
|
94
|
+
.background(AppTheme.current.colors.background.surface, shape)
|
|
@@ -1,109 +1,68 @@
|
|
|
1
1
|
package vn.momo.kits.navigation.bottomtab
|
|
2
2
|
|
|
3
|
-
import androidx.compose.animation.core.Spring
|
|
4
|
-
import androidx.compose.animation.core.animateDpAsState
|
|
5
|
-
import androidx.compose.animation.core.animateFloatAsState
|
|
6
|
-
import androidx.compose.animation.core.spring
|
|
7
|
-
import androidx.compose.foundation.background
|
|
8
3
|
import androidx.compose.foundation.clickable
|
|
9
|
-
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
10
|
-
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
|
11
|
-
import androidx.compose.foundation.border
|
|
12
4
|
import androidx.compose.foundation.layout.Arrangement
|
|
13
5
|
import androidx.compose.foundation.layout.Box
|
|
14
6
|
import androidx.compose.foundation.layout.BoxScope
|
|
15
|
-
import androidx.compose.foundation.layout.BoxWithConstraints
|
|
16
7
|
import androidx.compose.foundation.layout.Column
|
|
17
|
-
import androidx.compose.foundation.layout.Row
|
|
18
|
-
import androidx.compose.foundation.layout.RowScope
|
|
19
|
-
import androidx.compose.foundation.layout.absolutePadding
|
|
20
|
-
import androidx.compose.foundation.layout.fillMaxHeight
|
|
21
|
-
import androidx.compose.foundation.layout.fillMaxSize
|
|
22
|
-
import androidx.compose.foundation.layout.fillMaxWidth
|
|
23
8
|
import androidx.compose.foundation.layout.height
|
|
24
9
|
import androidx.compose.foundation.layout.offset
|
|
25
10
|
import androidx.compose.foundation.layout.padding
|
|
26
11
|
import androidx.compose.foundation.layout.size
|
|
27
12
|
import androidx.compose.foundation.layout.width
|
|
13
|
+
import androidx.compose.foundation.layout.absolutePadding
|
|
14
|
+
import androidx.compose.foundation.layout.wrapContentWidth
|
|
28
15
|
import androidx.compose.foundation.shape.CircleShape
|
|
29
16
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
30
17
|
import androidx.compose.runtime.Composable
|
|
31
|
-
import androidx.compose.runtime.CompositionLocalProvider
|
|
32
|
-
import androidx.compose.runtime.LaunchedEffect
|
|
33
|
-
import androidx.compose.runtime.MutableState
|
|
34
18
|
import androidx.compose.runtime.compositionLocalOf
|
|
35
|
-
import androidx.compose.runtime.getValue
|
|
36
|
-
import androidx.compose.runtime.mutableStateOf
|
|
37
|
-
import androidx.compose.runtime.remember
|
|
38
19
|
import androidx.compose.ui.AbsoluteAlignment
|
|
39
20
|
import androidx.compose.ui.Alignment
|
|
40
21
|
import androidx.compose.ui.Modifier
|
|
41
|
-
import androidx.compose.ui.draw.clip
|
|
42
|
-
import androidx.compose.ui.draw.shadow
|
|
43
|
-
import androidx.compose.ui.graphics.graphicsLayer
|
|
44
22
|
import androidx.compose.ui.graphics.Color
|
|
45
|
-
import androidx.compose.ui.
|
|
23
|
+
import androidx.compose.ui.platform.LocalDensity
|
|
46
24
|
import androidx.compose.ui.semantics.Role
|
|
47
|
-
import androidx.compose.ui.
|
|
25
|
+
import androidx.compose.ui.semantics.contentDescription
|
|
26
|
+
import androidx.compose.ui.semantics.role
|
|
27
|
+
import androidx.compose.ui.semantics.selected
|
|
28
|
+
import androidx.compose.ui.semantics.semantics
|
|
29
|
+
import vn.momo.kits.modifier.activeOpacityClickable
|
|
48
30
|
import androidx.compose.ui.unit.Dp
|
|
49
31
|
import androidx.compose.ui.unit.dp
|
|
50
|
-
import vn.momo.kits.application.LocalContext
|
|
51
|
-
import vn.momo.kits.application.MiniAppContext
|
|
52
|
-
import vn.momo.kits.components.Badge
|
|
53
|
-
import vn.momo.kits.components.BadgeDot
|
|
54
|
-
import vn.momo.kits.components.DotSize
|
|
55
32
|
import vn.momo.kits.components.Icon
|
|
56
|
-
import vn.momo.kits.components.Text
|
|
57
33
|
import vn.momo.kits.const.AppTheme
|
|
34
|
+
import vn.momo.kits.const.Colors
|
|
35
|
+
import vn.momo.kits.const.Radius
|
|
58
36
|
import vn.momo.kits.const.Spacing
|
|
59
|
-
import vn.momo.kits.const.Typography
|
|
60
37
|
import vn.momo.kits.layout.DuoMetrics
|
|
61
38
|
import vn.momo.kits.layout.ScreenLayout
|
|
62
39
|
import vn.momo.kits.layout.SideBarEdge
|
|
63
40
|
import vn.momo.kits.modifier.noFeedbackClickable
|
|
64
41
|
import vn.momo.kits.modifier.setAutomationId
|
|
65
42
|
|
|
66
|
-
// Figma
|
|
67
|
-
private val
|
|
68
|
-
private val ICON_SIZE = 28.dp
|
|
69
|
-
private val QR_ICON_SIZE = 24.dp
|
|
70
|
-
private val RAIL_PADDING = 6.dp
|
|
71
|
-
private val RAIL_GAP = Spacing.XXS
|
|
72
|
-
// selection bubble overflows the 48 rail cell by 5 above and below
|
|
73
|
-
private val RAIL_BUBBLE_WIDTH = 44.dp
|
|
74
|
-
private val RAIL_BUBBLE_HEIGHT = 58.dp
|
|
75
|
-
private val FLOATING_HEIGHT = DuoMetrics.floatingTabBarHeight
|
|
76
|
-
private val FLOATING_PADDING = Spacing.XS
|
|
77
|
-
// the system bar sizes its pill to the tabs instead of stretching it across the display
|
|
78
|
-
private val FLOATING_ITEM_WIDTH = 80.dp
|
|
79
|
-
// while pressed the selection bubble grows into a lens past the pill's edges
|
|
80
|
-
private const val LENS_SCALE_X = 1.2f
|
|
81
|
-
private const val LENS_SCALE_Y = 1.3f
|
|
82
|
-
// Figma Home-2026 tab bar "Selection": brand pink at 8%
|
|
83
|
-
private const val SELECTION_TINT_ALPHA = 0x14 / 255f
|
|
84
|
-
// RN reanimated spring { damping: 18, stiffness: 220, mass: 0.8 }
|
|
85
|
-
private val BUBBLE_SPRING = spring<Dp>(dampingRatio = 0.68f, stiffness = 275f, visibilityThreshold = Dp(0.5f))
|
|
86
|
-
private val LENS_SPRING = spring<Float>(dampingRatio = 0.68f, stiffness = 275f)
|
|
43
|
+
// Figma "Specs Navigation" (DS-984) Vertical type, mirrored from RN DuoTabBar.tsx.
|
|
44
|
+
private val COMPACT_SIZE = DuoMetrics.controlSize
|
|
87
45
|
|
|
88
46
|
// Space from the window bottom the rail stack and its gap take, so the header side bar stays above it.
|
|
89
47
|
internal val LocalDuoRailReserve = compositionLocalOf { 0.dp }
|
|
90
48
|
|
|
91
|
-
// Rail plus the
|
|
49
|
+
// Rail container plus the center action under it; compressed, the rail is a single button.
|
|
92
50
|
internal fun duoRailHeight(itemCount: Int, hasQr: Boolean, compressed: Boolean = false): Dp {
|
|
93
|
-
val rail = if (compressed)
|
|
94
|
-
else
|
|
95
|
-
return rail + if (hasQr)
|
|
51
|
+
val rail = if (compressed) COMPACT_SIZE
|
|
52
|
+
else TabBarMetrics.railItemHeight * itemCount + TabBarMetrics.railPaddingBottom
|
|
53
|
+
return rail + if (hasQr) TabBarMetrics.railCtaGap + TabBarMetrics.railCtaHeight else 0.dp
|
|
96
54
|
}
|
|
97
55
|
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
56
|
+
// Space tab content leaves under the floating horizontal bar (phone and unfolded Duo), the rising center
|
|
57
|
+
// action included; 0 when the Duo rail sits in the side strip.
|
|
58
|
+
internal fun duoFloatingTabBarInset(layout: ScreenLayout, hasCenterAction: Boolean = false): Dp =
|
|
59
|
+
if (layout.isIPhoneDuo && layout.sideBar != null) 0.dp
|
|
60
|
+
else TabBarMetrics.height + tabBarBottomGap(layout.insetBottom) + if (hasCenterAction) TabBarMetrics.ctaLift else 0.dp
|
|
101
61
|
|
|
102
|
-
//
|
|
103
|
-
internal
|
|
104
|
-
if (layout.isIPhoneDuo && layout.sideBar == null) FLOATING_HEIGHT + floatingTabBarBottom(layout.insetBottom) else 0.dp
|
|
62
|
+
// Whether the tabs' bar shows the center action, whose button rises ctaLift above the container.
|
|
63
|
+
internal val LocalTabBarHasCenterAction = compositionLocalOf { false }
|
|
105
64
|
|
|
106
|
-
// iPhone Duo tab bar: rail in the side bar, or
|
|
65
|
+
// iPhone Duo tab bar: rail in the side bar, or the horizontal bar when unfolded portrait.
|
|
107
66
|
@Composable
|
|
108
67
|
internal fun BoxScope.DuoTabBar(
|
|
109
68
|
layout: ScreenLayout,
|
|
@@ -116,13 +75,23 @@ internal fun BoxScope.DuoTabBar(
|
|
|
116
75
|
if (layout.sideBar != null) {
|
|
117
76
|
DuoRailTabBar(layout, items, floatingButton, selectedIndex, onTabSelected, compression)
|
|
118
77
|
} else {
|
|
119
|
-
|
|
78
|
+
HorizontalTabBar(
|
|
79
|
+
items = items,
|
|
80
|
+
floatingButton = floatingButton,
|
|
81
|
+
selectedIndex = selectedIndex,
|
|
82
|
+
onTabSelected = onTabSelected,
|
|
83
|
+
fixedFontScale = true,
|
|
84
|
+
modifier = Modifier
|
|
85
|
+
.align(Alignment.BottomCenter)
|
|
86
|
+
.padding(bottom = tabBarBottomGap(layout.insetBottom))
|
|
87
|
+
.width(horizontalBarWidth(layout.width, layout.height, layout.insetLeft, layout.insetRight)),
|
|
88
|
+
)
|
|
120
89
|
}
|
|
121
90
|
}
|
|
122
91
|
|
|
123
|
-
// Vertical bar anchored to the bottom of the side bar,
|
|
124
|
-
//
|
|
125
|
-
//
|
|
92
|
+
// Vertical bar anchored to the bottom of the side bar, center action below it. When the side bar is
|
|
93
|
+
// short it can shrink to one button showing the current tab (HIG "Tab bar compressed"); tapping it
|
|
94
|
+
// expands the rail and compresses the toolbar.
|
|
126
95
|
@Composable
|
|
127
96
|
private fun BoxScope.DuoRailTabBar(
|
|
128
97
|
layout: ScreenLayout,
|
|
@@ -135,26 +104,31 @@ private fun BoxScope.DuoRailTabBar(
|
|
|
135
104
|
val sideBar = layout.sideBar ?: return
|
|
136
105
|
val isRight = sideBar.edge == SideBarEdge.RIGHT
|
|
137
106
|
|
|
107
|
+
// the rail lines up with the header buttons in the side bar: centered on a 48 lane kept Spacing.M
|
|
108
|
+
// from the strip's inner edge; the wider rail and center action overflow the lane evenly
|
|
138
109
|
Column(
|
|
139
110
|
modifier = Modifier
|
|
140
111
|
.align(if (isRight) AbsoluteAlignment.BottomRight else AbsoluteAlignment.BottomLeft)
|
|
141
112
|
.width(sideBar.width)
|
|
142
113
|
.padding(bottom = sideBar.bottom)
|
|
143
|
-
.absolutePadding(left = if (isRight) Spacing.M else 0.dp, right = if (isRight) 0.dp else Spacing.M)
|
|
144
|
-
|
|
145
|
-
|
|
114
|
+
.absolutePadding(left = if (isRight) Spacing.M else 0.dp, right = if (isRight) 0.dp else Spacing.M)
|
|
115
|
+
.wrapContentWidth(if (isRight) AbsoluteAlignment.Left else AbsoluteAlignment.Right)
|
|
116
|
+
.width(COMPACT_SIZE),
|
|
117
|
+
horizontalAlignment = Alignment.CenterHorizontally,
|
|
118
|
+
verticalArrangement = Arrangement.spacedBy(TabBarMetrics.railCtaGap),
|
|
146
119
|
) {
|
|
147
120
|
val current = items.getOrNull(selectedIndex)
|
|
148
121
|
if (compression.tabBarCompressed && current != null) {
|
|
149
|
-
|
|
122
|
+
Column(
|
|
150
123
|
modifier = Modifier
|
|
151
|
-
.size(
|
|
152
|
-
.
|
|
124
|
+
.size(COMPACT_SIZE)
|
|
125
|
+
.tabBarContainer(CircleShape)
|
|
153
126
|
.noFeedbackClickable(onClick = compression.expandTabBar)
|
|
154
127
|
.setAutomationId("bottom_tab_bar"),
|
|
155
|
-
|
|
128
|
+
horizontalAlignment = Alignment.CenterHorizontally,
|
|
129
|
+
verticalArrangement = Arrangement.Center,
|
|
156
130
|
) {
|
|
157
|
-
|
|
131
|
+
TabIcon(current, AppTheme.current.colors.primary, vertical = true)
|
|
158
132
|
}
|
|
159
133
|
} else {
|
|
160
134
|
Rail(items, selectedIndex) {
|
|
@@ -163,215 +137,67 @@ private fun BoxScope.DuoRailTabBar(
|
|
|
163
137
|
}
|
|
164
138
|
}
|
|
165
139
|
if (floatingButton != null) {
|
|
166
|
-
|
|
140
|
+
RailCenterAction(floatingButton)
|
|
167
141
|
}
|
|
168
142
|
}
|
|
169
143
|
}
|
|
170
144
|
|
|
171
|
-
// Column of
|
|
145
|
+
// Column of rail items (.Nav/Duo/Item) with the sliding active indicator.
|
|
172
146
|
@Composable
|
|
173
147
|
private fun Rail(items: List<BottomTabItem>, selectedIndex: Int, onItemClick: (Int) -> Unit) {
|
|
174
|
-
val
|
|
175
|
-
val bubbleOffset by animateDpAsState(
|
|
176
|
-
targetValue = (ITEM_SIZE + RAIL_GAP) * (pressedIndex.value ?: selectedIndex).coerceAtLeast(0),
|
|
177
|
-
animationSpec = BUBBLE_SPRING,
|
|
178
|
-
label = "DuoRailBubble",
|
|
179
|
-
)
|
|
148
|
+
val density = LocalDensity.current
|
|
180
149
|
Box(
|
|
181
150
|
Modifier
|
|
182
|
-
.
|
|
183
|
-
.
|
|
151
|
+
.wrapContentWidth(unbounded = true)
|
|
152
|
+
.width(TabBarMetrics.railContainerWidth)
|
|
153
|
+
.tabBarContainer(RoundedCornerShape(Radius.XL))
|
|
154
|
+
.padding(horizontal = TabBarMetrics.railPaddingHorizontal)
|
|
155
|
+
.padding(bottom = TabBarMetrics.railPaddingBottom)
|
|
184
156
|
.setAutomationId("bottom_tab_bar")
|
|
185
157
|
) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
)
|
|
192
|
-
.size(RAIL_BUBBLE_WIDTH, RAIL_BUBBLE_HEIGHT)
|
|
193
|
-
.selectionLens(pressedIndex.value != null)
|
|
158
|
+
ActiveIndicator(
|
|
159
|
+
offset = with(density) { (Spacing.XS + TabBarMetrics.railItemHeight * selectedIndex.coerceAtLeast(0)).toPx() },
|
|
160
|
+
modifier = Modifier.size(TabBarMetrics.railItemWidth, TabBarMetrics.railIndicatorHeight),
|
|
161
|
+
shape = RoundedCornerShape(TabBarMetrics.railIndicatorRadius),
|
|
162
|
+
axisX = false,
|
|
194
163
|
)
|
|
195
|
-
Column
|
|
196
|
-
modifier = Modifier.padding(vertical = RAIL_PADDING),
|
|
197
|
-
verticalArrangement = Arrangement.spacedBy(RAIL_GAP),
|
|
198
|
-
) {
|
|
164
|
+
Column {
|
|
199
165
|
items.forEachIndexed { index, item ->
|
|
200
|
-
|
|
166
|
+
Column(
|
|
201
167
|
modifier = Modifier
|
|
202
|
-
.size(
|
|
203
|
-
.
|
|
204
|
-
|
|
168
|
+
.size(TabBarMetrics.railItemWidth, TabBarMetrics.railItemHeight)
|
|
169
|
+
.activeOpacityClickable { onItemClick(index) }
|
|
170
|
+
.semantics {
|
|
171
|
+
role = Role.Tab
|
|
172
|
+
selected = index == selectedIndex
|
|
173
|
+
contentDescription = item.label
|
|
174
|
+
},
|
|
175
|
+
horizontalAlignment = Alignment.CenterHorizontally,
|
|
176
|
+
verticalArrangement = Arrangement.Center,
|
|
205
177
|
) {
|
|
206
|
-
|
|
178
|
+
TabItemContent(item, selected = index == selectedIndex, vertical = true, fixedFontScale = true)
|
|
207
179
|
}
|
|
208
180
|
}
|
|
209
181
|
}
|
|
210
182
|
}
|
|
211
183
|
}
|
|
212
184
|
|
|
213
|
-
//
|
|
185
|
+
// Center action of the rail: round button with its label, under the container.
|
|
214
186
|
@Composable
|
|
215
|
-
private fun
|
|
216
|
-
|
|
217
|
-
items: List<BottomTabItem>,
|
|
218
|
-
floatingButton: BottomTabFloatingButton?,
|
|
219
|
-
selectedIndex: Int,
|
|
220
|
-
onTabSelected: (Int) -> Unit,
|
|
221
|
-
) {
|
|
222
|
-
val pressedIndex = remember { mutableStateOf<Int?>(null) }
|
|
223
|
-
|
|
224
|
-
Row(
|
|
225
|
-
modifier = Modifier
|
|
226
|
-
.align(Alignment.BottomCenter)
|
|
227
|
-
.fillMaxWidth()
|
|
228
|
-
.absolutePadding(
|
|
229
|
-
left = layout.insetLeft + DuoMetrics.floatingTabBarMargin,
|
|
230
|
-
right = layout.insetRight + DuoMetrics.floatingTabBarMargin,
|
|
231
|
-
)
|
|
232
|
-
.padding(bottom = floatingTabBarBottom(layout.insetBottom)),
|
|
233
|
-
horizontalArrangement = Arrangement.spacedBy(Spacing.S, Alignment.CenterHorizontally),
|
|
234
|
-
) {
|
|
235
|
-
Box(
|
|
236
|
-
modifier = Modifier
|
|
237
|
-
.weight(1f, fill = false)
|
|
238
|
-
.width(FLOATING_ITEM_WIDTH * items.size + FLOATING_PADDING * 2)
|
|
239
|
-
.height(FLOATING_HEIGHT)
|
|
240
|
-
.tabBarMaterial(RoundedCornerShape(FLOATING_HEIGHT / 2))
|
|
241
|
-
.padding(FLOATING_PADDING)
|
|
242
|
-
.setAutomationId("bottom_tab_bar")
|
|
243
|
-
) {
|
|
244
|
-
BoxWithConstraints(Modifier.fillMaxSize()) {
|
|
245
|
-
val cellWidth = maxWidth / items.size.coerceAtLeast(1)
|
|
246
|
-
val bubbleOffset by animateDpAsState(
|
|
247
|
-
targetValue = cellWidth * (pressedIndex.value ?: selectedIndex).coerceAtLeast(0),
|
|
248
|
-
animationSpec = BUBBLE_SPRING,
|
|
249
|
-
label = "DuoFloatingBubble",
|
|
250
|
-
)
|
|
251
|
-
Box(
|
|
252
|
-
Modifier
|
|
253
|
-
.offset(x = bubbleOffset)
|
|
254
|
-
.width(cellWidth)
|
|
255
|
-
.fillMaxHeight()
|
|
256
|
-
.selectionLens(pressedIndex.value != null)
|
|
257
|
-
)
|
|
258
|
-
Row(Modifier.fillMaxSize()) {
|
|
259
|
-
items.forEachIndexed { index, item ->
|
|
260
|
-
FloatingCell(item, selected = index == selectedIndex, index, pressedIndex) {
|
|
261
|
-
onTabSelected(index)
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (floatingButton != null) {
|
|
268
|
-
QrButton(floatingButton, size = FLOATING_HEIGHT, Modifier.shadow(3.dp, CircleShape))
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
@Composable
|
|
274
|
-
private fun RowScope.FloatingCell(
|
|
275
|
-
item: BottomTabItem,
|
|
276
|
-
selected: Boolean,
|
|
277
|
-
index: Int,
|
|
278
|
-
pressedIndex: MutableState<Int?>,
|
|
279
|
-
onClick: () -> Unit,
|
|
280
|
-
) {
|
|
281
|
-
val colors = AppTheme.current.colors
|
|
187
|
+
private fun RailCenterAction(data: BottomTabFloatingButton) {
|
|
188
|
+
val (interactionSource, pressed) = rememberCenterActionPress()
|
|
282
189
|
Column(
|
|
283
190
|
modifier = Modifier
|
|
284
|
-
.
|
|
285
|
-
.
|
|
286
|
-
.
|
|
191
|
+
.wrapContentWidth(unbounded = true)
|
|
192
|
+
.size(TabBarMetrics.railCtaWidth, TabBarMetrics.railCtaHeight)
|
|
193
|
+
.clickable(interactionSource = interactionSource, indication = null, onClick = data.onPress)
|
|
194
|
+
.setAutomationId(data.label),
|
|
287
195
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
288
|
-
verticalArrangement = Arrangement.spacedBy(
|
|
196
|
+
verticalArrangement = Arrangement.spacedBy(TabBarMetrics.railCtaLabelGap, Alignment.CenterVertically),
|
|
289
197
|
) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
val context = LocalContext.current
|
|
293
|
-
val fixedScale = remember(context) {
|
|
294
|
-
(context ?: MiniAppContext()).copy(userScaleRate = 1f, useOSScaleRate = false)
|
|
295
|
-
}
|
|
296
|
-
CompositionLocalProvider(LocalContext provides fixedScale) {
|
|
297
|
-
Text(
|
|
298
|
-
text = item.label,
|
|
299
|
-
style = Typography.labelXsMedium,
|
|
300
|
-
color = if (selected) colors.primary else colors.text.hint,
|
|
301
|
-
maxLines = 1,
|
|
302
|
-
overflow = TextOverflow.Ellipsis,
|
|
303
|
-
)
|
|
198
|
+
Box(Modifier.centerActionButton(TabBarMetrics.railCtaSize, pressed), contentAlignment = Alignment.Center) {
|
|
199
|
+
data.iconContent?.invoke() ?: Icon(source = data.icon, color = Colors.black_01, size = TabBarMetrics.ctaIconSize)
|
|
304
200
|
}
|
|
201
|
+
CenterActionLabel(data.label, data.labelContent, vertical = true, fixedFontScale = true)
|
|
305
202
|
}
|
|
306
203
|
}
|
|
307
|
-
|
|
308
|
-
// Tracks the finger so the selection lens jumps to the pressed tab before it is selected.
|
|
309
|
-
@Composable
|
|
310
|
-
private fun Modifier.tabClickable(index: Int, pressedIndex: MutableState<Int?>, onClick: () -> Unit): Modifier {
|
|
311
|
-
val interactionSource = remember { MutableInteractionSource() }
|
|
312
|
-
val pressed by interactionSource.collectIsPressedAsState()
|
|
313
|
-
LaunchedEffect(pressed) {
|
|
314
|
-
if (pressed) pressedIndex.value = index
|
|
315
|
-
else if (pressedIndex.value == index) pressedIndex.value = null
|
|
316
|
-
}
|
|
317
|
-
return clickable(interactionSource = interactionSource, indication = null, role = Role.Tab, onClick = onClick)
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// Selection bubble; while pressed it grows into a lens (80x54 to about 96x70).
|
|
321
|
-
@Composable
|
|
322
|
-
private fun Modifier.selectionLens(pressed: Boolean): Modifier {
|
|
323
|
-
val lens by animateFloatAsState(if (pressed) 1f else 0f, LENS_SPRING, label = "DuoSelectionLens")
|
|
324
|
-
val tint = AppTheme.current.colors.primary.copy(alpha = SELECTION_TINT_ALPHA)
|
|
325
|
-
return graphicsLayer {
|
|
326
|
-
scaleX = 1 + lens * (LENS_SCALE_X - 1)
|
|
327
|
-
scaleY = 1 + lens * (LENS_SCALE_Y - 1)
|
|
328
|
-
}.background(tint, CircleShape)
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
@Composable
|
|
332
|
-
private fun DuoTabIcon(item: BottomTabItem, selected: Boolean) {
|
|
333
|
-
val colors = AppTheme.current.colors
|
|
334
|
-
val badgeLabel = item.badgeLabel?.takeUnless { it.toIntOrNull() == 0 }
|
|
335
|
-
Box {
|
|
336
|
-
Icon(
|
|
337
|
-
source = item.icon,
|
|
338
|
-
size = ICON_SIZE,
|
|
339
|
-
color = if (selected) colors.primary else colors.text.hint,
|
|
340
|
-
)
|
|
341
|
-
when {
|
|
342
|
-
badgeLabel == null && !item.showDot -> Unit
|
|
343
|
-
badgeLabel.isNullOrEmpty() -> BadgeDot(
|
|
344
|
-
size = DotSize.Small,
|
|
345
|
-
modifier = Modifier.align(Alignment.TopEnd),
|
|
346
|
-
)
|
|
347
|
-
else -> Badge(
|
|
348
|
-
badgeLabel,
|
|
349
|
-
modifier = Modifier.align(Alignment.TopStart).offset(x = ICON_SIZE / 2, y = -Spacing.XS),
|
|
350
|
-
)
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
@Composable
|
|
356
|
-
private fun QrButton(data: BottomTabFloatingButton, size: Dp, modifier: Modifier = Modifier) {
|
|
357
|
-
Box(
|
|
358
|
-
modifier = modifier
|
|
359
|
-
.size(size)
|
|
360
|
-
.clip(CircleShape)
|
|
361
|
-
.background(AppTheme.current.colors.primary)
|
|
362
|
-
.noFeedbackClickable(onClick = data.onPress)
|
|
363
|
-
.setAutomationId(data.label),
|
|
364
|
-
contentAlignment = Alignment.Center,
|
|
365
|
-
) {
|
|
366
|
-
Icon(source = data.icon, color = Color.White, size = QR_ICON_SIZE)
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// RN BarMaterial: surface with a 1dp border.
|
|
371
|
-
@Composable
|
|
372
|
-
private fun Modifier.tabBarMaterial(shape: Shape): Modifier {
|
|
373
|
-
val colors = AppTheme.current.colors
|
|
374
|
-
return shadow(3.dp, shape)
|
|
375
|
-
.background(colors.background.surface)
|
|
376
|
-
.border(1.dp, colors.border.default, shape)
|
|
377
|
-
}
|