@momo-kits/native-kits 0.168.1-beta.30-debug → 0.168.1-beta.31-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 (31) hide show
  1. package/CLAUDE.md +2 -1
  2. package/compose/build.gradle.kts +1 -1
  3. package/compose/compose.podspec +1 -1
  4. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +13 -1
  6. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +3 -3
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +9 -9
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +18 -10
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +167 -313
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +71 -79
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +380 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +326 -93
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +2 -1
  15. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  16. package/gradle.properties +1 -1
  17. package/ios/Input/Input.swift +3 -1
  18. package/ios/Input/InputTextArea.swift +3 -1
  19. package/ios/Navigation/BottomTab/BottomTab.swift +33 -14
  20. package/ios/Navigation/BottomTab/BottomTabBar.swift +131 -254
  21. package/ios/Navigation/BottomTab/CurvedContainer.swift +47 -51
  22. package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +364 -0
  23. package/ios/Navigation/BottomTab/DuoTabBar.swift +292 -71
  24. package/ios/Navigation/StackScreen.swift +1 -3
  25. package/ios/native-kits.podspec +1 -1
  26. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  27. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +59 -224
  28. package/package.json +1 -1
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -106
  30. package/ios/Navigation/BottomTab/TabBarMetrics.swift +0 -88
  31. package/local.properties +0 -9
@@ -16,6 +16,7 @@ public struct BottomTab: View {
16
16
  private let compressionBehavior: DuoBarCompressionBehavior
17
17
  private let onTabPress: ((_ index: Int, _ switchTab: @escaping () -> Void) -> Void)?
18
18
  private let backToInitialTab: Bool
19
+ private let onTabLongPress: ((_ index: Int) -> Void)?
19
20
 
20
21
  @EnvironmentObject private var navigator: Navigator
21
22
  /// The screen hosting the tabs (Compose's `LocalNavigation` in BottomTab).
@@ -34,28 +35,32 @@ public struct BottomTab: View {
34
35
  /// starts compressed; tapping the compressed one swaps them.
35
36
  /// `onTabPress` gets every tab press with the switch to perform, e.g. after a login gate.
36
37
  /// `backToInitialTab`: back off another tab returns to the initial one before leaving the screen.
38
+ /// `onTabLongPress`: RN `tabLongPress`; on iPhone Duo the held tab is still selected on release.
37
39
  public init(
38
40
  items: [BottomTabItem],
39
41
  floatingButton: BottomTabFloatingButton? = nil,
40
42
  compressionBehavior: DuoBarCompressionBehavior = .toolbar,
41
43
  initialRouteName: String? = nil,
42
44
  onTabPress: ((_ index: Int, _ switchTab: @escaping () -> Void) -> Void)? = nil,
43
- backToInitialTab: Bool = true
45
+ backToInitialTab: Bool = true,
46
+ onTabLongPress: ((_ index: Int) -> Void)? = nil
44
47
  ) {
45
48
  self.items = items
46
49
  self.floatingButton = floatingButton
47
50
  self.compressionBehavior = compressionBehavior
48
51
  self.onTabPress = onTabPress
49
52
  self.backToInitialTab = backToInitialTab
53
+ self.onTabLongPress = onTabLongPress
50
54
  let start = items.firstIndex { $0.name == initialRouteName } ?? 0
51
55
  _startIndex = State(initialValue: start)
52
56
  _selectedIndex = State(initialValue: start)
53
57
  }
54
58
 
55
59
  private var bottomInset: CGFloat { safeAreaBottomInset() }
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
+ // the Duo bars overlay the content or sit in the side strip, so only the home indicator is kept clear
61
+ private var reservedBottom: CGFloat {
62
+ layout.isIPhoneDuo ? layout.insets.bottom : BOTTOM_TAB_BAR_HEIGHT + bottomInset + Spacing.S
63
+ }
59
64
 
60
65
  private var compression: DuoBarCompression {
61
66
  DuoBarCompression.resolve(
@@ -100,16 +105,30 @@ public struct BottomTab: View {
100
105
  floatingButton: floatingButton,
101
106
  selectedIndex: selectedIndex,
102
107
  onTabSelected: selectTab,
103
- compression: compression
108
+ compression: compression,
109
+ onTabLongPress: onTabLongPress,
110
+ onTick: { [maxApi = navigator.maxApi] in
111
+ if let maxApi {
112
+ maxApi.triggerEventVibration("light")
113
+ } else {
114
+ UIImpactFeedbackGenerator(style: .light).impactOccurred()
115
+ }
116
+ }
104
117
  )
105
118
  } else {
106
- BottomTabBar(
107
- items: items,
108
- floatingButton: floatingButton,
109
- selectedIndex: selectedIndex,
110
- onTabSelected: selectTab,
111
- bottomInset: bottomInset
112
- )
119
+ // Tab bar + home-indicator filler.
120
+ VStack(spacing: 0) {
121
+ BottomTabBar(
122
+ items: items,
123
+ floatingButton: floatingButton,
124
+ selectedIndex: selectedIndex,
125
+ onTabSelected: selectTab,
126
+ onTabLongPress: onTabLongPress
127
+ )
128
+ theme.colors.background.surface
129
+ .frame(height: bottomInset + Spacing.S)
130
+ .ignoresSafeArea(edges: .horizontal)
131
+ }
113
132
  }
114
133
  }
115
134
  .frame(maxWidth: .infinity, maxHeight: .infinity)
@@ -131,7 +150,6 @@ public struct BottomTab: View {
131
150
  }
132
151
 
133
152
  private func selectTab(_ index: Int) {
134
- navigator.maxApi?.triggerEventVibration("light")
135
153
  let switchTab = { if index != selectedIndex { selectedIndex = index } }
136
154
  if let onTabPress { onTabPress(index, switchTab) } else { switchTab() }
137
155
  }
@@ -320,7 +338,8 @@ private struct TabCard: View {
320
338
 
321
339
  /// Bottom safe-area inset (home indicator).
322
340
  private func safeAreaBottomInset() -> CGFloat {
323
- UIApplication.shared.connectedScenes
341
+ let bottomInset = UIApplication.shared.connectedScenes
324
342
  .compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
325
343
  .first ?? 0
344
+ return min(bottomInset, 21)
326
345
  }
@@ -3,8 +3,8 @@
3
3
  // MoMoUIKits
4
4
  //
5
5
  // SwiftUI mirror of Compose's `navigation/bottomtab/BottomTabBar.kt`.
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.
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
@@ -57,311 +57,188 @@ public struct BottomTabFloatingButton {
57
57
  }
58
58
  }
59
59
 
60
- let BOTTOM_TAB_BAR_HEIGHT: CGFloat = TabBarMetrics.height
60
+ let bottomTabFloatingButtonWidth: CGFloat = 75
61
+ let BOTTOM_TAB_BAR_HEIGHT: CGFloat = 64
61
62
 
62
63
  // MARK: - Tab bar
63
64
 
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
+ var onTabLongPress: ((Int) -> Void)?
71
71
 
72
72
  @Environment(\.screenLayout) private var layout
73
+ @Environment(\.appTheme) private var theme
73
74
 
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
- }
86
-
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
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 }
97
78
 
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)
79
+ private var tabWidth: CGFloat {
80
+ if floatingButton != nil {
81
+ return (screenWidth - bottomTabFloatingButtonWidth) / CGFloat(items.count)
82
+ }
83
+ return screenWidth / CGFloat(items.count)
107
84
  }
108
85
 
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)
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
113
89
  }
114
90
 
115
91
  var body: some View {
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
- }
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)
140
102
  }
141
- .padding(.horizontal, TabBarMetrics.paddingHorizontal)
142
- .padding(.vertical, TabBarMetrics.paddingVertical)
143
103
  }
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)
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)
149
124
 
150
- if let cta {
151
- CenterAction(data: cta, fixedFontScale: fixedFontScale)
125
+ if let floatingButton {
126
+ CenterFloatingButton(data: floatingButton)
152
127
  }
153
128
  }
154
- .frame(width: width)
155
129
  }
156
- }
157
-
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
130
 
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)
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) } }
182
141
  )
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)
142
+ .frame(maxWidth: .infinity)
143
+ }
195
144
  }
196
145
  }
197
146
 
198
147
  // MARK: - Tab item
199
148
 
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 {
149
+ private struct TabBarItem: View {
203
150
  let item: BottomTabItem
204
151
  let selected: Bool
205
- var vertical = false
206
- var showLabel = true
207
- var fixedFontScale = false
152
+ let badgeMaxWidth: CGFloat
153
+ let onClick: () -> Void
154
+ let onLongClick: (() -> Void)?
208
155
 
209
156
  @Environment(\.appTheme) private var theme
210
157
 
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
- }
158
+ private var tintColor: Color { selected ? theme.colors.primary : theme.colors.text.hint }
224
159
 
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)
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
234
165
  }
235
- }
236
-
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
245
- }
246
- return label
247
- }
248
-
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
255
-
256
- @Environment(\.appTheme) private var theme
257
166
 
258
167
  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 {
270
- BadgeDot(size: .small)
271
- .offset(x: vertical ? 16 - (TabBarMetrics.iconSize - 10) / 2 : 16, y: -Spacing.XXS)
272
- } else {
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)
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
+ }
277
177
  }
278
- }
178
+ .overlay(alignment: .topTrailing) {
179
+ if badgeLabel?.isEmpty == true || (badgeLabel == nil && item.showDot) {
180
+ BadgeDot(size: .small).offset(x: 4, y: -4)
181
+ }
182
+ }
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)
279
192
  }
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))
280
201
  }
281
202
  }
282
203
 
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
287
-
288
- @Environment(\.appTheme) private var theme
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
- }
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)?
294
207
 
295
- var body: some View {
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))
208
+ func body(content: Content) -> some View {
209
+ if let action {
210
+ content.onLongPressGesture(minimumDuration: 0.5, perform: action)
211
+ } else {
212
+ content
213
+ }
303
214
  }
304
215
  }
305
216
 
306
- // MARK: - Center action
217
+ // MARK: - Center floating button
307
218
 
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
219
+ private struct CenterFloatingButton: View {
220
+ let data: BottomTabFloatingButton
316
221
 
317
222
  @Environment(\.appTheme) private var theme
318
223
 
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))
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))
347
237
  }
348
- // the whole slot is the hit area, not just the button and label
349
- .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
238
+ .frame(width: bottomTabFloatingButtonWidth)
239
+ .padding(.horizontal, Spacing.XXS)
240
+ .padding(.vertical, Spacing.S)
350
241
  .contentShape(Rectangle())
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)
242
+ .onTapGesture { data.onPress() }
366
243
  }
367
244
  }