@momo-kits/native-kits 0.168.1-beta.31-debug → 0.168.1-beta.32

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 (152) hide show
  1. package/CLAUDE.md +1 -2
  2. package/ios/Input/Input.swift +1 -3
  3. package/ios/Input/InputTextArea.swift +1 -3
  4. package/ios/Navigation/BottomTab/BottomTab.swift +48 -67
  5. package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -131
  6. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  7. package/ios/Navigation/BottomTab/DuoTabBar.swift +72 -292
  8. package/ios/Navigation/BottomTab/TabBarMetrics.swift +88 -0
  9. package/ios/Navigation/StackScreen.swift +3 -1
  10. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  11. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  12. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  13. package/package.json +1 -1
  14. package/build.gradle.kts +0 -11
  15. package/compose/build.gradle.kts +0 -198
  16. package/compose/build.gradle.kts.backup +0 -198
  17. package/compose/compose.podspec +0 -47
  18. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -20
  19. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  20. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
  21. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  22. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -153
  23. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
  24. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +0 -18
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -110
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +0 -62
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -1071
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -269
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -81
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -357
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -128
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -542
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -231
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -189
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -478
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -114
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -265
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -235
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -223
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -265
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -185
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -343
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -41
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -84
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -40
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -370
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -308
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -90
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -330
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -220
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -473
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -207
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -92
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -560
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -125
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -207
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -501
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -236
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -17
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -287
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -321
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -52
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -502
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -148
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -116
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -205
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -422
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -732
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -148
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -232
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -237
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -97
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +0 -380
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -436
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -169
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -455
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -105
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -399
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -192
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -91
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -9
  129. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -74
  130. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
  131. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -21
  132. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  133. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  134. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  135. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -118
  136. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -42
  137. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
  138. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
  139. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
  140. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -66
  141. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -218
  142. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
  143. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -138
  144. package/gradle/libs.versions.toml +0 -69
  145. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  146. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  147. package/gradle.properties +0 -26
  148. package/gradlew +0 -252
  149. package/gradlew.bat +0 -94
  150. package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +0 -364
  151. package/ios-demo/README.md +0 -120
  152. package/settings.gradle.kts +0 -64
@@ -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,346 @@ 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
  }
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
+
58
79
  }
59
80
 
60
- let bottomTabFloatingButtonWidth: CGFloat = 75
61
- let BOTTOM_TAB_BAR_HEIGHT: CGFloat = 64
81
+ let BOTTOM_TAB_BAR_HEIGHT: CGFloat = TabBarMetrics.height
62
82
 
63
83
  // MARK: - Tab bar
64
84
 
85
+ /// Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
65
86
  struct BottomTabBar: View {
66
87
  let items: [BottomTabItem]
67
88
  let floatingButton: BottomTabFloatingButton?
68
89
  let selectedIndex: Int
69
90
  let onTabSelected: (Int) -> Void
70
- var onTabLongPress: ((Int) -> Void)?
91
+ let bottomInset: CGFloat
71
92
 
72
93
  @Environment(\.screenLayout) private var layout
73
- @Environment(\.appTheme) private var theme
74
94
 
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 }
95
+ var body: some View {
96
+ HorizontalTabBar(
97
+ items: items,
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
+ }
78
107
 
79
- private var tabWidth: CGFloat {
80
- if floatingButton != nil {
81
- return (screenWidth - bottomTabFloatingButtonWidth) / CGFloat(items.count)
82
- }
83
- return screenWidth / CGFloat(items.count)
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
+ }
122
+
123
+ /// Items share what the padding, gaps and center action slot leave.
124
+ private var itemWidth: CGFloat {
125
+ let slots = CGFloat(items.count + (cta == nil ? 0 : 1))
126
+ let content = width - 2 * TabBarMetrics.paddingHorizontal - (slots - 1) * TabBarMetrics.itemGap
127
+ return max((content - (cta == nil ? 0 : TabBarMetrics.ctaSlotWidth)) / CGFloat(max(items.count, 1)), 0)
84
128
  }
85
129
 
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
130
+ private func itemX(_ index: Int) -> CGFloat {
131
+ let afterCta = cta != nil && index >= items.count / 2
132
+ return TabBarMetrics.paddingHorizontal + CGFloat(index) * (itemWidth + TabBarMetrics.itemGap)
133
+ + (afterCta ? TabBarMetrics.ctaSlotWidth + TabBarMetrics.itemGap : 0)
89
134
  }
90
135
 
91
136
  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)
137
+ let shape = NotchedBarShape(radius: TabBarMetrics.height / 2, notchCenterX: cta == nil ? nil : width / 2)
138
+ ZStack(alignment: .top) {
139
+ ZStack(alignment: .topLeading) {
140
+ ActiveIndicator(radius: TabBarMetrics.indicatorRadius)
141
+ .frame(width: itemWidth, height: TabBarMetrics.indicatorHeight)
142
+ .offset(x: itemX(selectedIndex), y: TabBarMetrics.paddingVertical)
143
+ .animation(TabBarMetrics.indicatorMotion, value: selectedIndex)
144
+
145
+ HStack(spacing: TabBarMetrics.itemGap) {
146
+ ForEach(items.indices, id: \.self) { index in
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
+ }
102
161
  }
162
+ .padding(.horizontal, TabBarMetrics.paddingHorizontal)
163
+ .padding(.vertical, TabBarMetrics.paddingVertical)
103
164
  }
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)
165
+ .frame(width: width, height: TabBarMetrics.height, alignment: .topLeading)
166
+ .modifier(TabBarContainer(shape: shape))
167
+ .accessibilityElement(children: .contain)
168
+ .accessibilityIdentifier("bottom_tab_bar")
169
+ .padding(.top, cta == nil ? 0 : TabBarMetrics.ctaLift)
124
170
 
125
- if let floatingButton {
126
- CenterFloatingButton(data: floatingButton)
171
+ if let cta {
172
+ CenterAction(data: cta, fixedFontScale: fixedFontScale)
127
173
  }
128
174
  }
175
+ .frame(width: width)
129
176
  }
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
130
185
 
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) } }
186
+ var body: some View {
187
+ let shape = RoundedRectangle(cornerRadius: radius)
188
+ shape
189
+ .fill(theme.colors.background.tonal)
190
+ // inner shadows: primary 12% falling 1 from the top edge, white 12% rising 2 from the bottom one
191
+ .overlay(
192
+ LinearGradient(
193
+ stops: [
194
+ .init(color: theme.colors.primary.opacity(0.12), location: 0),
195
+ .init(color: theme.colors.primary.opacity(0), location: 0.1),
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)
141
203
  )
142
- .frame(maxWidth: .infinity)
143
- }
204
+ .allowsHitTesting(false)
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)
144
216
  }
145
217
  }
146
218
 
147
219
  // MARK: - Tab item
148
220
 
149
- private struct TabBarItem: View {
221
+ /// Icon in its indicator slot, label under it. The bar slides one shared active indicator behind the
222
+ /// slots; the icon and label tint cross-fade on focus.
223
+ struct TabItemContent: View {
150
224
  let item: BottomTabItem
151
225
  let selected: Bool
152
- let badgeMaxWidth: CGFloat
153
- let onClick: () -> Void
154
- let onLongClick: (() -> Void)?
226
+ var vertical = false
227
+ var showLabel = true
228
+ var fixedFontScale = false
155
229
 
156
230
  @Environment(\.appTheme) private var theme
157
231
 
158
- private var tintColor: Color { selected ? theme.colors.primary : theme.colors.text.hint }
232
+ var body: some View {
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
+ }
159
257
 
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
258
+ /// Badge value shown on a tab: nil hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
259
+ func tabBadgeLabel(_ item: BottomTabItem) -> String? {
260
+ guard let label = item.badgeLabel else { return item.showDot ? "" : nil }
261
+ if label.isEmpty { return "" }
262
+ if label.allSatisfy({ ("0"..."9").contains($0) }) {
263
+ let value = Int(label) ?? Int.max
264
+ if value == 0 { return item.showDot ? "" : nil }
265
+ return value > 99 ? "99+" : label
165
266
  }
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
166
278
 
167
279
  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
- }
280
+ ZStack {
281
+ Icon(source: item.icon, size: TabBarMetrics.iconSize, color: theme.colors.text.secondary)
282
+ .opacity(selected ? 0 : 1)
283
+ Icon(source: item.icon, size: TabBarMetrics.iconSize, color: theme.colors.primary)
284
+ .opacity(selected ? 1 : 0)
285
+ }
286
+ .animation(TabBarMetrics.tintMotion, value: selected)
287
+ .frame(width: TabBarMetrics.iconSize, height: TabBarMetrics.iconSize)
288
+ .overlay(alignment: vertical ? .top : .topLeading) {
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)
182
298
  }
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)
299
+ }
192
300
  }
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
301
  }
202
302
  }
203
303
 
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)?
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
207
308
 
208
- func body(content: Content) -> some View {
209
- if let action {
210
- content.onLongPressGesture(minimumDuration: 0.5, perform: action)
211
- } else {
212
- content
213
- }
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))
214
324
  }
215
325
  }
216
326
 
217
- // MARK: - Center floating button
327
+ // MARK: - Center action
218
328
 
219
- private struct CenterFloatingButton: View {
220
- let data: BottomTabFloatingButton
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
221
338
 
222
339
  @Environment(\.appTheme) private var theme
223
340
 
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))
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)
356
+ }
357
+ }
358
+ .frame(width: size, height: size)
359
+ .scaleEffect(pressed ? TabBarMetrics.ctaPressedScale : 1)
360
+ .animation(TabBarMetrics.ctaPressMotion, value: pressed)
361
+ MomoText(
362
+ label,
363
+ typography: vertical ? .labelXsMedium : .labelSMedium,
364
+ color: theme.colors.text.secondary,
365
+ textAlign: .center,
366
+ maxLines: 1
367
+ )
368
+ .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))
237
373
  }
238
- .frame(width: bottomTabFloatingButtonWidth)
239
- .padding(.horizontal, Spacing.XXS)
240
- .padding(.vertical, Spacing.S)
374
+ // the whole slot is the hit area, not just the button and label
375
+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
241
376
  .contentShape(Rectangle())
242
- .onTapGesture { data.onPress() }
377
+ }
378
+ }
379
+
380
+ /// Center action (.Nav/CTA): button rising out of the notch, label under it.
381
+ private struct CenterAction: View {
382
+ let data: BottomTabFloatingButton
383
+ var fixedFontScale = false
384
+
385
+ var body: some View {
386
+ SwiftUI.Button(action: data.onPress) { EmptyView() }
387
+ .buttonStyle(CenterActionStyle(size: TabBarMetrics.ctaSize, vertical: false, icon: data.icon,
388
+ iconContent: data.iconContent, labelContent: data.labelContent,
389
+ label: data.label, fixedFontScale: fixedFontScale))
390
+ .frame(width: TabBarMetrics.ctaSlotWidth, height: TabBarMetrics.ctaSize + TabBarMetrics.ctaLabelGap + TabBarMetrics.ctaLabelHeight)
391
+ .accessibilityLabel(data.label)
392
+ .accessibilityIdentifier(data.label)
243
393
  }
244
394
  }
@@ -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
  }