@momo-kits/native-kits 0.300.7-debug → 0.300.8-beta.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 +12 -8
- package/README.md +8 -7
- package/compose/build.gradle.kts +2 -4
- package/compose/build.gradle.kts.backup +1 -3
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +1 -2
- 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/commonMain/kotlin/vn/momo/kits/application/Context.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +2 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsBinding.kt +60 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsHost.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +20 -24
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +5 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +7 -17
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +18 -18
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +2 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +15 -18
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +4 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +13 -73
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +1 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +1 -53
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +3 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +2 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +12 -15
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +11 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +17 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +20 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +3 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +7 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +1 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +1 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +83 -82
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +6 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +9 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +13 -35
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +2 -4
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +5 -22
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +6 -24
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +55 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +1 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +3 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +22 -50
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +2 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +11 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +18 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +5 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +123 -64
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +24 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +11 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +16 -19
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +59 -41
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +69 -51
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +14 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +5 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +43 -32
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +330 -149
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +87 -70
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +1 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +92 -261
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +31 -40
- 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 +46 -72
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +8 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +29 -24
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +8 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +9 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +26 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +1 -3
- 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 +4 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +2 -3
- package/compose/src/commonTest/kotlin/vn/momo/kits/application/KitsHostTest.kt +44 -0
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +2 -7
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +9 -18
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +1 -1
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +3 -6
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +5 -6
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +12 -12
- 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 +11 -6
- package/gradle/libs.versions.toml +1 -3
- package/gradle.properties +1 -3
- package/ios/Application/ApplicationEnvironment.swift +6 -4
- package/ios/Application/DesignSystemKits.swift +59 -13
- package/ios/Application/DesignSystemKitsPayload.swift +0 -8
- package/ios/Application/LanguageSource.swift +2 -11
- package/ios/Application/Localize.swift +8 -35
- package/ios/Application/LocalizeModifier.swift +2 -11
- package/ios/Application/MaxApi.swift +3 -11
- package/ios/Avatar/Avatar.swift +0 -1
- package/ios/Badge/Badge.swift +5 -8
- package/ios/Badge/BadgeRibbon.swift +2 -5
- package/ios/Button/Button.swift +4 -8
- package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +5 -7
- package/ios/Carousel/Carousel.swift +4 -17
- package/ios/Checkbox/Checkbox.swift +0 -2
- package/ios/Collapse/Collapse.swift +17 -11
- package/ios/Colors+Radius+Spacing/Theme.swift +0 -7
- package/ios/DateTimePicker/DateTimePicker.swift +4 -10
- package/ios/DateTimePicker/DateTimePickerTypes.swift +1 -3
- package/ios/DateTimePicker/DateTimePickerUtils.swift +0 -3
- package/ios/DateTimePicker/WheelPicker.swift +2 -4
- package/ios/Extensions/ActiveOpacityButtonStyle.swift +2 -3
- package/ios/Extensions/Color++.swift +2 -4
- package/ios/Extensions/SkeletonUICompat.swift +0 -8
- package/ios/Icon/Icon.swift +3 -6
- package/ios/IconButton/IconButton.swift +2 -5
- package/ios/Input/ErrorView.swift +0 -7
- package/ios/Input/Input.swift +9 -20
- package/ios/Input/InputPhoneNumber.swift +37 -20
- package/ios/Input/InputSearch.swift +23 -12
- package/ios/Input/InputTextArea.swift +4 -13
- package/ios/InputDropDown/InputDropDown.swift +1 -11
- package/ios/InputMoney/InputMoney.swift +9 -28
- package/ios/InputOTP/InputOTP.swift +2 -9
- package/ios/Layout/HeaderLayout.swift +72 -0
- package/ios/Layout/Item.swift +1 -2
- package/ios/Layout/ModalLayout.swift +144 -0
- package/ios/Layout/ScreenLayout.swift +48 -31
- package/ios/Layout/Section.swift +2 -3
- package/ios/Loader/Loader.swift +3 -12
- package/ios/Lottie/LottieView.swift +0 -11
- package/ios/Navigation/BottomSheet.swift +73 -94
- package/ios/Navigation/BottomTab/BottomTab.swift +58 -73
- package/ios/Navigation/BottomTab/BottomTabBar.swift +286 -121
- package/ios/Navigation/BottomTab/CurvedContainer.swift +52 -54
- package/ios/Navigation/BottomTab/DuoBarCompression.swift +5 -12
- package/ios/Navigation/BottomTab/DuoTabBar.swift +67 -202
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +97 -0
- package/ios/Navigation/Component/FloatingButton.swift +4 -11
- package/ios/Navigation/Component/Header.swift +35 -54
- package/ios/Navigation/Component/HeaderBackground.swift +2 -8
- package/ios/Navigation/Component/HeaderJourney.swift +4 -8
- package/ios/Navigation/Component/HeaderLocation.swift +4 -8
- package/ios/Navigation/Component/HeaderRight.swift +20 -22
- package/ios/Navigation/Component/HeaderTitle.swift +1 -6
- package/ios/Navigation/Component/HeaderUser.swift +4 -10
- package/ios/Navigation/Component/SideBar.swift +6 -21
- package/ios/Navigation/Component/SnackBar.swift +9 -13
- package/ios/Navigation/HostBackGestureBridge.swift +2 -9
- package/ios/Navigation/ModalScreen.swift +24 -13
- package/ios/Navigation/Navigation.swift +35 -19
- package/ios/Navigation/NavigationContainer.swift +4 -15
- package/ios/Navigation/Navigator.swift +21 -39
- package/ios/Navigation/StackScreen.swift +64 -51
- package/ios/Navigation/StackTransition.swift +7 -14
- package/ios/Navigation/SwipeBackHaptic.swift +2 -7
- package/ios/Navigation/Tracking/ScreenTracker.swift +2 -7
- package/ios/Pagination/PaginationDot.swift +0 -9
- package/ios/Pagination/PaginationNumber.swift +1 -9
- package/ios/Pagination/PaginationScroll.swift +2 -14
- package/ios/Pagination/PaginationWhiteDot.swift +1 -10
- package/ios/Popup/PopupDisplay.swift +7 -5
- package/ios/Popup/PopupInput.swift +6 -4
- package/ios/Popup/PopupLayout.swift +17 -9
- package/ios/Popup/PopupNotify.swift +32 -25
- package/ios/PopupView/FullscreenPopup.swift +3 -4
- package/ios/PopupView/PopupView.swift +2 -2
- package/ios/PopupView/Utils++.swift +1 -2
- package/ios/ProgressInfo/ProgressInfo.swift +2 -13
- package/ios/Skeleton/Skeleton.swift +5 -16
- package/ios/Slider/Slider.swift +5 -12
- package/ios/StatusBarTap/StatusBarTap.h +2 -3
- package/ios/StatusBarTap/StatusBarTap.m +3 -16
- package/ios/Stepper/Stepper.swift +8 -27
- package/ios/Steps/Steps.swift +29 -26
- package/ios/Swipeable/SwipeCell.swift +2 -2
- package/ios/Swipeable/SwipeCellModel.swift +3 -6
- package/ios/TabView/TabView.swift +14 -28
- package/ios/Template/TrustBanner/TrustBanner.swift +2 -9
- package/ios/Title/Title.swift +1 -3
- package/ios/Tooltip/Tooltip.swift +4 -9
- package/ios/Typography/FontScale.swift +79 -24
- package/ios/Typography/Text.swift +6 -12
- package/ios/Typography/Typography.swift +8 -11
- package/ios/Uploader/Uploader.swift +2 -17
- 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/AnimatedHeaderDemo.swift +11 -2
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +296 -59
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputPhoneNumberDemo.swift +15 -4
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/LocalizeDemo.swift +0 -8
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +114 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TypographyDemo.swift +16 -0
- package/package.json +1 -1
- package/publish.sh +8 -2
- package/scripts/ci/build-swiftui.sh +22 -0
- package/scripts/ci/resolve-version.mjs +144 -0
- package/settings.gradle.kts +0 -1
|
@@ -1,40 +1,54 @@
|
|
|
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.clip
|
|
14
|
+
import androidx.compose.ui.draw.dropShadow
|
|
15
|
+
import androidx.compose.ui.draw.innerShadow
|
|
16
|
+
import androidx.compose.ui.graphics.Color
|
|
17
|
+
import androidx.compose.ui.graphics.Shape
|
|
18
|
+
import androidx.compose.ui.graphics.graphicsLayer
|
|
19
|
+
import androidx.compose.ui.layout.onPlaced
|
|
20
|
+
import androidx.compose.ui.layout.positionInParent
|
|
21
|
+
import androidx.compose.ui.platform.LocalDensity
|
|
22
|
+
import androidx.compose.ui.semantics.Role
|
|
23
|
+
import androidx.compose.ui.semantics.contentDescription
|
|
24
|
+
import androidx.compose.ui.semantics.role
|
|
25
|
+
import androidx.compose.ui.semantics.selected
|
|
26
|
+
import androidx.compose.ui.semantics.semantics
|
|
4
27
|
import androidx.compose.foundation.background
|
|
5
28
|
import androidx.compose.foundation.border
|
|
6
29
|
import androidx.compose.foundation.layout.*
|
|
7
30
|
import androidx.compose.foundation.shape.CircleShape
|
|
8
31
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
9
32
|
import androidx.compose.runtime.Composable
|
|
10
|
-
import androidx.compose.runtime.LaunchedEffect
|
|
11
|
-
import androidx.compose.runtime.getValue
|
|
12
|
-
import androidx.compose.runtime.mutableIntStateOf
|
|
13
33
|
import androidx.compose.runtime.remember
|
|
14
|
-
import androidx.compose.runtime.saveable.rememberSaveable
|
|
15
|
-
import androidx.compose.runtime.setValue
|
|
16
34
|
import androidx.compose.ui.Alignment
|
|
17
35
|
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
36
|
import androidx.compose.ui.text.style.TextAlign
|
|
22
37
|
import androidx.compose.ui.text.style.TextOverflow
|
|
23
|
-
import androidx.compose.ui.unit.Dp
|
|
24
|
-
import androidx.compose.ui.unit.IntOffset
|
|
25
38
|
import androidx.compose.ui.unit.dp
|
|
26
39
|
import vn.momo.kits.application.IsShowBaseLineDebug
|
|
27
40
|
import vn.momo.kits.components.*
|
|
28
41
|
import vn.momo.kits.const.*
|
|
42
|
+
import vn.momo.kits.layout.getScreenLayout
|
|
29
43
|
import vn.momo.kits.modifier.InternalApi
|
|
30
|
-
import vn.momo.kits.modifier.conditional
|
|
31
44
|
import vn.momo.kits.modifier.activeOpacityClickable
|
|
32
|
-
import vn.momo.kits.
|
|
33
|
-
import vn.momo.kits.
|
|
45
|
+
import vn.momo.kits.modifier.conditional
|
|
46
|
+
import vn.momo.kits.modifier.setAutomationId
|
|
34
47
|
|
|
35
48
|
@InternalApi
|
|
36
|
-
const val BOTTOM_TAB_BAR_HEIGHT =
|
|
49
|
+
const val BOTTOM_TAB_BAR_HEIGHT = 68
|
|
37
50
|
|
|
51
|
+
// Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
|
|
38
52
|
@Composable
|
|
39
53
|
internal fun BottomTabBar(
|
|
40
54
|
items: List<BottomTabItem>,
|
|
@@ -42,176 +56,343 @@ internal fun BottomTabBar(
|
|
|
42
56
|
selectedIndex: Int,
|
|
43
57
|
onTabSelected: (Int) -> Unit,
|
|
44
58
|
) {
|
|
45
|
-
|
|
46
59
|
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
60
|
Box(
|
|
62
|
-
|
|
61
|
+
modifier = Modifier
|
|
62
|
+
.fillMaxWidth()
|
|
63
|
+
.padding(bottom = tabBarBottomGap(layout.insetBottom)),
|
|
64
|
+
contentAlignment = Alignment.BottomCenter,
|
|
63
65
|
) {
|
|
64
|
-
|
|
66
|
+
HorizontalTabBar(
|
|
67
|
+
items = items,
|
|
68
|
+
floatingButton = floatingButton,
|
|
69
|
+
selectedIndex = selectedIndex,
|
|
70
|
+
onTabSelected = onTabSelected,
|
|
71
|
+
modifier = Modifier
|
|
72
|
+
.offset(x = (layout.insetLeft - layout.insetRight) / 2)
|
|
73
|
+
.width(
|
|
74
|
+
horizontalBarWidth(
|
|
75
|
+
layout.width, layout.height, layout.insetLeft, layout.insetRight,
|
|
76
|
+
items.size, hasCenterAction(floatingButton, items.size),
|
|
77
|
+
),
|
|
78
|
+
),
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Floating bar, items split evenly; Special type puts the center action in a notch, rising ctaLift above the bar.
|
|
84
|
+
@Composable
|
|
85
|
+
internal fun HorizontalTabBar(
|
|
86
|
+
items: List<BottomTabItem>,
|
|
87
|
+
floatingButton: BottomTabFloatingButton?,
|
|
88
|
+
selectedIndex: Int,
|
|
89
|
+
onTabSelected: (Int) -> Unit,
|
|
90
|
+
modifier: Modifier = Modifier,
|
|
91
|
+
) {
|
|
92
|
+
val cta = floatingButton?.takeIf { hasCenterAction(it, items.size) }
|
|
93
|
+
val mid = items.size / 2
|
|
94
|
+
val density = LocalDensity.current
|
|
95
|
+
val itemBounds = remember(items.size) { mutableStateMapOf<Int, Pair<Float, Float>>() }
|
|
96
|
+
|
|
97
|
+
BoxWithConstraints(modifier = modifier) {
|
|
98
|
+
val shape = remember(maxWidth, cta != null) {
|
|
99
|
+
NotchedBarShape(TabBarMetrics.height / 2, if (cta != null) maxWidth / 2 else null)
|
|
100
|
+
}
|
|
101
|
+
Box(
|
|
65
102
|
modifier = Modifier
|
|
103
|
+
.padding(top = if (cta != null) TabBarMetrics.ctaLift else 0.dp)
|
|
66
104
|
.fillMaxWidth()
|
|
67
|
-
.height(
|
|
68
|
-
.
|
|
69
|
-
.
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
.horizontalSafeAreaPadding(),
|
|
73
|
-
horizontalArrangement = Arrangement.SpaceAround,
|
|
105
|
+
.height(TabBarMetrics.height)
|
|
106
|
+
.tabBarContainer(shape)
|
|
107
|
+
.padding(horizontal = TabBarMetrics.paddingHorizontal, vertical = TabBarMetrics.paddingVertical)
|
|
108
|
+
.setAutomationId("bottom_tab_bar"),
|
|
74
109
|
) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
110
|
+
itemBounds[selectedIndex]?.let { (x, width) ->
|
|
111
|
+
ActiveIndicator(
|
|
112
|
+
offset = x,
|
|
113
|
+
modifier = Modifier
|
|
114
|
+
.width(with(density) { width.toDp() })
|
|
115
|
+
.height(TabBarMetrics.indicatorHeight),
|
|
116
|
+
shape = RoundedCornerShape(TabBarMetrics.indicatorRadius),
|
|
117
|
+
axisX = true,
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
Row(
|
|
121
|
+
modifier = Modifier.fillMaxSize(),
|
|
122
|
+
horizontalArrangement = Arrangement.spacedBy(TabBarMetrics.itemGap),
|
|
123
|
+
verticalAlignment = Alignment.CenterVertically,
|
|
124
|
+
) {
|
|
125
|
+
items.forEachIndexed { index, item ->
|
|
126
|
+
if (cta != null && index == mid) {
|
|
127
|
+
Spacer(Modifier.width(TabBarMetrics.ctaSlotWidth))
|
|
128
|
+
}
|
|
129
|
+
TabBarItem(
|
|
130
|
+
item = item,
|
|
131
|
+
selected = index == selectedIndex,
|
|
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, Modifier.align(Alignment.TopCenter).offset(y = centerActionTop())) }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
83
143
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
)
|
|
144
|
+
// Offset of the center action column from the bar top: the items are centered in the container (which
|
|
145
|
+
// starts ctaLift down), so the column is placed for its label to start on the tab labels' line.
|
|
146
|
+
private fun centerActionTop() = with(TabBarMetrics) {
|
|
147
|
+
val itemHeight = indicatorHeight + itemIconLabelGap + labelHeight
|
|
148
|
+
val itemLabelTop = ctaLift + paddingVertical + (height - paddingVertical * 2 - itemHeight) / 2 +
|
|
149
|
+
indicatorHeight + itemIconLabelGap
|
|
150
|
+
itemLabelTop - ctaLabelGap - ctaSize
|
|
151
|
+
}
|
|
93
152
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
153
|
+
// One active indicator per bar (Background/tonal with its inner shadows) sliding to the selected item
|
|
154
|
+
// along x (horizontal bar) or y (rail); it lands in place on the first measure and slides from then on.
|
|
155
|
+
@Composable
|
|
156
|
+
internal fun ActiveIndicator(offset: Float, modifier: Modifier, shape: Shape, axisX: Boolean) {
|
|
157
|
+
val colors = AppTheme.current.colors
|
|
158
|
+
val position = remember { Animatable(offset) }
|
|
159
|
+
LaunchedEffect(offset) {
|
|
160
|
+
if (position.value != offset) position.animateTo(offset, TabBarMotion.indicator)
|
|
161
|
+
}
|
|
162
|
+
Box(
|
|
163
|
+
modifier
|
|
164
|
+
.graphicsLayer {
|
|
165
|
+
if (axisX) translationX = position.value else translationY = position.value
|
|
166
|
+
}
|
|
167
|
+
.background(colors.background.tonal, shape)
|
|
168
|
+
.then(
|
|
169
|
+
indicatorInnerShadows(colors.primary).fold(Modifier as Modifier) { acc, shadow ->
|
|
170
|
+
acc.innerShadow(shape, shadow)
|
|
171
|
+
}
|
|
102
172
|
)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@Composable
|
|
177
|
+
private fun RowScope.TabBarItem(
|
|
178
|
+
item: BottomTabItem,
|
|
179
|
+
selected: Boolean,
|
|
180
|
+
modifier: Modifier,
|
|
181
|
+
onClick: () -> Unit,
|
|
182
|
+
) {
|
|
183
|
+
Column(
|
|
184
|
+
modifier = modifier
|
|
185
|
+
.weight(1f)
|
|
186
|
+
.conditional(IsShowBaseLineDebug) {
|
|
187
|
+
border(1.dp, Colors.blue_03)
|
|
107
188
|
}
|
|
108
|
-
|
|
189
|
+
.activeOpacityClickable { onClick() }
|
|
190
|
+
.semantics {
|
|
191
|
+
role = Role.Tab
|
|
192
|
+
this.selected = selected
|
|
193
|
+
contentDescription = item.label
|
|
194
|
+
},
|
|
195
|
+
horizontalAlignment = Alignment.CenterHorizontally,
|
|
196
|
+
verticalArrangement = Arrangement.spacedBy(TabBarMetrics.itemIconLabelGap),
|
|
197
|
+
) {
|
|
198
|
+
TabItemContent(item, selected)
|
|
109
199
|
}
|
|
110
200
|
}
|
|
111
201
|
|
|
202
|
+
// Icon in its indicator slot, label under it. The bar slides one shared active indicator behind the
|
|
203
|
+
// slots; the icon and label tint cross-fade on focus.
|
|
112
204
|
@Composable
|
|
113
|
-
internal fun
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
205
|
+
internal fun ColumnScope.TabItemContent(
|
|
206
|
+
item: BottomTabItem,
|
|
207
|
+
selected: Boolean,
|
|
208
|
+
vertical: Boolean = false,
|
|
209
|
+
showLabel: Boolean = true,
|
|
210
|
+
) {
|
|
211
|
+
val colors = AppTheme.current.colors
|
|
212
|
+
val tint by animateColorAsState(
|
|
213
|
+
if (selected) colors.primary else colors.text.secondary,
|
|
214
|
+
tween(TabBarMotion.TINT_MILLIS, easing = inOutQuad),
|
|
215
|
+
label = "TabTint",
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
Box(
|
|
219
|
+
modifier = Modifier
|
|
220
|
+
.then(if (vertical) Modifier else Modifier.fillMaxWidth())
|
|
221
|
+
.height(if (vertical) TabBarMetrics.railIndicatorHeight else TabBarMetrics.indicatorHeight)
|
|
222
|
+
.padding(horizontal = TabBarMetrics.indicatorPaddingHorizontal),
|
|
223
|
+
contentAlignment = Alignment.Center,
|
|
224
|
+
) {
|
|
225
|
+
TabIcon(item, tint, vertical)
|
|
226
|
+
}
|
|
227
|
+
if (showLabel) {
|
|
228
|
+
// fixed slot so a capped-scale label overflows downward and the icon above it stays put
|
|
229
|
+
Box(
|
|
230
|
+
modifier = Modifier.height(
|
|
231
|
+
if (vertical) TabBarMetrics.railLabelHeight else TabBarMetrics.labelHeight
|
|
232
|
+
),
|
|
233
|
+
contentAlignment = Alignment.TopCenter,
|
|
234
|
+
) {
|
|
235
|
+
Text(
|
|
236
|
+
text = item.label,
|
|
237
|
+
color = tint,
|
|
238
|
+
style = if (vertical) Typography.labelXsMedium else Typography.labelSMedium,
|
|
239
|
+
textAlign = TextAlign.Center,
|
|
240
|
+
maxLines = 1,
|
|
241
|
+
overflow = TextOverflow.Ellipsis,
|
|
242
|
+
modifier = (if (vertical) Modifier else Modifier.fillMaxWidth())
|
|
243
|
+
.wrapContentHeight(Alignment.Top, unbounded = true),
|
|
126
244
|
)
|
|
127
245
|
}
|
|
128
246
|
}
|
|
129
247
|
}
|
|
130
248
|
|
|
249
|
+
// Badge value shown on a tab: null hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
|
|
250
|
+
internal fun tabBadgeLabel(item: BottomTabItem): String? {
|
|
251
|
+
val label = item.badgeLabel ?: return if (item.showDot) "" else null
|
|
252
|
+
if (label.isEmpty()) return ""
|
|
253
|
+
if (label.all { it in '0'..'9' }) {
|
|
254
|
+
val value = label.toLongOrNull() ?: Long.MAX_VALUE
|
|
255
|
+
if (value == 0L) return if (item.showDot) "" else null
|
|
256
|
+
return if (value > 99) "99+" else label
|
|
257
|
+
}
|
|
258
|
+
return label
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// 24 icon; badges hang off it unclipped: dot at 16/-2, label badge at 12/-7 growing right, or
|
|
262
|
+
// centered over the icon at -10 on the rail.
|
|
131
263
|
@Composable
|
|
132
|
-
internal fun
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
264
|
+
internal fun TabIcon(item: BottomTabItem, tint: androidx.compose.ui.graphics.Color, vertical: Boolean) {
|
|
265
|
+
val badge = tabBadgeLabel(item)
|
|
266
|
+
Box(Modifier.size(TabBarMetrics.iconSize)) {
|
|
267
|
+
Icon(source = item.icon, size = TabBarMetrics.iconSize, color = tint)
|
|
268
|
+
when {
|
|
269
|
+
badge == null -> Unit
|
|
270
|
+
badge.isEmpty() -> BadgeDot(
|
|
271
|
+
size = DotSize.Small,
|
|
272
|
+
modifier = Modifier.offset(x = 16.dp, y = -Spacing.XXS),
|
|
273
|
+
)
|
|
274
|
+
vertical -> TabBadge(
|
|
275
|
+
badge,
|
|
276
|
+
Modifier.matchParentSize()
|
|
277
|
+
.wrapContentSize(Alignment.TopCenter, unbounded = true)
|
|
278
|
+
.offset(y = (-10).dp),
|
|
279
|
+
)
|
|
280
|
+
else -> TabBadge(
|
|
281
|
+
badge,
|
|
282
|
+
Modifier.matchParentSize()
|
|
283
|
+
.wrapContentSize(Alignment.TopStart, unbounded = true)
|
|
284
|
+
.offset(x = Spacing.M, y = (-7).dp),
|
|
285
|
+
)
|
|
143
286
|
}
|
|
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
|
-
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Numbers use the error color, text the warning color (Figma Badge round numeric / text); the text keeps
|
|
291
|
+
// its design size so it fits the 16 height on the Duo displays too.
|
|
292
|
+
@Composable
|
|
293
|
+
private fun TabBadge(label: String, modifier: Modifier) {
|
|
294
|
+
val colors = AppTheme.current.colors
|
|
295
|
+
val isNumber = label.trimEnd('+').let { it.isNotEmpty() && it.all { c -> c in '0'..'9' } }
|
|
296
|
+
Box(
|
|
297
|
+
modifier = modifier
|
|
298
|
+
.height(16.dp)
|
|
299
|
+
.widthIn(min = 16.dp, max = TabBarMetrics.badgeMaxWidth)
|
|
300
|
+
.background(if (isNumber) colors.error.primary else colors.warning.primary, CircleShape)
|
|
301
|
+
.border(1.dp, colors.background.surface, CircleShape)
|
|
302
|
+
.padding(horizontal = Spacing.XS),
|
|
303
|
+
contentAlignment = Alignment.Center,
|
|
304
|
+
) {
|
|
305
|
+
ScaleSizeScope(1f) {
|
|
168
306
|
Text(
|
|
169
|
-
text =
|
|
170
|
-
|
|
171
|
-
|
|
307
|
+
text = label,
|
|
308
|
+
style = Typography.actionXxsBold,
|
|
309
|
+
color = Colors.black_01,
|
|
172
310
|
maxLines = 1,
|
|
173
|
-
overflow = TextOverflow.Ellipsis
|
|
311
|
+
overflow = TextOverflow.Ellipsis,
|
|
174
312
|
)
|
|
175
313
|
}
|
|
176
314
|
}
|
|
177
315
|
}
|
|
178
316
|
|
|
317
|
+
// Center action press: the button shrinks while held; the label stays plain text.
|
|
179
318
|
@Composable
|
|
180
|
-
internal fun
|
|
181
|
-
|
|
319
|
+
internal fun rememberCenterActionPress(): Pair<MutableInteractionSource, Boolean> {
|
|
320
|
+
val interactionSource = remember { MutableInteractionSource() }
|
|
321
|
+
val pressed by interactionSource.collectIsPressedAsState()
|
|
322
|
+
return interactionSource to pressed
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
@Composable
|
|
326
|
+
internal fun Modifier.centerActionPressScale(pressed: Boolean): Modifier {
|
|
327
|
+
val scale by animateFloatAsState(
|
|
328
|
+
if (pressed) TabBarMotion.CTA_PRESSED_SCALE else 1f,
|
|
329
|
+
tween(TabBarMotion.CTA_PRESS_MILLIS, easing = inOutQuad),
|
|
330
|
+
label = "CenterActionPress",
|
|
331
|
+
)
|
|
332
|
+
return graphicsLayer {
|
|
333
|
+
scaleX = scale
|
|
334
|
+
scaleY = scale
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
@Composable
|
|
339
|
+
internal fun Modifier.centerActionButton(size: androidx.compose.ui.unit.Dp, pressed: Boolean): Modifier {
|
|
340
|
+
return centerActionPressScale(pressed)
|
|
341
|
+
.size(size)
|
|
342
|
+
.then(CtaShadows.fold(Modifier as Modifier) { acc, shadow -> acc.spreadShadow(CircleShape, shadow) })
|
|
343
|
+
.background(AppTheme.current.colors.primary, CircleShape)
|
|
344
|
+
.border(1.dp, Color.White.copy(alpha = TabBarMetrics.ctaBorderOpacity), CircleShape)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
@Composable
|
|
348
|
+
internal fun CenterActionLabel(label: String, overlay: (@Composable () -> Unit)?, vertical: Boolean) {
|
|
349
|
+
val colors = AppTheme.current.colors
|
|
350
|
+
Box(
|
|
182
351
|
modifier = Modifier
|
|
183
|
-
.
|
|
184
|
-
.padding(horizontal = Spacing.
|
|
352
|
+
.then(if (vertical) Modifier else Modifier.heightIn(min = TabBarMetrics.ctaLabelHeight))
|
|
353
|
+
.padding(horizontal = if (vertical) Spacing.XS else Spacing.XXS),
|
|
354
|
+
contentAlignment = Alignment.Center,
|
|
355
|
+
) {
|
|
356
|
+
Text(
|
|
357
|
+
text = label,
|
|
358
|
+
style = if (vertical) Typography.labelXsMedium else Typography.labelSMedium,
|
|
359
|
+
color = colors.text.secondary,
|
|
360
|
+
textAlign = TextAlign.Center,
|
|
361
|
+
maxLines = 1,
|
|
362
|
+
overflow = TextOverflow.Ellipsis,
|
|
363
|
+
)
|
|
364
|
+
overlay?.let {
|
|
365
|
+
Box(Modifier.matchParentSize().wrapContentSize(Alignment.Center, unbounded = true)) { it() }
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Center action (.Nav/CTA): button rising out of the notch, label under it.
|
|
371
|
+
@Composable
|
|
372
|
+
private fun CenterAction(data: BottomTabFloatingButton, modifier: Modifier) {
|
|
373
|
+
val (interactionSource, pressed) = rememberCenterActionPress()
|
|
374
|
+
Column(
|
|
375
|
+
modifier = modifier
|
|
376
|
+
.width(TabBarMetrics.ctaSlotWidth)
|
|
185
377
|
.conditional(IsShowBaseLineDebug) {
|
|
186
378
|
border(1.dp, Colors.blue_03)
|
|
187
379
|
}
|
|
188
|
-
.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
verticalArrangement = Arrangement.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
Icon(source = data.icon, color = Color.White, size = 28.dp)
|
|
380
|
+
.clickable(interactionSource = interactionSource, indication = null, onClick = data.onPress)
|
|
381
|
+
.setAutomationId(data.label),
|
|
382
|
+
horizontalAlignment = Alignment.CenterHorizontally,
|
|
383
|
+
verticalArrangement = Arrangement.spacedBy(TabBarMetrics.ctaLabelGap),
|
|
384
|
+
) {
|
|
385
|
+
Box(Modifier.centerActionButton(TabBarMetrics.ctaSize, pressed), contentAlignment = Alignment.Center) {
|
|
386
|
+
val iconContent = data.iconContent
|
|
387
|
+
if (iconContent != null) {
|
|
388
|
+
// custom content (e.g. an oversized Lottie) is clipped to the round button
|
|
389
|
+
Box(Modifier.size(TabBarMetrics.ctaSize).clip(CircleShape), contentAlignment = Alignment.Center) {
|
|
390
|
+
iconContent()
|
|
391
|
+
}
|
|
392
|
+
} else {
|
|
393
|
+
Icon(source = data.icon, color = Colors.black_01, size = TabBarMetrics.ctaIconSize)
|
|
394
|
+
}
|
|
204
395
|
}
|
|
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
|
-
)
|
|
396
|
+
CenterActionLabel(data.label, data.labelContent, vertical = false)
|
|
216
397
|
}
|
|
217
398
|
}
|