@momo-kits/native-kits 0.168.1-beta.32-debug → 0.168.1-beta.33-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 +1 -0
- package/compose/build.gradle.kts +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +2 -3
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +9 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +26 -34
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +167 -319
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +71 -79
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +380 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +326 -93
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +2 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +1 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +2 -3
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
- package/ios/Input/Input.swift +3 -1
- package/ios/Input/InputTextArea.swift +3 -1
- package/ios/Navigation/BottomTab/BottomTab.swift +67 -48
- package/ios/Navigation/BottomTab/BottomTabBar.swift +131 -281
- package/ios/Navigation/BottomTab/CurvedContainer.swift +47 -51
- package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +364 -0
- package/ios/Navigation/BottomTab/DuoTabBar.swift +292 -72
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/StackScreen.swift +1 -3
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +59 -272
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +90 -0
- package/package.json +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -106
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +0 -88
- package/ios-demo/Resources/tabbar_scan_qr_button.json +0 -1
- package/ios-demo/Resources/tabbar_scan_qr_label.json +0 -1
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// MoMoUIKits
|
|
4
4
|
//
|
|
5
5
|
// SwiftUI mirror of Compose's `navigation/bottomtab/BottomTabBar.kt`.
|
|
6
|
-
//
|
|
7
|
-
//
|
|
6
|
+
// Renders the row of tab items, an animated selection indicator, a top shadow,
|
|
7
|
+
// badges/dots, and an optional center floating button (with the curved notch).
|
|
8
8
|
//
|
|
9
9
|
|
|
10
10
|
import SwiftUI
|
|
@@ -49,346 +49,196 @@ 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?
|
|
56
52
|
|
|
57
53
|
public init(icon: String, label: String, onPress: @escaping () -> Void) {
|
|
58
54
|
self.icon = icon
|
|
59
55
|
self.label = label
|
|
60
56
|
self.onPress = onPress
|
|
61
|
-
self.iconContent = nil
|
|
62
|
-
self.labelContent = nil
|
|
63
57
|
}
|
|
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
|
-
|
|
79
58
|
}
|
|
80
59
|
|
|
81
|
-
let
|
|
60
|
+
let bottomTabFloatingButtonWidth: CGFloat = 75
|
|
61
|
+
let BOTTOM_TAB_BAR_HEIGHT: CGFloat = 64
|
|
82
62
|
|
|
83
63
|
// MARK: - Tab bar
|
|
84
64
|
|
|
85
|
-
/// Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
|
|
86
65
|
struct BottomTabBar: View {
|
|
87
66
|
let items: [BottomTabItem]
|
|
88
67
|
let floatingButton: BottomTabFloatingButton?
|
|
89
68
|
let selectedIndex: Int
|
|
90
69
|
let onTabSelected: (Int) -> Void
|
|
91
|
-
|
|
70
|
+
var onTabLongPress: ((Int) -> Void)?
|
|
92
71
|
|
|
93
72
|
@Environment(\.screenLayout) private var layout
|
|
73
|
+
@Environment(\.appTheme) private var theme
|
|
94
74
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
}
|
|
107
|
-
|
|
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
|
-
}
|
|
75
|
+
// the bar sits between the side safe areas
|
|
76
|
+
private var screenWidth: CGFloat { layout.width - layout.insets.leading - layout.insets.trailing }
|
|
77
|
+
private var mid: Int { items.count / 2 }
|
|
122
78
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return
|
|
79
|
+
private var tabWidth: CGFloat {
|
|
80
|
+
if floatingButton != nil {
|
|
81
|
+
return (screenWidth - bottomTabFloatingButtonWidth) / CGFloat(items.count)
|
|
82
|
+
}
|
|
83
|
+
return screenWidth / CGFloat(items.count)
|
|
128
84
|
}
|
|
129
85
|
|
|
130
|
-
private
|
|
131
|
-
let
|
|
132
|
-
return
|
|
133
|
-
+ (afterCta ? TabBarMetrics.ctaSlotWidth + TabBarMetrics.itemGap : 0)
|
|
86
|
+
private var indicatorOffset: CGFloat {
|
|
87
|
+
let adjust: CGFloat = (floatingButton != nil && selectedIndex >= mid) ? bottomTabFloatingButtonWidth : 0
|
|
88
|
+
return tabWidth * CGFloat(selectedIndex) + tabWidth / 2 - screenWidth / 2 + adjust
|
|
134
89
|
}
|
|
135
90
|
|
|
136
91
|
var body: some View {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
}
|
|
92
|
+
ZStack(alignment: .bottom) {
|
|
93
|
+
HStack(spacing: 0) {
|
|
94
|
+
if floatingButton == nil {
|
|
95
|
+
tabItems(from: 0, to: items.count)
|
|
96
|
+
} else {
|
|
97
|
+
tabItems(from: 0, to: mid)
|
|
98
|
+
Spacer()
|
|
99
|
+
.frame(width: bottomTabFloatingButtonWidth)
|
|
100
|
+
.padding(.horizontal, Spacing.XXS)
|
|
101
|
+
tabItems(from: mid, to: items.count)
|
|
161
102
|
}
|
|
162
|
-
.padding(.horizontal, TabBarMetrics.paddingHorizontal)
|
|
163
|
-
.padding(.vertical, TabBarMetrics.paddingVertical)
|
|
164
103
|
}
|
|
165
|
-
.frame(
|
|
166
|
-
.
|
|
167
|
-
.
|
|
168
|
-
|
|
169
|
-
|
|
104
|
+
.frame(maxWidth: .infinity)
|
|
105
|
+
.frame(height: BOTTOM_TAB_BAR_HEIGHT)
|
|
106
|
+
.background(theme.colors.background.surface.ignoresSafeArea(edges: .horizontal))
|
|
107
|
+
|
|
108
|
+
// Animated selection indicator.
|
|
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)
|
|
170
124
|
|
|
171
|
-
if let
|
|
172
|
-
|
|
125
|
+
if let floatingButton {
|
|
126
|
+
CenterFloatingButton(data: floatingButton)
|
|
173
127
|
}
|
|
174
128
|
}
|
|
175
|
-
.frame(width: width)
|
|
176
129
|
}
|
|
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
|
|
185
130
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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)
|
|
131
|
+
@ViewBuilder
|
|
132
|
+
private func tabItems(from: Int, to: Int) -> some View {
|
|
133
|
+
ForEach(from..<to, id: \.self) { index in
|
|
134
|
+
TabBarItem(
|
|
135
|
+
item: items[index],
|
|
136
|
+
selected: index == selectedIndex,
|
|
137
|
+
// from the icon's center to the cell's end edge, inside both XXS paddings
|
|
138
|
+
badgeMaxWidth: tabWidth / 2 - Spacing.XXS * 2,
|
|
139
|
+
onClick: { onTabSelected(index) },
|
|
140
|
+
onLongClick: onTabLongPress.map { callback in { callback(index) } }
|
|
203
141
|
)
|
|
204
|
-
.
|
|
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)
|
|
142
|
+
.frame(maxWidth: .infinity)
|
|
143
|
+
}
|
|
216
144
|
}
|
|
217
145
|
}
|
|
218
146
|
|
|
219
147
|
// MARK: - Tab item
|
|
220
148
|
|
|
221
|
-
|
|
222
|
-
/// slots; the icon and label tint cross-fade on focus.
|
|
223
|
-
struct TabItemContent: View {
|
|
149
|
+
private struct TabBarItem: View {
|
|
224
150
|
let item: BottomTabItem
|
|
225
151
|
let selected: Bool
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
152
|
+
let badgeMaxWidth: CGFloat
|
|
153
|
+
let onClick: () -> Void
|
|
154
|
+
let onLongClick: (() -> Void)?
|
|
229
155
|
|
|
230
156
|
@Environment(\.appTheme) private var theme
|
|
231
157
|
|
|
232
|
-
var
|
|
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
|
-
}
|
|
158
|
+
private var tintColor: Color { selected ? theme.colors.primary : theme.colors.text.hint }
|
|
257
159
|
|
|
258
|
-
///
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
let value = Int(label) ?? Int.max
|
|
264
|
-
if value == 0 { return item.showDot ? "" : nil }
|
|
265
|
-
return value > 99 ? "99+" : label
|
|
160
|
+
/// Mirrors Compose's `formatLabel`: hide a badge that is the number "0".
|
|
161
|
+
private var badgeLabel: String? {
|
|
162
|
+
guard let label = item.badgeLabel else { return nil }
|
|
163
|
+
if let n = Int(label), n == 0 { return nil }
|
|
164
|
+
return label
|
|
266
165
|
}
|
|
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
|
|
278
166
|
|
|
279
167
|
var body: some View {
|
|
280
|
-
|
|
281
|
-
Icon(source: item.icon, size:
|
|
282
|
-
.
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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)
|
|
168
|
+
VStack(spacing: 0) {
|
|
169
|
+
Icon(source: item.icon, size: 28, color: tintColor)
|
|
170
|
+
.overlay(alignment: .topLeading) {
|
|
171
|
+
// starts at the icon's center and grows toward the cell's end edge, ellipsized past it
|
|
172
|
+
if let badgeLabel, !badgeLabel.isEmpty {
|
|
173
|
+
Badge(label: badgeLabel)
|
|
174
|
+
.frame(width: max(badgeMaxWidth, 0), alignment: .leading)
|
|
175
|
+
.offset(x: 14, y: -Spacing.S)
|
|
176
|
+
}
|
|
298
177
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
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
|
|
308
|
-
|
|
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))
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// MARK: - Center action
|
|
328
|
-
|
|
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
|
|
338
|
-
|
|
339
|
-
@Environment(\.appTheme) private var theme
|
|
340
|
-
|
|
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)
|
|
178
|
+
.overlay(alignment: .topTrailing) {
|
|
179
|
+
if badgeLabel?.isEmpty == true || (badgeLabel == nil && item.showDot) {
|
|
180
|
+
BadgeDot(size: .small).offset(x: 4, y: -4)
|
|
181
|
+
}
|
|
356
182
|
}
|
|
357
|
-
|
|
358
|
-
.frame(width: size, height: size)
|
|
359
|
-
.scaleEffect(pressed ? TabBarMetrics.ctaPressedScale : 1)
|
|
360
|
-
.animation(TabBarMetrics.ctaPressMotion, value: pressed)
|
|
183
|
+
.padding(Spacing.XS)
|
|
361
184
|
MomoText(
|
|
362
|
-
label,
|
|
363
|
-
typography:
|
|
364
|
-
color:
|
|
185
|
+
item.label,
|
|
186
|
+
typography: selected ? .labelXsMedium : .descriptionXsRegular,
|
|
187
|
+
color: tintColor,
|
|
365
188
|
textAlign: .center,
|
|
366
189
|
maxLines: 1
|
|
367
190
|
)
|
|
368
191
|
.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))
|
|
373
192
|
}
|
|
374
|
-
|
|
375
|
-
.
|
|
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)
|
|
376
198
|
.contentShape(Rectangle())
|
|
199
|
+
.onTapGesture { onClick() }
|
|
200
|
+
.modifier(TabLongPress(action: onLongClick))
|
|
377
201
|
}
|
|
378
202
|
}
|
|
379
203
|
|
|
380
|
-
///
|
|
381
|
-
private struct
|
|
204
|
+
/// Only attached with a callback, so a held tab without one still selects on release.
|
|
205
|
+
private struct TabLongPress: ViewModifier {
|
|
206
|
+
let action: (() -> Void)?
|
|
207
|
+
|
|
208
|
+
func body(content: Content) -> some View {
|
|
209
|
+
if let action {
|
|
210
|
+
content.onLongPressGesture(minimumDuration: 0.5, perform: action)
|
|
211
|
+
} else {
|
|
212
|
+
content
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// MARK: - Center floating button
|
|
218
|
+
|
|
219
|
+
private struct CenterFloatingButton: View {
|
|
382
220
|
let data: BottomTabFloatingButton
|
|
383
|
-
|
|
221
|
+
|
|
222
|
+
@Environment(\.appTheme) private var theme
|
|
384
223
|
|
|
385
224
|
var body: some View {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
.
|
|
225
|
+
VStack(spacing: 0) {
|
|
226
|
+
CurvedContainer()
|
|
227
|
+
Circle()
|
|
228
|
+
.fill(theme.colors.primary)
|
|
229
|
+
.frame(width: 48, height: 48)
|
|
230
|
+
.overlay(Icon(source: data.icon, size: 28, color: .white))
|
|
231
|
+
Spacer().frame(height: 4)
|
|
232
|
+
MomoText(data.label, typography: .labelXsMedium, color: Colors.black01, textAlign: .center, maxLines: 1)
|
|
233
|
+
.frame(maxWidth: .infinity)
|
|
234
|
+
.frame(height: 14)
|
|
235
|
+
.background(theme.colors.primary)
|
|
236
|
+
.clipShape(RoundedRectangle(cornerRadius: Radius.XL))
|
|
237
|
+
}
|
|
238
|
+
.frame(width: bottomTabFloatingButtonWidth)
|
|
239
|
+
.padding(.horizontal, Spacing.XXS)
|
|
240
|
+
.padding(.vertical, Spacing.S)
|
|
241
|
+
.contentShape(Rectangle())
|
|
242
|
+
.onTapGesture { data.onPress() }
|
|
393
243
|
}
|
|
394
244
|
}
|
|
@@ -2,68 +2,64 @@
|
|
|
2
2
|
// CurvedContainer.swift
|
|
3
3
|
// MoMoUIKits
|
|
4
4
|
//
|
|
5
|
-
// SwiftUI mirror of Compose's `CurvedContainer.kt
|
|
6
|
-
//
|
|
5
|
+
// SwiftUI mirror of Compose's `CurvedContainer` (navigation/bottomtab/CurvedContainer.kt).
|
|
6
|
+
// Draws the surface-colored notch that sits behind the center floating button,
|
|
7
|
+
// carving a circular cut-out into the tab bar's top edge.
|
|
7
8
|
//
|
|
8
9
|
|
|
9
10
|
import SwiftUI
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
var
|
|
12
|
+
struct CurvedContainer: View {
|
|
13
|
+
var circleSize: CGFloat = 48
|
|
14
|
+
var tabBarItemIconSize: CGFloat = 28
|
|
15
|
+
var circleOverSize: CGFloat = 2
|
|
16
|
+
var width: CGFloat = 71
|
|
17
|
+
var height: CGFloat = 16
|
|
18
|
+
var color: Color = Colors.black01
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
let
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
let h = rect.height
|
|
20
|
+
var body: some View {
|
|
21
|
+
let circlePositionTop = circleSize - tabBarItemIconSize - 10
|
|
22
|
+
let circleOverTop = circlePositionTop + circleOverSize
|
|
23
|
+
let circleR = circleSize / 2
|
|
24
|
+
let circleOverR = circleR + circleOverSize
|
|
25
|
+
let centerX = width / 2
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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)
|
|
27
|
+
CurvedShape(circleOverTop: circleOverTop, centerX: centerX, circleOverR: circleOverR, width: width)
|
|
28
|
+
.fill(color)
|
|
29
|
+
.frame(width: width, height: height)
|
|
30
|
+
.offset(y: 24)
|
|
31
|
+
.zIndex(-1)
|
|
45
32
|
}
|
|
46
33
|
}
|
|
47
34
|
|
|
48
|
-
///
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
/// Mirrors Compose's `getPath`: a flat bar with a smooth circular dip in the
|
|
36
|
+
/// middle, sized to cradle the floating button.
|
|
37
|
+
private struct CurvedShape: Shape {
|
|
38
|
+
let circleOverTop: CGFloat
|
|
39
|
+
let centerX: CGFloat
|
|
40
|
+
let circleOverR: CGFloat
|
|
41
|
+
let width: CGFloat
|
|
51
42
|
|
|
52
|
-
|
|
43
|
+
func path(in rect: CGRect) -> Path {
|
|
44
|
+
var path = Path()
|
|
45
|
+
path.move(to: CGPoint(x: 0, y: circleOverTop))
|
|
46
|
+
path.addLine(to: CGPoint(x: centerX - circleOverR - 40, y: circleOverTop))
|
|
53
47
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
.shadow(color: Color.black.opacity(0.12), radius: 12)
|
|
64
|
-
shape.fill(theme.colors.background.surface)
|
|
65
|
-
}
|
|
66
|
-
.allowsHitTesting(false)
|
|
48
|
+
path.addCurve(
|
|
49
|
+
to: CGPoint(x: centerX, y: 0),
|
|
50
|
+
control1: CGPoint(x: centerX - circleOverR, y: circleOverTop),
|
|
51
|
+
control2: CGPoint(x: centerX - circleOverR, y: 0)
|
|
52
|
+
)
|
|
53
|
+
path.addCurve(
|
|
54
|
+
to: CGPoint(x: centerX + circleOverR + 40, y: circleOverTop),
|
|
55
|
+
control1: CGPoint(x: centerX + circleOverR, y: 0),
|
|
56
|
+
control2: CGPoint(x: centerX + circleOverR, y: circleOverTop)
|
|
67
57
|
)
|
|
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
|
|
68
64
|
}
|
|
69
65
|
}
|