@momo-kits/native-kits 0.168.1-beta.4-debug → 0.168.1-beta.40-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 (100) hide show
  1. package/CLAUDE.md +15 -10
  2. package/README.md +2 -10
  3. package/build.gradle.kts +1 -3
  4. package/compose/build.gradle.kts +20 -19
  5. package/compose/build.gradle.kts.backup +19 -18
  6. package/compose/compose.podspec +1 -1
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +4 -3
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +1 -1
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -14
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +14 -23
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +21 -15
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +84 -82
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -3
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +2 -1
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +18 -14
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +20 -13
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +117 -62
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +22 -6
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +16 -26
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +54 -36
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +1 -6
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +35 -29
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +321 -149
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +2 -3
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +89 -198
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +1 -1
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +3 -1
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +30 -44
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +2 -2
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +32 -40
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +12 -3
  43. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +3 -1
  44. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +2 -6
  45. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +12 -10
  46. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  47. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +60 -10
  48. package/gradle/libs.versions.toml +4 -11
  49. package/gradle/wrapper/gradle-wrapper.properties +1 -3
  50. package/gradle.properties +3 -3
  51. package/ios/Application/ApplicationEnvironment.swift +7 -6
  52. package/ios/Application/DesignSystemKits.swift +163 -0
  53. package/ios/Application/DesignSystemKitsPayload.swift +68 -0
  54. package/ios/Badge/BadgeRibbon.swift +8 -1
  55. package/ios/Extensions/Color++.swift +2 -4
  56. package/ios/Input/Input.swift +16 -4
  57. package/ios/Input/InputPhoneNumber.swift +1 -3
  58. package/ios/Input/InputSearch.swift +1 -2
  59. package/ios/Input/InputTextArea.swift +8 -4
  60. package/ios/InputMoney/InputMoney.swift +6 -7
  61. package/ios/Layout/ModalLayout.swift +152 -0
  62. package/ios/Layout/ScreenLayout.swift +77 -18
  63. package/ios/Navigation/BottomSheet.swift +56 -53
  64. package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
  65. package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
  66. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  67. package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
  68. package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
  69. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  70. package/ios/Navigation/Component/HeaderBackground.swift +22 -1
  71. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  72. package/ios/Navigation/Component/SnackBar.swift +4 -0
  73. package/ios/Navigation/ModalScreen.swift +20 -5
  74. package/ios/Navigation/StackScreen.swift +6 -8
  75. package/ios/Popup/PopupDisplay.swift +6 -4
  76. package/ios/Popup/PopupInput.swift +6 -4
  77. package/ios/Popup/PopupLayout.swift +17 -11
  78. package/ios/Popup/PopupNotify.swift +32 -25
  79. package/ios/Stepper/Stepper.swift +1 -2
  80. package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
  81. package/ios/Typography/FontScale.swift +29 -15
  82. package/ios/Typography/Text.swift +88 -14
  83. package/ios/Typography/Typography.swift +2 -2
  84. package/ios/native-kits.podspec +1 -1
  85. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  86. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  87. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  88. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  89. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  90. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  91. package/package.json +1 -1
  92. package/publish.sh +2 -33
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitDesignSystem.kt +0 -18
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +0 -22
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +0 -37
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +0 -41
  97. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +0 -44
  98. package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +0 -62
  99. package/ios/Typography/FontScaleStore.swift +0 -58
  100. 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 Duo bars overlay the content or sit in the side strip, so only the home indicator is kept clear
57
- private var reservedBottom: CGFloat {
58
- layout.isIPhoneDuo ? layout.insets.bottom : BOTTOM_TAB_BAR_HEIGHT + bottomInset + Spacing.S
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
- // Tab bar + home-indicator filler.
108
- VStack(spacing: 0) {
109
- BottomTabBar(
110
- items: items,
111
- floatingButton: floatingButton,
112
- selectedIndex: selectedIndex,
113
- onTabSelected: selectTab
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
- private static let switchDuration: TimeInterval = 0.2
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.frame = view.bounds }
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, existing) }
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 previous = selectedIndex.flatMap { tabs[$0] }
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.motion.visible = true
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
- // a frame at the start values first, so a tab created just now fades in too
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
- selected.motion.visible = true
263
- previous.motion.visible = false
264
- }
265
- DispatchQueue.main.asyncAfter(deadline: .now() + Self.switchDuration) { [weak self] in
266
- self?.leave(previous)
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, tab))
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, _ tab: Tab) -> AnyView {
282
- AnyView(TabCard(motion: tab.motion, content: content(index)).environment(\.self, environment))
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.frame = view.bounds
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
- let bottomInset = UIApplication.shared.connectedScenes
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
- // 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,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
- let bottomTabFloatingButtonWidth: CGFloat = 75
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
- // the bar sits between the side safe areas
75
- private var screenWidth: CGFloat { layout.width - layout.insets.leading - layout.insets.trailing }
76
- 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
+ }
77
105
 
78
- private var tabWidth: CGFloat {
79
- if floatingButton != nil {
80
- return (screenWidth - bottomTabFloatingButtonWidth) / CGFloat(items.count)
81
- }
82
- return screenWidth / CGFloat(items.count)
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
- private var indicatorOffset: CGFloat {
86
- let adjust: CGFloat = (floatingButton != nil && selectedIndex >= mid) ? bottomTabFloatingButtonWidth : 0
87
- return tabWidth * CGFloat(selectedIndex) + tabWidth / 2 - screenWidth / 2 + adjust
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
- ZStack(alignment: .bottom) {
92
- HStack(spacing: 0) {
93
- if floatingButton == nil {
94
- tabItems(from: 0, to: items.count)
95
- } else {
96
- tabItems(from: 0, to: mid)
97
- Spacer()
98
- .frame(width: bottomTabFloatingButtonWidth)
99
- .padding(.horizontal, Spacing.XXS)
100
- 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
+ }
101
159
  }
160
+ .padding(.horizontal, TabBarMetrics.paddingHorizontal)
161
+ .padding(.vertical, TabBarMetrics.paddingVertical)
102
162
  }
103
- .frame(maxWidth: .infinity)
104
- .frame(height: BOTTOM_TAB_BAR_HEIGHT)
105
- .background(theme.colors.background.surface.ignoresSafeArea(edges: .horizontal))
106
-
107
- // Animated selection indicator.
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 floatingButton {
125
- CenterFloatingButton(data: floatingButton)
169
+ if let cta {
170
+ CenterAction(data: cta, fixedFontScale: fixedFontScale)
126
171
  }
127
172
  }
173
+ .frame(width: width)
128
174
  }
175
+ }
129
176
 
130
- @ViewBuilder
131
- private func tabItems(from: Int, to: Int) -> some View {
132
- ForEach(from..<to, id: \.self) { index in
133
- TabBarItem(
134
- item: items[index],
135
- selected: index == selectedIndex,
136
- onClick: { onTabSelected(index) }
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
- .frame(maxWidth: .infinity)
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
- 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 {
146
222
  let item: BottomTabItem
147
223
  let selected: Bool
148
- let onClick: () -> Void
224
+ var vertical = false
225
+ var showLabel = true
226
+ var fixedFontScale = false
149
227
 
150
228
  @Environment(\.appTheme) private var theme
151
229
 
152
- 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
+ }
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
- /// Mirrors Compose's `formatLabel`: hide a badge that is the number "0".
155
- private var badgeLabel: String? {
156
- guard let label = item.badgeLabel else { return nil }
157
- if let n = Int(label), n == 0 { return nil }
158
- return label
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
- var body: some View {
162
- ZStack(alignment: .topTrailing) {
163
- VStack(spacing: 0) {
164
- Icon(source: item.icon, size: 28, color: tintColor)
165
- .padding(Spacing.XS)
166
- MomoText(
167
- item.label,
168
- typography: selected ? .labelXsMedium : .descriptionXsRegular,
169
- color: tintColor,
170
- textAlign: .center,
171
- maxLines: 1
172
- )
173
- .truncationMode(.tail)
174
- }
175
- .frame(maxWidth: .infinity, maxHeight: .infinity)
176
- .padding(.horizontal, Spacing.S)
177
- .padding(.vertical, Spacing.S)
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
- if let badgeLabel {
180
- if badgeLabel.isEmpty {
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: -Spacing.S, y: Spacing.XS)
290
+ .offset(x: vertical ? 16 - (TabBarMetrics.iconSize - 10) / 2 : 16, y: -Spacing.XXS)
183
291
  } else {
184
- Badge(label: badgeLabel)
185
- .offset(x: -Spacing.XS, y: 0)
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
- // MARK: - Center floating button
200
-
201
- private struct CenterFloatingButton: View {
202
- let data: BottomTabFloatingButton
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
- VStack(spacing: 0) {
208
- CurvedContainer()
209
- Circle()
210
- .fill(theme.colors.primary)
211
- .frame(width: 48, height: 48)
212
- .overlay(Icon(source: data.icon, size: 28, color: .white))
213
- Spacer().frame(height: 4)
214
- MomoText(data.label, typography: .labelXsMedium, color: Colors.black01, textAlign: .center, maxLines: 1)
215
- .frame(maxWidth: .infinity)
216
- .frame(height: 14)
217
- .background(theme.colors.primary)
218
- .clipShape(RoundedRectangle(cornerRadius: Radius.XL))
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
- .frame(width: bottomTabFloatingButtonWidth)
221
- .padding(.horizontal, Spacing.XXS)
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
- .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)
225
391
  }
226
392
  }