@momo-kits/native-kits 0.168.1-beta.37-debug → 0.168.1-beta.38-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.
Files changed (47) hide show
  1. package/CLAUDE.md +2 -3
  2. package/compose/build.gradle.kts +1 -1
  3. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
  4. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +81 -72
  5. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +13 -8
  6. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +163 -54
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +12 -17
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +34 -27
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +319 -167
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +93 -326
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -2
  18. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +3 -2
  19. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +3 -9
  20. package/ios/Input/Input.swift +1 -3
  21. package/ios/Input/InputTextArea.swift +1 -3
  22. package/ios/Layout/ScreenLayout.swift +24 -28
  23. package/ios/Navigation/BottomSheet.swift +157 -29
  24. package/ios/Navigation/BottomTab/BottomTab.swift +48 -67
  25. package/ios/Navigation/BottomTab/BottomTabBar.swift +280 -132
  26. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  27. package/ios/Navigation/BottomTab/DuoTabBar.swift +72 -292
  28. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  29. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  30. package/ios/Navigation/ModalScreen.swift +7 -18
  31. package/ios/Navigation/StackScreen.swift +3 -1
  32. package/ios/Popup/PopupDisplay.swift +2 -4
  33. package/ios/Popup/PopupInput.swift +2 -4
  34. package/ios/Popup/PopupLayout.swift +9 -10
  35. package/ios/Popup/PopupNotify.swift +23 -26
  36. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  37. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  38. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  39. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +0 -103
  40. package/package.json +1 -1
  41. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -187
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +0 -380
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
  45. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
  46. package/ios/Layout/ModalLayout.swift +0 -152
  47. package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +0 -364
@@ -3,8 +3,8 @@
3
3
  // MoMoUIKits
4
4
  //
5
5
  // SwiftUI mirror of Compose's `navigation/bottomtab/BottomTabBar.kt`.
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).
6
+ // Horizontal navigation bar (Figma "Specs Navigation", DS-984): floating container, items split
7
+ // evenly with a tonal active indicator, badges/dots, and the Special type's center action in a notch.
8
8
  //
9
9
 
10
10
  import SwiftUI
@@ -49,196 +49,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
57
63
  }
58
- }
59
64
 
60
- let bottomTabFloatingButtonWidth: CGFloat = 75
61
- let BOTTOM_TAB_BAR_HEIGHT: CGFloat = 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
+ }
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
70
- var onTabLongPress: ((Int) -> Void)?
89
+ let bottomInset: CGFloat
71
90
 
72
91
  @Environment(\.screenLayout) private var layout
73
- @Environment(\.appTheme) private var theme
74
92
 
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 }
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
+ }
105
+
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
78
116
 
79
- private var tabWidth: CGFloat {
80
- if floatingButton != nil {
81
- return (screenWidth - bottomTabFloatingButtonWidth) / CGFloat(items.count)
82
- }
83
- return screenWidth / CGFloat(items.count)
117
+ private var cta: BottomTabFloatingButton? {
118
+ TabBarMetrics.hasCenterAction(floatingButton, tabCount: items.count) ? floatingButton : nil
119
+ }
120
+
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)
84
126
  }
85
127
 
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
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)
89
132
  }
90
133
 
91
134
  var body: some View {
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)
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
+ }
102
159
  }
160
+ .padding(.horizontal, TabBarMetrics.paddingHorizontal)
161
+ .padding(.vertical, TabBarMetrics.paddingVertical)
103
162
  }
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)
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)
124
168
 
125
- if let floatingButton {
126
- CenterFloatingButton(data: floatingButton)
169
+ if let cta {
170
+ CenterAction(data: cta, fixedFontScale: fixedFontScale)
127
171
  }
128
172
  }
173
+ .frame(width: width)
129
174
  }
175
+ }
176
+
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
130
183
 
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) } }
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)
141
201
  )
142
- .frame(maxWidth: .infinity)
143
- }
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)
144
214
  }
145
215
  }
146
216
 
147
217
  // MARK: - Tab item
148
218
 
149
- private struct TabBarItem: View {
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 {
150
222
  let item: BottomTabItem
151
223
  let selected: Bool
152
- let badgeMaxWidth: CGFloat
153
- let onClick: () -> Void
154
- let onLongClick: (() -> Void)?
224
+ var vertical = false
225
+ var showLabel = true
226
+ var fixedFontScale = false
155
227
 
156
228
  @Environment(\.appTheme) private var theme
157
229
 
158
- private var tintColor: Color { selected ? theme.colors.primary : theme.colors.text.hint }
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
+ }
159
243
 
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
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)
165
253
  }
254
+ }
255
+
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
264
+ }
265
+ return label
266
+ }
267
+
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
166
276
 
167
277
  var body: some View {
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
- }
177
- }
178
- .overlay(alignment: .topTrailing) {
179
- if badgeLabel?.isEmpty == true || (badgeLabel == nil && item.showDot) {
180
- BadgeDot(size: .small).offset(x: 4, y: -4)
181
- }
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 {
289
+ BadgeDot(size: .small)
290
+ .offset(x: vertical ? 16 - (TabBarMetrics.iconSize - 10) / 2 : 16, y: -Spacing.XXS)
291
+ } else {
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)
182
296
  }
183
- .padding(Spacing.XS)
184
- MomoText(
185
- item.label,
186
- typography: selected ? .labelXsMedium : .descriptionXsRegular,
187
- color: tintColor,
188
- textAlign: .center,
189
- maxLines: 1
190
- )
191
- .truncationMode(.tail)
297
+ }
192
298
  }
193
- .frame(maxWidth: .infinity, maxHeight: .infinity)
194
- .padding(.horizontal, Spacing.S)
195
- .padding(.vertical, Spacing.S)
196
- .frame(maxWidth: .infinity, maxHeight: .infinity)
197
- .padding(.horizontal, Spacing.XXS)
198
- .contentShape(Rectangle())
199
- .onTapGesture { onClick() }
200
- .modifier(TabLongPress(action: onLongClick))
201
299
  }
202
300
  }
203
301
 
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)?
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
207
306
 
208
- func body(content: Content) -> some View {
209
- if let action {
210
- content.onLongPressGesture(minimumDuration: 0.5, perform: action)
211
- } else {
212
- content
213
- }
307
+ @Environment(\.appTheme) private var theme
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
+
314
+ var body: some View {
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))
214
322
  }
215
323
  }
216
324
 
217
- // MARK: - Center floating button
325
+ // MARK: - Center action
218
326
 
219
- private struct CenterFloatingButton: View {
220
- let data: BottomTabFloatingButton
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
221
336
 
222
337
  @Environment(\.appTheme) private var theme
223
338
 
224
- var body: some View {
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))
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))
237
371
  }
238
- .frame(width: bottomTabFloatingButtonWidth)
239
- .padding(.horizontal, Spacing.XXS)
240
- .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)
241
374
  .contentShape(Rectangle())
242
- .onTapGesture { data.onPress() }
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)
243
391
  }
244
392
  }
@@ -2,64 +2,68 @@
2
2
  // CurvedContainer.swift
3
3
  // MoMoUIKits
4
4
  //
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.
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
- 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
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
- 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
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
- 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)
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
- /// 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
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
- 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))
52
+ @Environment(\.appTheme) private var theme
47
53
 
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)
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
  }