@momo-kits/native-kits 0.168.1-beta.4 → 0.168.1-beta.40
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 +15 -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 +16 -4
- package/ios/Input/InputPhoneNumber.swift +1 -3
- package/ios/Input/InputSearch.swift +1 -2
- package/ios/Input/InputTextArea.swift +8 -4
- package/ios/InputMoney/InputMoney.swift +6 -7
- package/ios/Layout/ModalLayout.swift +152 -0
- package/ios/Layout/ScreenLayout.swift +77 -18
- package/ios/Navigation/BottomSheet.swift +56 -53
- 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/DuoBarCompression.swift +2 -3
- package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
- package/ios/Navigation/Component/HeaderBackground.swift +22 -1
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/Component/SnackBar.swift +4 -0
- package/ios/Navigation/ModalScreen.swift +20 -5
- package/ios/Navigation/StackScreen.swift +6 -8
- package/ios/Popup/PopupDisplay.swift +6 -4
- package/ios/Popup/PopupInput.swift +6 -4
- package/ios/Popup/PopupLayout.swift +17 -11
- package/ios/Popup/PopupNotify.swift +32 -25
- 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 +88 -14
- package/ios/Typography/Typography.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/package.json +1 -1
- package/publish.sh +2 -33
- package/ios/Typography/FontScaleStore.swift +0 -58
- package/ios/Typography/KitDesignSystem.swift +0 -17
|
@@ -53,10 +53,9 @@ public struct BottomTab: View {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
private var bottomInset: CGFloat { safeAreaBottomInset() }
|
|
56
|
-
// the
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
56
|
+
// the bars float over the content (tab screens keep clear of them through duoTabBarInsets) or sit
|
|
57
|
+
// in the side strip, so only the home indicator is kept clear
|
|
58
|
+
private var reservedBottom: CGFloat { layout.insets.bottom }
|
|
60
59
|
|
|
61
60
|
private var compression: DuoBarCompression {
|
|
62
61
|
DuoBarCompression.resolve(
|
|
@@ -104,18 +103,13 @@ public struct BottomTab: View {
|
|
|
104
103
|
compression: compression
|
|
105
104
|
)
|
|
106
105
|
} else {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
)
|
|
115
|
-
theme.colors.background.surface
|
|
116
|
-
.frame(height: bottomInset + Spacing.S)
|
|
117
|
-
.ignoresSafeArea(edges: .horizontal)
|
|
118
|
-
}
|
|
106
|
+
BottomTabBar(
|
|
107
|
+
items: items,
|
|
108
|
+
floatingButton: floatingButton,
|
|
109
|
+
selectedIndex: selectedIndex,
|
|
110
|
+
onTabSelected: selectTab,
|
|
111
|
+
bottomInset: bottomInset
|
|
112
|
+
)
|
|
119
113
|
}
|
|
120
114
|
}
|
|
121
115
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
@@ -137,6 +131,7 @@ public struct BottomTab: View {
|
|
|
137
131
|
}
|
|
138
132
|
|
|
139
133
|
private func selectTab(_ index: Int) {
|
|
134
|
+
navigator.maxApi?.triggerEventVibration("light")
|
|
140
135
|
let switchTab = { if index != selectedIndex { selectedIndex = index } }
|
|
141
136
|
if let onTabPress { onTabPress(index, switchTab) } else { switchTab() }
|
|
142
137
|
}
|
|
@@ -208,11 +203,11 @@ private struct TabHost: UIViewControllerRepresentable {
|
|
|
208
203
|
|
|
209
204
|
private final class TabController: UIViewController {
|
|
210
205
|
private final class Tab {
|
|
211
|
-
let motion = TabMotion()
|
|
212
206
|
var host: UIHostingController<AnyView>!
|
|
213
207
|
}
|
|
214
208
|
|
|
215
|
-
|
|
209
|
+
/// The tab switch: the screens slide in index order over 280ms, CSS `ease`.
|
|
210
|
+
private static let switchDuration: TimeInterval = 0.28
|
|
216
211
|
|
|
217
212
|
private var tabs: [Int: Tab] = [:]
|
|
218
213
|
private var selectedIndex: Int?
|
|
@@ -226,7 +221,7 @@ private final class TabController: UIViewController {
|
|
|
226
221
|
|
|
227
222
|
override func viewDidLayoutSubviews() {
|
|
228
223
|
super.viewDidLayoutSubviews()
|
|
229
|
-
for subview in view.subviews { subview
|
|
224
|
+
for subview in view.subviews { place(subview) }
|
|
230
225
|
}
|
|
231
226
|
|
|
232
227
|
func update(
|
|
@@ -243,33 +238,43 @@ private final class TabController: UIViewController {
|
|
|
243
238
|
}
|
|
244
239
|
if let selectedIndex, tabs[selectedIndex] == nil { self.selectedIndex = nil }
|
|
245
240
|
// hidden tabs too, so a tab coming back already shows the latest items and environment
|
|
246
|
-
for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex
|
|
241
|
+
for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex) }
|
|
247
242
|
guard (0..<count).contains(index), index != selectedIndex else { return }
|
|
248
243
|
|
|
249
|
-
let
|
|
244
|
+
let previousIndex = selectedIndex
|
|
245
|
+
let previous = previousIndex.flatMap { tabs[$0] }
|
|
250
246
|
selectedIndex = index
|
|
251
247
|
let selected = tabs[index] ?? makeTab(index)
|
|
248
|
+
// a tab selected again while it leaves carries on from where it is
|
|
249
|
+
let entering = selected.host.view.superview == nil
|
|
252
250
|
attach(selected)
|
|
253
251
|
|
|
254
|
-
guard let previous, view.window != nil else {
|
|
255
|
-
selected.
|
|
252
|
+
guard let previous, let previousIndex, view.window != nil else {
|
|
253
|
+
selected.host.view.transform = .identity
|
|
256
254
|
previous.map(leave)
|
|
257
255
|
return
|
|
258
256
|
}
|
|
259
257
|
previous.host.view.isUserInteractionEnabled = false
|
|
260
|
-
|
|
258
|
+
let offset = index > previousIndex ? view.bounds.width : -view.bounds.width
|
|
259
|
+
if entering { selected.host.view.transform = CGAffineTransform(translationX: offset, y: 0) }
|
|
260
|
+
// a frame at the start values first, so a tab created just now slides in with its content
|
|
261
261
|
DispatchQueue.main.async {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
262
|
+
let animator = UIViewPropertyAnimator(
|
|
263
|
+
duration: Self.switchDuration,
|
|
264
|
+
controlPoint1: CGPoint(x: 0.25, y: 0.1),
|
|
265
|
+
controlPoint2: CGPoint(x: 0.25, y: 1)
|
|
266
|
+
) {
|
|
267
|
+
selected.host.view.transform = .identity
|
|
268
|
+
previous.host.view.transform = CGAffineTransform(translationX: -offset, y: 0)
|
|
269
|
+
}
|
|
270
|
+
animator.addCompletion { [weak self] _ in self?.leave(previous) }
|
|
271
|
+
animator.startAnimation()
|
|
267
272
|
}
|
|
268
273
|
}
|
|
269
274
|
|
|
270
275
|
private func makeTab(_ index: Int) -> Tab {
|
|
271
276
|
let tab = Tab()
|
|
272
|
-
let host = UIHostingController(rootView: rootView(index
|
|
277
|
+
let host = UIHostingController(rootView: rootView(index))
|
|
273
278
|
host.view.backgroundColor = .clear
|
|
274
279
|
addChild(host)
|
|
275
280
|
host.didMove(toParent: self)
|
|
@@ -278,14 +283,20 @@ private final class TabController: UIViewController {
|
|
|
278
283
|
return tab
|
|
279
284
|
}
|
|
280
285
|
|
|
281
|
-
private func rootView(_ index: Int
|
|
282
|
-
AnyView(
|
|
286
|
+
private func rootView(_ index: Int) -> AnyView {
|
|
287
|
+
AnyView(content(index).environment(\.self, environment))
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/// Bounds and center, a sliding tab carries a transform that frame doesn't work with.
|
|
291
|
+
private func place(_ subview: UIView) {
|
|
292
|
+
subview.bounds = view.bounds
|
|
293
|
+
subview.center = CGPoint(x: view.bounds.midX, y: view.bounds.midY)
|
|
283
294
|
}
|
|
284
295
|
|
|
285
296
|
private func attach(_ tab: Tab) {
|
|
286
297
|
let hostView: UIView = tab.host.view
|
|
287
298
|
hostView.isUserInteractionEnabled = true
|
|
288
|
-
hostView
|
|
299
|
+
place(hostView)
|
|
289
300
|
if hostView.superview === view {
|
|
290
301
|
view.bringSubviewToFront(hostView)
|
|
291
302
|
} else {
|
|
@@ -297,6 +308,7 @@ private final class TabController: UIViewController {
|
|
|
297
308
|
private func leave(_ tab: Tab) {
|
|
298
309
|
guard selectedIndex.flatMap({ tabs[$0] }) !== tab else { return }
|
|
299
310
|
tab.host.view.removeFromSuperview()
|
|
311
|
+
tab.host.view.transform = .identity
|
|
300
312
|
}
|
|
301
313
|
|
|
302
314
|
private func tearDown(_ tab: Tab) {
|
|
@@ -306,27 +318,9 @@ private final class TabController: UIViewController {
|
|
|
306
318
|
}
|
|
307
319
|
}
|
|
308
320
|
|
|
309
|
-
private final class TabMotion: ObservableObject {
|
|
310
|
-
@Published var visible = false
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/// The tab switch: 0.97 scale + fade over 200ms, both ways (Compose's tab enter / exit transitions).
|
|
314
|
-
private struct TabCard: View {
|
|
315
|
-
@ObservedObject var motion: TabMotion
|
|
316
|
-
let content: AnyView
|
|
317
|
-
|
|
318
|
-
var body: some View {
|
|
319
|
-
content
|
|
320
|
-
.opacity(motion.visible ? 1 : 0)
|
|
321
|
-
.scaleEffect(motion.visible ? 1 : 0.97)
|
|
322
|
-
.animation(.easeInOut(duration: 0.2), value: motion.visible)
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
321
|
/// Bottom safe-area inset (home indicator).
|
|
327
322
|
private func safeAreaBottomInset() -> CGFloat {
|
|
328
|
-
|
|
323
|
+
UIApplication.shared.connectedScenes
|
|
329
324
|
.compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
|
|
330
325
|
.first ?? 0
|
|
331
|
-
return min(bottomInset, 21)
|
|
332
326
|
}
|
|
@@ -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
|
}
|