@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
|
@@ -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,178 +49,344 @@ 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
|
|
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())
|
|
57
77
|
}
|
|
58
|
-
}
|
|
59
78
|
|
|
60
|
-
|
|
61
|
-
let BOTTOM_TAB_BAR_HEIGHT: CGFloat = 64
|
|
79
|
+
}
|
|
62
80
|
|
|
63
81
|
// MARK: - Tab bar
|
|
64
82
|
|
|
83
|
+
/// Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
|
|
65
84
|
struct BottomTabBar: View {
|
|
66
85
|
let items: [BottomTabItem]
|
|
67
86
|
let floatingButton: BottomTabFloatingButton?
|
|
68
87
|
let selectedIndex: Int
|
|
69
88
|
let onTabSelected: (Int) -> Void
|
|
89
|
+
let bottomInset: CGFloat
|
|
70
90
|
|
|
71
91
|
@Environment(\.screenLayout) private var layout
|
|
72
|
-
@Environment(\.appTheme) private var theme
|
|
73
92
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
93
|
+
var body: some View {
|
|
94
|
+
HorizontalTabBar(
|
|
95
|
+
items: items,
|
|
96
|
+
floatingButton: floatingButton,
|
|
97
|
+
selectedIndex: selectedIndex,
|
|
98
|
+
onTabSelected: onTabSelected,
|
|
99
|
+
width: TabBarMetrics.horizontalBarWidth(layout)
|
|
100
|
+
)
|
|
101
|
+
.padding(.bottom, TabBarMetrics.bottomGap(bottomInset))
|
|
102
|
+
.frame(maxWidth: .infinity)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
77
105
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
106
|
+
/// Horizontal navigation bar: floating container, items split evenly; Special type puts the center
|
|
107
|
+
/// action in a notch in the middle, rising ctaLift above the container. One active indicator slides
|
|
108
|
+
/// behind the selected item.
|
|
109
|
+
struct HorizontalTabBar: View {
|
|
110
|
+
let items: [BottomTabItem]
|
|
111
|
+
let floatingButton: BottomTabFloatingButton?
|
|
112
|
+
let selectedIndex: Int
|
|
113
|
+
let onTabSelected: (Int) -> Void
|
|
114
|
+
let width: CGFloat
|
|
115
|
+
var fixedFontScale = false
|
|
116
|
+
|
|
117
|
+
private var cta: BottomTabFloatingButton? {
|
|
118
|
+
TabBarMetrics.hasCenterAction(floatingButton, tabCount: items.count) ? floatingButton : nil
|
|
83
119
|
}
|
|
84
120
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
121
|
+
/// Items share what the padding, gaps and center action slot leave.
|
|
122
|
+
private var itemWidth: CGFloat {
|
|
123
|
+
let slots = CGFloat(items.count + (cta == nil ? 0 : 1))
|
|
124
|
+
let content = width - 2 * TabBarMetrics.paddingHorizontal - (slots - 1) * TabBarMetrics.itemGap
|
|
125
|
+
return max((content - (cta == nil ? 0 : TabBarMetrics.ctaSlotWidth)) / CGFloat(max(items.count, 1)), 0)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private func itemX(_ index: Int) -> CGFloat {
|
|
129
|
+
let afterCta = cta != nil && index >= items.count / 2
|
|
130
|
+
return TabBarMetrics.paddingHorizontal + CGFloat(index) * (itemWidth + TabBarMetrics.itemGap)
|
|
131
|
+
+ (afterCta ? TabBarMetrics.ctaSlotWidth + TabBarMetrics.itemGap : 0)
|
|
88
132
|
}
|
|
89
133
|
|
|
90
134
|
var body: some View {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
135
|
+
let shape = NotchedBarShape(radius: TabBarMetrics.height / 2, notchCenterX: cta == nil ? nil : width / 2)
|
|
136
|
+
ZStack(alignment: .top) {
|
|
137
|
+
ZStack(alignment: .topLeading) {
|
|
138
|
+
ActiveIndicator(radius: TabBarMetrics.indicatorRadius)
|
|
139
|
+
.frame(width: itemWidth, height: TabBarMetrics.indicatorHeight)
|
|
140
|
+
.offset(x: itemX(selectedIndex), y: TabBarMetrics.paddingVertical)
|
|
141
|
+
.animation(TabBarMetrics.indicatorMotion, value: selectedIndex)
|
|
142
|
+
|
|
143
|
+
HStack(spacing: TabBarMetrics.itemGap) {
|
|
144
|
+
ForEach(items.indices, id: \.self) { index in
|
|
145
|
+
if cta != nil && index == items.count / 2 {
|
|
146
|
+
Color.clear.frame(width: TabBarMetrics.ctaSlotWidth)
|
|
147
|
+
}
|
|
148
|
+
SwiftUI.Button { onTabSelected(index) } label: {
|
|
149
|
+
VStack(spacing: Spacing.XXS) {
|
|
150
|
+
TabItemContent(item: items[index], selected: index == selectedIndex, fixedFontScale: fixedFontScale)
|
|
151
|
+
}
|
|
152
|
+
.frame(width: itemWidth)
|
|
153
|
+
.contentShape(Rectangle())
|
|
154
|
+
}
|
|
155
|
+
.buttonStyle(.plain)
|
|
156
|
+
.accessibilityLabel(items[index].label)
|
|
157
|
+
.accessibilityAddTraits(index == selectedIndex ? .isSelected : [])
|
|
158
|
+
}
|
|
101
159
|
}
|
|
160
|
+
.padding(.horizontal, TabBarMetrics.paddingHorizontal)
|
|
161
|
+
.padding(.vertical, TabBarMetrics.paddingVertical)
|
|
102
162
|
}
|
|
103
|
-
.frame(
|
|
104
|
-
.
|
|
105
|
-
.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
RoundedRectangle(cornerRadius: 2)
|
|
109
|
-
.fill(theme.colors.primary)
|
|
110
|
-
.frame(width: 44, height: 2)
|
|
111
|
-
.offset(x: indicatorOffset, y: -BOTTOM_TAB_BAR_HEIGHT + 2)
|
|
112
|
-
.animation(.easeInOut(duration: 0.25), value: selectedIndex)
|
|
113
|
-
|
|
114
|
-
// Top shadow.
|
|
115
|
-
LinearGradient(
|
|
116
|
-
colors: [Color.black.opacity(0.05), .clear],
|
|
117
|
-
startPoint: .bottom,
|
|
118
|
-
endPoint: .top
|
|
119
|
-
)
|
|
120
|
-
.frame(height: 6)
|
|
121
|
-
.frame(maxWidth: .infinity)
|
|
122
|
-
.offset(y: -BOTTOM_TAB_BAR_HEIGHT)
|
|
163
|
+
.frame(width: width, height: TabBarMetrics.height, alignment: .topLeading)
|
|
164
|
+
.modifier(TabBarContainer(shape: shape))
|
|
165
|
+
.accessibilityElement(children: .contain)
|
|
166
|
+
.accessibilityIdentifier("bottom_tab_bar")
|
|
167
|
+
.padding(.top, cta == nil ? 0 : TabBarMetrics.ctaLift)
|
|
123
168
|
|
|
124
|
-
if let
|
|
125
|
-
|
|
169
|
+
if let cta {
|
|
170
|
+
CenterAction(data: cta, fixedFontScale: fixedFontScale)
|
|
126
171
|
}
|
|
127
172
|
}
|
|
173
|
+
.frame(width: width)
|
|
128
174
|
}
|
|
175
|
+
}
|
|
129
176
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
177
|
+
/// One active indicator per bar: Background/tonal with its inner light (white 12% from below) and
|
|
178
|
+
/// tint (primary 12% from above).
|
|
179
|
+
struct ActiveIndicator: View {
|
|
180
|
+
let radius: CGFloat
|
|
181
|
+
|
|
182
|
+
@Environment(\.appTheme) private var theme
|
|
183
|
+
|
|
184
|
+
var body: some View {
|
|
185
|
+
let shape = RoundedRectangle(cornerRadius: radius)
|
|
186
|
+
shape
|
|
187
|
+
.fill(theme.colors.background.tonal)
|
|
188
|
+
// inner shadows: primary 12% falling 1 from the top edge, white 12% rising 2 from the bottom one
|
|
189
|
+
.overlay(
|
|
190
|
+
LinearGradient(
|
|
191
|
+
stops: [
|
|
192
|
+
.init(color: theme.colors.primary.opacity(0.12), location: 0),
|
|
193
|
+
.init(color: theme.colors.primary.opacity(0), location: 0.1),
|
|
194
|
+
.init(color: Color.white.opacity(0), location: 0.85),
|
|
195
|
+
.init(color: Color.white.opacity(0.12), location: 1),
|
|
196
|
+
],
|
|
197
|
+
startPoint: .top,
|
|
198
|
+
endPoint: .bottom
|
|
199
|
+
)
|
|
200
|
+
.clipShape(shape)
|
|
137
201
|
)
|
|
138
|
-
.
|
|
139
|
-
|
|
202
|
+
.allowsHitTesting(false)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/// Like the system tab bar, text keeps its design size instead of growing with the wide Duo displays.
|
|
207
|
+
struct FixedFontScale: ViewModifier {
|
|
208
|
+
let enabled: Bool
|
|
209
|
+
|
|
210
|
+
@Environment(\.momoFontScale) private var fontScale
|
|
211
|
+
|
|
212
|
+
func body(content: Content) -> some View {
|
|
213
|
+
content.environment(\.momoFontScale, enabled ? FontScale(userScaleRate: 1, useOSScaleRate: false) : fontScale)
|
|
140
214
|
}
|
|
141
215
|
}
|
|
142
216
|
|
|
143
217
|
// MARK: - Tab item
|
|
144
218
|
|
|
145
|
-
|
|
219
|
+
/// Icon in its indicator slot, label under it. The bar slides one shared active indicator behind the
|
|
220
|
+
/// slots; the icon and label tint cross-fade on focus.
|
|
221
|
+
struct TabItemContent: View {
|
|
146
222
|
let item: BottomTabItem
|
|
147
223
|
let selected: Bool
|
|
148
|
-
|
|
224
|
+
var vertical = false
|
|
225
|
+
var showLabel = true
|
|
226
|
+
var fixedFontScale = false
|
|
149
227
|
|
|
150
228
|
@Environment(\.appTheme) private var theme
|
|
151
229
|
|
|
152
|
-
|
|
230
|
+
var body: some View {
|
|
231
|
+
TabIcon(item: item, selected: selected, vertical: vertical)
|
|
232
|
+
.frame(height: vertical ? TabBarMetrics.railIndicatorHeight : TabBarMetrics.indicatorHeight)
|
|
233
|
+
if showLabel {
|
|
234
|
+
let label = ZStack {
|
|
235
|
+
labelText(theme.colors.text.secondary).opacity(selected ? 0 : 1)
|
|
236
|
+
labelText(theme.colors.primary).opacity(selected ? 1 : 0)
|
|
237
|
+
}
|
|
238
|
+
.animation(TabBarMetrics.tintMotion, value: selected)
|
|
239
|
+
.frame(maxWidth: vertical ? nil : .infinity)
|
|
240
|
+
label.modifier(FixedFontScale(enabled: fixedFontScale))
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
private func labelText(_ color: Color) -> some View {
|
|
245
|
+
MomoText(
|
|
246
|
+
item.label,
|
|
247
|
+
typography: vertical ? .labelXsMedium : .labelSMedium,
|
|
248
|
+
color: color,
|
|
249
|
+
textAlign: .center,
|
|
250
|
+
maxLines: 1
|
|
251
|
+
)
|
|
252
|
+
.truncationMode(.tail)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
153
255
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
256
|
+
/// Badge value shown on a tab: nil hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
|
|
257
|
+
func tabBadgeLabel(_ item: BottomTabItem) -> String? {
|
|
258
|
+
guard let label = item.badgeLabel else { return item.showDot ? "" : nil }
|
|
259
|
+
if label.isEmpty { return "" }
|
|
260
|
+
if label.allSatisfy({ ("0"..."9").contains($0) }) {
|
|
261
|
+
let value = Int(label) ?? Int.max
|
|
262
|
+
if value == 0 { return item.showDot ? "" : nil }
|
|
263
|
+
return value > 99 ? "99+" : label
|
|
159
264
|
}
|
|
265
|
+
return label
|
|
266
|
+
}
|
|
160
267
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
color: tintColor,
|
|
170
|
-
textAlign: .center,
|
|
171
|
-
maxLines: 1
|
|
172
|
-
)
|
|
173
|
-
.truncationMode(.tail)
|
|
174
|
-
}
|
|
175
|
-
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
176
|
-
.padding(.horizontal, Spacing.S)
|
|
177
|
-
.padding(.vertical, Spacing.S)
|
|
268
|
+
/// 24 icon, active and inactive tints cross-faded; badges hang off it: dot at 16/-2, label badge at
|
|
269
|
+
/// 12/-7 growing right, or centered over the icon at -10 on the rail.
|
|
270
|
+
struct TabIcon: View {
|
|
271
|
+
let item: BottomTabItem
|
|
272
|
+
let selected: Bool
|
|
273
|
+
var vertical = false
|
|
274
|
+
|
|
275
|
+
@Environment(\.appTheme) private var theme
|
|
178
276
|
|
|
179
|
-
|
|
180
|
-
|
|
277
|
+
var body: some View {
|
|
278
|
+
ZStack {
|
|
279
|
+
Icon(source: item.icon, size: TabBarMetrics.iconSize, color: theme.colors.text.secondary)
|
|
280
|
+
.opacity(selected ? 0 : 1)
|
|
281
|
+
Icon(source: item.icon, size: TabBarMetrics.iconSize, color: theme.colors.primary)
|
|
282
|
+
.opacity(selected ? 1 : 0)
|
|
283
|
+
}
|
|
284
|
+
.animation(TabBarMetrics.tintMotion, value: selected)
|
|
285
|
+
.frame(width: TabBarMetrics.iconSize, height: TabBarMetrics.iconSize)
|
|
286
|
+
.overlay(alignment: vertical ? .top : .topLeading) {
|
|
287
|
+
if let badge = tabBadgeLabel(item) {
|
|
288
|
+
if badge.isEmpty {
|
|
181
289
|
BadgeDot(size: .small)
|
|
182
|
-
.offset(x: -
|
|
290
|
+
.offset(x: vertical ? 16 - (TabBarMetrics.iconSize - 10) / 2 : 16, y: -Spacing.XXS)
|
|
183
291
|
} else {
|
|
184
|
-
|
|
185
|
-
.
|
|
292
|
+
TabBadge(label: badge)
|
|
293
|
+
.fixedSize()
|
|
294
|
+
.frame(width: TabBarMetrics.badgeMaxWidth, alignment: vertical ? .center : .leading)
|
|
295
|
+
.offset(x: vertical ? 0 : Spacing.M, y: vertical ? -10 : -7)
|
|
186
296
|
}
|
|
187
|
-
} else if item.showDot {
|
|
188
|
-
BadgeDot(size: .small)
|
|
189
|
-
.offset(x: -Spacing.S, y: Spacing.XS)
|
|
190
297
|
}
|
|
191
298
|
}
|
|
192
|
-
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
193
|
-
.padding(.horizontal, Spacing.XXS)
|
|
194
|
-
.contentShape(Rectangle())
|
|
195
|
-
.onTapGesture { onClick() }
|
|
196
299
|
}
|
|
197
300
|
}
|
|
198
301
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
private struct
|
|
202
|
-
let
|
|
302
|
+
/// Numbers use the error color, text the warning color (Figma Badge round numeric / text); the text
|
|
303
|
+
/// keeps its design size so it fits the 16 height on the Duo displays too.
|
|
304
|
+
private struct TabBadge: View {
|
|
305
|
+
let label: String
|
|
203
306
|
|
|
204
307
|
@Environment(\.appTheme) private var theme
|
|
205
308
|
|
|
309
|
+
private var isNumber: Bool {
|
|
310
|
+
let digits = label.hasSuffix("+") ? String(label.dropLast()) : label
|
|
311
|
+
return !digits.isEmpty && digits.allSatisfy { ("0"..."9").contains($0) }
|
|
312
|
+
}
|
|
313
|
+
|
|
206
314
|
var body: some View {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
315
|
+
MomoText(label, typography: .actionXxsBold, color: Colors.black01, maxLines: 1)
|
|
316
|
+
.truncationMode(.tail)
|
|
317
|
+
.environment(\.momoFontScale, FontScale(userScaleRate: 1, useOSScaleRate: false))
|
|
318
|
+
.padding(.horizontal, Spacing.XS)
|
|
319
|
+
.frame(minWidth: 16, maxWidth: TabBarMetrics.badgeMaxWidth, minHeight: 16, maxHeight: 16)
|
|
320
|
+
.background(Capsule().fill(isNumber ? theme.colors.error.primary : theme.colors.warning.primary))
|
|
321
|
+
.overlay(Capsule().strokeBorder(theme.colors.background.surface, lineWidth: 1))
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// MARK: - Center action
|
|
326
|
+
|
|
327
|
+
/// Center action press: the button shrinks while held; the label stays plain text.
|
|
328
|
+
struct CenterActionStyle: ButtonStyle {
|
|
329
|
+
let size: CGFloat
|
|
330
|
+
let vertical: Bool
|
|
331
|
+
let icon: String
|
|
332
|
+
var iconContent: AnyView? = nil
|
|
333
|
+
var labelContent: AnyView? = nil
|
|
334
|
+
let label: String
|
|
335
|
+
var fixedFontScale = false
|
|
336
|
+
|
|
337
|
+
@Environment(\.appTheme) private var theme
|
|
338
|
+
|
|
339
|
+
func makeBody(configuration: Configuration) -> some View {
|
|
340
|
+
let pressed = configuration.isPressed
|
|
341
|
+
VStack(spacing: vertical ? TabBarMetrics.railCtaLabelGap : TabBarMetrics.ctaLabelGap) {
|
|
342
|
+
ZStack {
|
|
343
|
+
// Figma Effect/Popover, one layer per shadow, spread as a shrunk circle:
|
|
344
|
+
// 8% y8 blur 24 spread -12, 4% y12 blur 32 spread -16
|
|
345
|
+
Circle().inset(by: 12).fill(theme.colors.primary)
|
|
346
|
+
.shadow(color: Color.black.opacity(0.08), radius: 12, x: 0, y: 8)
|
|
347
|
+
Circle().inset(by: 16).fill(theme.colors.primary)
|
|
348
|
+
.shadow(color: Color.black.opacity(0.04), radius: 16, x: 0, y: 12)
|
|
349
|
+
Circle().fill(theme.colors.primary)
|
|
350
|
+
if let iconContent {
|
|
351
|
+
iconContent
|
|
352
|
+
} else {
|
|
353
|
+
Icon(source: icon, size: TabBarMetrics.ctaIconSize, color: Colors.black01)
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
.frame(width: size, height: size)
|
|
357
|
+
.scaleEffect(pressed ? TabBarMetrics.ctaPressedScale : 1)
|
|
358
|
+
.animation(TabBarMetrics.ctaPressMotion, value: pressed)
|
|
359
|
+
MomoText(
|
|
360
|
+
label,
|
|
361
|
+
typography: vertical ? .labelXsMedium : .labelSMedium,
|
|
362
|
+
color: theme.colors.text.secondary,
|
|
363
|
+
textAlign: .center,
|
|
364
|
+
maxLines: 1
|
|
365
|
+
)
|
|
366
|
+
.truncationMode(.tail)
|
|
367
|
+
.modifier(FixedFontScale(enabled: fixedFontScale))
|
|
368
|
+
.padding(.horizontal, vertical ? Spacing.XS : Spacing.XXS)
|
|
369
|
+
.frame(minHeight: vertical ? nil : TabBarMetrics.ctaLabelHeight)
|
|
370
|
+
.overlay(labelContent?.allowsHitTesting(false))
|
|
219
371
|
}
|
|
220
|
-
|
|
221
|
-
.
|
|
222
|
-
.padding(.vertical, Spacing.S)
|
|
372
|
+
// the whole slot is the hit area, not just the button and label
|
|
373
|
+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
|
|
223
374
|
.contentShape(Rectangle())
|
|
224
|
-
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/// Center action (.Nav/CTA): button rising out of the notch, label under it.
|
|
379
|
+
private struct CenterAction: View {
|
|
380
|
+
let data: BottomTabFloatingButton
|
|
381
|
+
var fixedFontScale = false
|
|
382
|
+
|
|
383
|
+
var body: some View {
|
|
384
|
+
SwiftUI.Button(action: data.onPress) { EmptyView() }
|
|
385
|
+
.buttonStyle(CenterActionStyle(size: TabBarMetrics.ctaSize, vertical: false, icon: data.icon,
|
|
386
|
+
iconContent: data.iconContent, labelContent: data.labelContent,
|
|
387
|
+
label: data.label, fixedFontScale: fixedFontScale))
|
|
388
|
+
.frame(width: TabBarMetrics.ctaSlotWidth, height: TabBarMetrics.ctaSize + TabBarMetrics.ctaLabelGap + TabBarMetrics.ctaLabelHeight)
|
|
389
|
+
.accessibilityLabel(data.label)
|
|
390
|
+
.accessibilityIdentifier(data.label)
|
|
225
391
|
}
|
|
226
392
|
}
|
|
@@ -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
|
}
|