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