@momo-kits/native-kits 0.168.1-beta.31-debug → 0.168.1-beta.32
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 +1 -2
- package/ios/Input/Input.swift +1 -3
- package/ios/Input/InputTextArea.swift +1 -3
- package/ios/Navigation/BottomTab/BottomTab.swift +48 -67
- package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -131
- package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
- package/ios/Navigation/BottomTab/DuoTabBar.swift +72 -292
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +88 -0
- package/ios/Navigation/StackScreen.swift +3 -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/package.json +1 -1
- package/build.gradle.kts +0 -11
- package/compose/build.gradle.kts +0 -198
- package/compose/build.gradle.kts.backup +0 -198
- package/compose/compose.podspec +0 -47
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -20
- package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -153
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +0 -18
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -110
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +0 -62
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -1071
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -269
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -81
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -357
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -128
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -542
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -231
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -189
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -478
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -114
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -265
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -235
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -223
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -265
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -185
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -343
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -41
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -84
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -40
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -370
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -308
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -90
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -330
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -220
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -473
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -207
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -92
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -560
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -125
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -207
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -501
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -236
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -17
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -287
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -321
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -52
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -502
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -148
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -116
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -205
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -422
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -732
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -148
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -232
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -237
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -97
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +0 -380
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -436
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -169
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -455
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -105
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -399
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -192
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -91
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -74
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -21
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -118
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -42
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -66
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -218
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -138
- package/gradle/libs.versions.toml +0 -69
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +0 -8
- package/gradle.properties +0 -26
- package/gradlew +0 -252
- package/gradlew.bat +0 -94
- package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +0 -364
- package/ios-demo/README.md +0 -120
- package/settings.gradle.kts +0 -64
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// MoMoUIKits
|
|
4
4
|
//
|
|
5
5
|
// SwiftUI mirror of Compose's `navigation/bottomtab/BottomTabBar.kt`.
|
|
6
|
-
//
|
|
7
|
-
// badges/dots, and
|
|
6
|
+
// Horizontal navigation bar (Figma "Specs Navigation", DS-984): floating container, items split
|
|
7
|
+
// evenly with a tonal active indicator, badges/dots, and the Special type's center action in a notch.
|
|
8
8
|
//
|
|
9
9
|
|
|
10
10
|
import SwiftUI
|
|
@@ -49,196 +49,346 @@ public struct BottomTabFloatingButton {
|
|
|
49
49
|
public let icon: String
|
|
50
50
|
public let label: String
|
|
51
51
|
public let onPress: () -> Void
|
|
52
|
+
/// Replaces the icon inside the 48 button, e.g. the button part of a Lottie; centered, unclipped.
|
|
53
|
+
public let iconContent: AnyView?
|
|
54
|
+
/// Drawn over the label text, which stays, e.g. the label part of a Lottie; centered, unclipped.
|
|
55
|
+
public let labelContent: AnyView?
|
|
52
56
|
|
|
53
57
|
public init(icon: String, label: String, onPress: @escaping () -> Void) {
|
|
54
58
|
self.icon = icon
|
|
55
59
|
self.label = label
|
|
56
60
|
self.onPress = onPress
|
|
61
|
+
self.iconContent = nil
|
|
62
|
+
self.labelContent = nil
|
|
57
63
|
}
|
|
64
|
+
|
|
65
|
+
/// The button and label parts given separately, e.g. a Lottie split into both.
|
|
66
|
+
public init<IconContent: View, LabelContent: View>(
|
|
67
|
+
label: String,
|
|
68
|
+
onPress: @escaping () -> Void,
|
|
69
|
+
@ViewBuilder iconContent: () -> IconContent,
|
|
70
|
+
@ViewBuilder labelContent: () -> LabelContent
|
|
71
|
+
) {
|
|
72
|
+
self.icon = ""
|
|
73
|
+
self.label = label
|
|
74
|
+
self.onPress = onPress
|
|
75
|
+
self.iconContent = AnyView(iconContent())
|
|
76
|
+
self.labelContent = AnyView(labelContent())
|
|
77
|
+
}
|
|
78
|
+
|
|
58
79
|
}
|
|
59
80
|
|
|
60
|
-
let
|
|
61
|
-
let BOTTOM_TAB_BAR_HEIGHT: CGFloat = 64
|
|
81
|
+
let BOTTOM_TAB_BAR_HEIGHT: CGFloat = TabBarMetrics.height
|
|
62
82
|
|
|
63
83
|
// MARK: - Tab bar
|
|
64
84
|
|
|
85
|
+
/// Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
|
|
65
86
|
struct BottomTabBar: View {
|
|
66
87
|
let items: [BottomTabItem]
|
|
67
88
|
let floatingButton: BottomTabFloatingButton?
|
|
68
89
|
let selectedIndex: Int
|
|
69
90
|
let onTabSelected: (Int) -> Void
|
|
70
|
-
|
|
91
|
+
let bottomInset: CGFloat
|
|
71
92
|
|
|
72
93
|
@Environment(\.screenLayout) private var layout
|
|
73
|
-
@Environment(\.appTheme) private var theme
|
|
74
94
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
95
|
+
var body: some View {
|
|
96
|
+
HorizontalTabBar(
|
|
97
|
+
items: items,
|
|
98
|
+
floatingButton: floatingButton,
|
|
99
|
+
selectedIndex: selectedIndex,
|
|
100
|
+
onTabSelected: onTabSelected,
|
|
101
|
+
width: TabBarMetrics.horizontalBarWidth(layout)
|
|
102
|
+
)
|
|
103
|
+
.padding(.bottom, TabBarMetrics.bottomGap(bottomInset))
|
|
104
|
+
.frame(maxWidth: .infinity)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
78
107
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
108
|
+
/// Horizontal navigation bar: floating container, items split evenly; Special type puts the center
|
|
109
|
+
/// action in a notch in the middle, rising ctaLift above the container. One active indicator slides
|
|
110
|
+
/// behind the selected item.
|
|
111
|
+
struct HorizontalTabBar: View {
|
|
112
|
+
let items: [BottomTabItem]
|
|
113
|
+
let floatingButton: BottomTabFloatingButton?
|
|
114
|
+
let selectedIndex: Int
|
|
115
|
+
let onTabSelected: (Int) -> Void
|
|
116
|
+
let width: CGFloat
|
|
117
|
+
var fixedFontScale = false
|
|
118
|
+
|
|
119
|
+
private var cta: BottomTabFloatingButton? {
|
|
120
|
+
TabBarMetrics.hasCenterAction(floatingButton, tabCount: items.count) ? floatingButton : nil
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/// Items share what the padding, gaps and center action slot leave.
|
|
124
|
+
private var itemWidth: CGFloat {
|
|
125
|
+
let slots = CGFloat(items.count + (cta == nil ? 0 : 1))
|
|
126
|
+
let content = width - 2 * TabBarMetrics.paddingHorizontal - (slots - 1) * TabBarMetrics.itemGap
|
|
127
|
+
return max((content - (cta == nil ? 0 : TabBarMetrics.ctaSlotWidth)) / CGFloat(max(items.count, 1)), 0)
|
|
84
128
|
}
|
|
85
129
|
|
|
86
|
-
private
|
|
87
|
-
let
|
|
88
|
-
return
|
|
130
|
+
private func itemX(_ index: Int) -> CGFloat {
|
|
131
|
+
let afterCta = cta != nil && index >= items.count / 2
|
|
132
|
+
return TabBarMetrics.paddingHorizontal + CGFloat(index) * (itemWidth + TabBarMetrics.itemGap)
|
|
133
|
+
+ (afterCta ? TabBarMetrics.ctaSlotWidth + TabBarMetrics.itemGap : 0)
|
|
89
134
|
}
|
|
90
135
|
|
|
91
136
|
var body: some View {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
137
|
+
let shape = NotchedBarShape(radius: TabBarMetrics.height / 2, notchCenterX: cta == nil ? nil : width / 2)
|
|
138
|
+
ZStack(alignment: .top) {
|
|
139
|
+
ZStack(alignment: .topLeading) {
|
|
140
|
+
ActiveIndicator(radius: TabBarMetrics.indicatorRadius)
|
|
141
|
+
.frame(width: itemWidth, height: TabBarMetrics.indicatorHeight)
|
|
142
|
+
.offset(x: itemX(selectedIndex), y: TabBarMetrics.paddingVertical)
|
|
143
|
+
.animation(TabBarMetrics.indicatorMotion, value: selectedIndex)
|
|
144
|
+
|
|
145
|
+
HStack(spacing: TabBarMetrics.itemGap) {
|
|
146
|
+
ForEach(items.indices, id: \.self) { index in
|
|
147
|
+
if cta != nil && index == items.count / 2 {
|
|
148
|
+
Color.clear.frame(width: TabBarMetrics.ctaSlotWidth)
|
|
149
|
+
}
|
|
150
|
+
SwiftUI.Button { onTabSelected(index) } label: {
|
|
151
|
+
VStack(spacing: Spacing.XXS) {
|
|
152
|
+
TabItemContent(item: items[index], selected: index == selectedIndex, fixedFontScale: fixedFontScale)
|
|
153
|
+
}
|
|
154
|
+
.frame(width: itemWidth)
|
|
155
|
+
.contentShape(Rectangle())
|
|
156
|
+
}
|
|
157
|
+
.buttonStyle(.plain)
|
|
158
|
+
.accessibilityLabel(items[index].label)
|
|
159
|
+
.accessibilityAddTraits(index == selectedIndex ? .isSelected : [])
|
|
160
|
+
}
|
|
102
161
|
}
|
|
162
|
+
.padding(.horizontal, TabBarMetrics.paddingHorizontal)
|
|
163
|
+
.padding(.vertical, TabBarMetrics.paddingVertical)
|
|
103
164
|
}
|
|
104
|
-
.frame(
|
|
105
|
-
.
|
|
106
|
-
.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
RoundedRectangle(cornerRadius: 2)
|
|
110
|
-
.fill(theme.colors.primary)
|
|
111
|
-
.frame(width: 44, height: 2)
|
|
112
|
-
.offset(x: indicatorOffset, y: -BOTTOM_TAB_BAR_HEIGHT + 2)
|
|
113
|
-
.animation(.easeInOut(duration: 0.25), value: selectedIndex)
|
|
114
|
-
|
|
115
|
-
// Top shadow.
|
|
116
|
-
LinearGradient(
|
|
117
|
-
colors: [Color.black.opacity(0.05), .clear],
|
|
118
|
-
startPoint: .bottom,
|
|
119
|
-
endPoint: .top
|
|
120
|
-
)
|
|
121
|
-
.frame(height: 6)
|
|
122
|
-
.frame(maxWidth: .infinity)
|
|
123
|
-
.offset(y: -BOTTOM_TAB_BAR_HEIGHT)
|
|
165
|
+
.frame(width: width, height: TabBarMetrics.height, alignment: .topLeading)
|
|
166
|
+
.modifier(TabBarContainer(shape: shape))
|
|
167
|
+
.accessibilityElement(children: .contain)
|
|
168
|
+
.accessibilityIdentifier("bottom_tab_bar")
|
|
169
|
+
.padding(.top, cta == nil ? 0 : TabBarMetrics.ctaLift)
|
|
124
170
|
|
|
125
|
-
if let
|
|
126
|
-
|
|
171
|
+
if let cta {
|
|
172
|
+
CenterAction(data: cta, fixedFontScale: fixedFontScale)
|
|
127
173
|
}
|
|
128
174
|
}
|
|
175
|
+
.frame(width: width)
|
|
129
176
|
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/// One active indicator per bar: Background/tonal with its inner light (white 12% from below) and
|
|
180
|
+
/// tint (primary 12% from above).
|
|
181
|
+
struct ActiveIndicator: View {
|
|
182
|
+
let radius: CGFloat
|
|
183
|
+
|
|
184
|
+
@Environment(\.appTheme) private var theme
|
|
130
185
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
186
|
+
var body: some View {
|
|
187
|
+
let shape = RoundedRectangle(cornerRadius: radius)
|
|
188
|
+
shape
|
|
189
|
+
.fill(theme.colors.background.tonal)
|
|
190
|
+
// inner shadows: primary 12% falling 1 from the top edge, white 12% rising 2 from the bottom one
|
|
191
|
+
.overlay(
|
|
192
|
+
LinearGradient(
|
|
193
|
+
stops: [
|
|
194
|
+
.init(color: theme.colors.primary.opacity(0.12), location: 0),
|
|
195
|
+
.init(color: theme.colors.primary.opacity(0), location: 0.1),
|
|
196
|
+
.init(color: Color.white.opacity(0), location: 0.85),
|
|
197
|
+
.init(color: Color.white.opacity(0.12), location: 1),
|
|
198
|
+
],
|
|
199
|
+
startPoint: .top,
|
|
200
|
+
endPoint: .bottom
|
|
201
|
+
)
|
|
202
|
+
.clipShape(shape)
|
|
141
203
|
)
|
|
142
|
-
.
|
|
143
|
-
|
|
204
|
+
.allowsHitTesting(false)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/// Like the system tab bar, text keeps its design size instead of growing with the wide Duo displays.
|
|
209
|
+
struct FixedFontScale: ViewModifier {
|
|
210
|
+
let enabled: Bool
|
|
211
|
+
|
|
212
|
+
@Environment(\.momoFontScale) private var fontScale
|
|
213
|
+
|
|
214
|
+
func body(content: Content) -> some View {
|
|
215
|
+
content.environment(\.momoFontScale, enabled ? FontScale(userScaleRate: 1, useOSScaleRate: false) : fontScale)
|
|
144
216
|
}
|
|
145
217
|
}
|
|
146
218
|
|
|
147
219
|
// MARK: - Tab item
|
|
148
220
|
|
|
149
|
-
|
|
221
|
+
/// Icon in its indicator slot, label under it. The bar slides one shared active indicator behind the
|
|
222
|
+
/// slots; the icon and label tint cross-fade on focus.
|
|
223
|
+
struct TabItemContent: View {
|
|
150
224
|
let item: BottomTabItem
|
|
151
225
|
let selected: Bool
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
226
|
+
var vertical = false
|
|
227
|
+
var showLabel = true
|
|
228
|
+
var fixedFontScale = false
|
|
155
229
|
|
|
156
230
|
@Environment(\.appTheme) private var theme
|
|
157
231
|
|
|
158
|
-
|
|
232
|
+
var body: some View {
|
|
233
|
+
TabIcon(item: item, selected: selected, vertical: vertical)
|
|
234
|
+
.frame(height: vertical ? TabBarMetrics.railIndicatorHeight : TabBarMetrics.indicatorHeight)
|
|
235
|
+
if showLabel {
|
|
236
|
+
let label = ZStack {
|
|
237
|
+
labelText(theme.colors.text.secondary).opacity(selected ? 0 : 1)
|
|
238
|
+
labelText(theme.colors.primary).opacity(selected ? 1 : 0)
|
|
239
|
+
}
|
|
240
|
+
.animation(TabBarMetrics.tintMotion, value: selected)
|
|
241
|
+
.frame(maxWidth: vertical ? nil : .infinity)
|
|
242
|
+
label.modifier(FixedFontScale(enabled: fixedFontScale))
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private func labelText(_ color: Color) -> some View {
|
|
247
|
+
MomoText(
|
|
248
|
+
item.label,
|
|
249
|
+
typography: vertical ? .labelXsMedium : .labelSMedium,
|
|
250
|
+
color: color,
|
|
251
|
+
textAlign: .center,
|
|
252
|
+
maxLines: 1
|
|
253
|
+
)
|
|
254
|
+
.truncationMode(.tail)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
159
257
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
258
|
+
/// Badge value shown on a tab: nil hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
|
|
259
|
+
func tabBadgeLabel(_ item: BottomTabItem) -> String? {
|
|
260
|
+
guard let label = item.badgeLabel else { return item.showDot ? "" : nil }
|
|
261
|
+
if label.isEmpty { return "" }
|
|
262
|
+
if label.allSatisfy({ ("0"..."9").contains($0) }) {
|
|
263
|
+
let value = Int(label) ?? Int.max
|
|
264
|
+
if value == 0 { return item.showDot ? "" : nil }
|
|
265
|
+
return value > 99 ? "99+" : label
|
|
165
266
|
}
|
|
267
|
+
return label
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/// 24 icon, active and inactive tints cross-faded; badges hang off it: dot at 16/-2, label badge at
|
|
271
|
+
/// 12/-7 growing right, or centered over the icon at -10 on the rail.
|
|
272
|
+
struct TabIcon: View {
|
|
273
|
+
let item: BottomTabItem
|
|
274
|
+
let selected: Bool
|
|
275
|
+
var vertical = false
|
|
276
|
+
|
|
277
|
+
@Environment(\.appTheme) private var theme
|
|
166
278
|
|
|
167
279
|
var body: some View {
|
|
168
|
-
|
|
169
|
-
Icon(source: item.icon, size:
|
|
170
|
-
.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
280
|
+
ZStack {
|
|
281
|
+
Icon(source: item.icon, size: TabBarMetrics.iconSize, color: theme.colors.text.secondary)
|
|
282
|
+
.opacity(selected ? 0 : 1)
|
|
283
|
+
Icon(source: item.icon, size: TabBarMetrics.iconSize, color: theme.colors.primary)
|
|
284
|
+
.opacity(selected ? 1 : 0)
|
|
285
|
+
}
|
|
286
|
+
.animation(TabBarMetrics.tintMotion, value: selected)
|
|
287
|
+
.frame(width: TabBarMetrics.iconSize, height: TabBarMetrics.iconSize)
|
|
288
|
+
.overlay(alignment: vertical ? .top : .topLeading) {
|
|
289
|
+
if let badge = tabBadgeLabel(item) {
|
|
290
|
+
if badge.isEmpty {
|
|
291
|
+
BadgeDot(size: .small)
|
|
292
|
+
.offset(x: vertical ? 16 - (TabBarMetrics.iconSize - 10) / 2 : 16, y: -Spacing.XXS)
|
|
293
|
+
} else {
|
|
294
|
+
TabBadge(label: badge)
|
|
295
|
+
.fixedSize()
|
|
296
|
+
.frame(width: TabBarMetrics.badgeMaxWidth, alignment: vertical ? .center : .leading)
|
|
297
|
+
.offset(x: vertical ? 0 : Spacing.M, y: vertical ? -10 : -7)
|
|
182
298
|
}
|
|
183
|
-
|
|
184
|
-
MomoText(
|
|
185
|
-
item.label,
|
|
186
|
-
typography: selected ? .labelXsMedium : .descriptionXsRegular,
|
|
187
|
-
color: tintColor,
|
|
188
|
-
textAlign: .center,
|
|
189
|
-
maxLines: 1
|
|
190
|
-
)
|
|
191
|
-
.truncationMode(.tail)
|
|
299
|
+
}
|
|
192
300
|
}
|
|
193
|
-
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
194
|
-
.padding(.horizontal, Spacing.S)
|
|
195
|
-
.padding(.vertical, Spacing.S)
|
|
196
|
-
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
197
|
-
.padding(.horizontal, Spacing.XXS)
|
|
198
|
-
.contentShape(Rectangle())
|
|
199
|
-
.onTapGesture { onClick() }
|
|
200
|
-
.modifier(TabLongPress(action: onLongClick))
|
|
201
301
|
}
|
|
202
302
|
}
|
|
203
303
|
|
|
204
|
-
///
|
|
205
|
-
|
|
206
|
-
|
|
304
|
+
/// Numbers use the error color, text the warning color (Figma Badge round numeric / text); the text
|
|
305
|
+
/// keeps its design size so it fits the 16 height on the Duo displays too.
|
|
306
|
+
private struct TabBadge: View {
|
|
307
|
+
let label: String
|
|
207
308
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
309
|
+
@Environment(\.appTheme) private var theme
|
|
310
|
+
|
|
311
|
+
private var isNumber: Bool {
|
|
312
|
+
let digits = label.hasSuffix("+") ? String(label.dropLast()) : label
|
|
313
|
+
return !digits.isEmpty && digits.allSatisfy { ("0"..."9").contains($0) }
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
var body: some View {
|
|
317
|
+
MomoText(label, typography: .actionXxsBold, color: Colors.black01, maxLines: 1)
|
|
318
|
+
.truncationMode(.tail)
|
|
319
|
+
.environment(\.momoFontScale, FontScale(userScaleRate: 1, useOSScaleRate: false))
|
|
320
|
+
.padding(.horizontal, Spacing.XS)
|
|
321
|
+
.frame(minWidth: 16, maxWidth: TabBarMetrics.badgeMaxWidth, minHeight: 16, maxHeight: 16)
|
|
322
|
+
.background(Capsule().fill(isNumber ? theme.colors.error.primary : theme.colors.warning.primary))
|
|
323
|
+
.overlay(Capsule().strokeBorder(theme.colors.background.surface, lineWidth: 1))
|
|
214
324
|
}
|
|
215
325
|
}
|
|
216
326
|
|
|
217
|
-
// MARK: - Center
|
|
327
|
+
// MARK: - Center action
|
|
218
328
|
|
|
219
|
-
|
|
220
|
-
|
|
329
|
+
/// Center action press: the button shrinks while held; the label stays plain text.
|
|
330
|
+
struct CenterActionStyle: ButtonStyle {
|
|
331
|
+
let size: CGFloat
|
|
332
|
+
let vertical: Bool
|
|
333
|
+
let icon: String
|
|
334
|
+
var iconContent: AnyView? = nil
|
|
335
|
+
var labelContent: AnyView? = nil
|
|
336
|
+
let label: String
|
|
337
|
+
var fixedFontScale = false
|
|
221
338
|
|
|
222
339
|
@Environment(\.appTheme) private var theme
|
|
223
340
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
.
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
.
|
|
235
|
-
|
|
236
|
-
|
|
341
|
+
func makeBody(configuration: Configuration) -> some View {
|
|
342
|
+
let pressed = configuration.isPressed
|
|
343
|
+
VStack(spacing: vertical ? TabBarMetrics.railCtaLabelGap : TabBarMetrics.ctaLabelGap) {
|
|
344
|
+
ZStack {
|
|
345
|
+
// Figma Effect/Popover, one layer per shadow, spread as a shrunk circle:
|
|
346
|
+
// 8% y8 blur 24 spread -12, 4% y12 blur 32 spread -16
|
|
347
|
+
Circle().inset(by: 12).fill(theme.colors.primary)
|
|
348
|
+
.shadow(color: Color.black.opacity(0.08), radius: 12, x: 0, y: 8)
|
|
349
|
+
Circle().inset(by: 16).fill(theme.colors.primary)
|
|
350
|
+
.shadow(color: Color.black.opacity(0.04), radius: 16, x: 0, y: 12)
|
|
351
|
+
Circle().fill(theme.colors.primary)
|
|
352
|
+
if let iconContent {
|
|
353
|
+
iconContent
|
|
354
|
+
} else {
|
|
355
|
+
Icon(source: icon, size: TabBarMetrics.ctaIconSize, color: Colors.black01)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
.frame(width: size, height: size)
|
|
359
|
+
.scaleEffect(pressed ? TabBarMetrics.ctaPressedScale : 1)
|
|
360
|
+
.animation(TabBarMetrics.ctaPressMotion, value: pressed)
|
|
361
|
+
MomoText(
|
|
362
|
+
label,
|
|
363
|
+
typography: vertical ? .labelXsMedium : .labelSMedium,
|
|
364
|
+
color: theme.colors.text.secondary,
|
|
365
|
+
textAlign: .center,
|
|
366
|
+
maxLines: 1
|
|
367
|
+
)
|
|
368
|
+
.truncationMode(.tail)
|
|
369
|
+
.modifier(FixedFontScale(enabled: fixedFontScale))
|
|
370
|
+
.padding(.horizontal, vertical ? Spacing.XS : Spacing.XXS)
|
|
371
|
+
.frame(minHeight: vertical ? nil : TabBarMetrics.ctaLabelHeight)
|
|
372
|
+
.overlay(labelContent?.allowsHitTesting(false))
|
|
237
373
|
}
|
|
238
|
-
|
|
239
|
-
.
|
|
240
|
-
.padding(.vertical, Spacing.S)
|
|
374
|
+
// the whole slot is the hit area, not just the button and label
|
|
375
|
+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
|
|
241
376
|
.contentShape(Rectangle())
|
|
242
|
-
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/// Center action (.Nav/CTA): button rising out of the notch, label under it.
|
|
381
|
+
private struct CenterAction: View {
|
|
382
|
+
let data: BottomTabFloatingButton
|
|
383
|
+
var fixedFontScale = false
|
|
384
|
+
|
|
385
|
+
var body: some View {
|
|
386
|
+
SwiftUI.Button(action: data.onPress) { EmptyView() }
|
|
387
|
+
.buttonStyle(CenterActionStyle(size: TabBarMetrics.ctaSize, vertical: false, icon: data.icon,
|
|
388
|
+
iconContent: data.iconContent, labelContent: data.labelContent,
|
|
389
|
+
label: data.label, fixedFontScale: fixedFontScale))
|
|
390
|
+
.frame(width: TabBarMetrics.ctaSlotWidth, height: TabBarMetrics.ctaSize + TabBarMetrics.ctaLabelGap + TabBarMetrics.ctaLabelHeight)
|
|
391
|
+
.accessibilityLabel(data.label)
|
|
392
|
+
.accessibilityIdentifier(data.label)
|
|
243
393
|
}
|
|
244
394
|
}
|
|
@@ -2,64 +2,68 @@
|
|
|
2
2
|
// CurvedContainer.swift
|
|
3
3
|
// MoMoUIKits
|
|
4
4
|
//
|
|
5
|
-
// SwiftUI mirror of Compose's `CurvedContainer
|
|
6
|
-
//
|
|
7
|
-
// carving a circular cut-out into the tab bar's top edge.
|
|
5
|
+
// SwiftUI mirror of Compose's `CurvedContainer.kt`: the navigation bar container shape, a rounded
|
|
6
|
+
// rectangle with a notch cut into the top edge around the center action, and its floating shadow.
|
|
8
7
|
//
|
|
9
8
|
|
|
10
9
|
import SwiftUI
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var height: CGFloat = 16
|
|
18
|
-
var color: Color = Colors.black01
|
|
11
|
+
/// Rounded container, with the notch dipped into the top edge around `notchCenterX` (from the
|
|
12
|
+
/// leading edge).
|
|
13
|
+
struct NotchedBarShape: Shape {
|
|
14
|
+
var radius: CGFloat
|
|
15
|
+
var notchCenterX: CGFloat?
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
let
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let
|
|
17
|
+
func path(in rect: CGRect) -> Path {
|
|
18
|
+
let r = min(radius, rect.height / 2, rect.width / 2)
|
|
19
|
+
guard let cx = notchCenterX else {
|
|
20
|
+
return Path(roundedRect: rect, cornerRadius: r)
|
|
21
|
+
}
|
|
22
|
+
let w = rect.width
|
|
23
|
+
let h = rect.height
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.
|
|
25
|
+
var path = Path()
|
|
26
|
+
path.move(to: CGPoint(x: r, y: 0))
|
|
27
|
+
path.addLine(to: CGPoint(x: cx - TabBarMetrics.notchHalfWidth, y: 0))
|
|
28
|
+
for curve in TabBarMetrics.notchCurves {
|
|
29
|
+
path.addCurve(
|
|
30
|
+
to: CGPoint(x: cx + curve[2].x, y: curve[2].y),
|
|
31
|
+
control1: CGPoint(x: cx + curve[0].x, y: curve[0].y),
|
|
32
|
+
control2: CGPoint(x: cx + curve[1].x, y: curve[1].y)
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
path.addLine(to: CGPoint(x: w - r, y: 0))
|
|
36
|
+
path.addRelativeArc(center: CGPoint(x: w - r, y: r), radius: r, startAngle: .degrees(-90), delta: .degrees(90))
|
|
37
|
+
path.addLine(to: CGPoint(x: w, y: h - r))
|
|
38
|
+
path.addRelativeArc(center: CGPoint(x: w - r, y: h - r), radius: r, startAngle: .degrees(0), delta: .degrees(90))
|
|
39
|
+
path.addLine(to: CGPoint(x: r, y: h))
|
|
40
|
+
path.addRelativeArc(center: CGPoint(x: r, y: h - r), radius: r, startAngle: .degrees(90), delta: .degrees(90))
|
|
41
|
+
path.addLine(to: CGPoint(x: 0, y: r))
|
|
42
|
+
path.addRelativeArc(center: CGPoint(x: r, y: r), radius: r, startAngle: .degrees(180), delta: .degrees(90))
|
|
43
|
+
path.closeSubpath()
|
|
44
|
+
return path.offsetBy(dx: rect.minX, dy: rect.minY)
|
|
32
45
|
}
|
|
33
46
|
}
|
|
34
47
|
|
|
35
|
-
///
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
let circleOverTop: CGFloat
|
|
39
|
-
let centerX: CGFloat
|
|
40
|
-
let circleOverR: CGFloat
|
|
41
|
-
let width: CGFloat
|
|
48
|
+
/// Navigation bar container: surface fill with the floating shadow following the shape.
|
|
49
|
+
struct TabBarContainer<S: Shape>: ViewModifier {
|
|
50
|
+
let shape: S
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
var path = Path()
|
|
45
|
-
path.move(to: CGPoint(x: 0, y: circleOverTop))
|
|
46
|
-
path.addLine(to: CGPoint(x: centerX - circleOverR - 40, y: circleOverTop))
|
|
52
|
+
@Environment(\.appTheme) private var theme
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
func body(content: Content) -> some View {
|
|
55
|
+
content.background(
|
|
56
|
+
// Figma Shadow/floating, one layer per shadow so they don't shadow each other:
|
|
57
|
+
// 12% blur 24, then 4% blur 32 spread -16 cast from the shape shrunk by 16
|
|
58
|
+
ZStack {
|
|
59
|
+
shape.fill(theme.colors.background.surface)
|
|
60
|
+
.padding(16)
|
|
61
|
+
.shadow(color: Color.black.opacity(0.04), radius: 16, x: 0, y: 12)
|
|
62
|
+
shape.fill(theme.colors.background.surface)
|
|
63
|
+
.shadow(color: Color.black.opacity(0.12), radius: 12)
|
|
64
|
+
shape.fill(theme.colors.background.surface)
|
|
65
|
+
}
|
|
66
|
+
.allowsHitTesting(false)
|
|
57
67
|
)
|
|
58
|
-
|
|
59
|
-
path.addLine(to: CGPoint(x: width, y: circleOverTop))
|
|
60
|
-
path.addLine(to: CGPoint(x: width, y: 60))
|
|
61
|
-
path.addLine(to: CGPoint(x: 0, y: 60))
|
|
62
|
-
path.closeSubpath()
|
|
63
|
-
return path
|
|
64
68
|
}
|
|
65
69
|
}
|