@momo-kits/native-kits 0.168.1-beta.4 → 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 (185) hide show
  1. package/CLAUDE.md +15 -10
  2. package/README.md +2 -10
  3. package/build.gradle.kts +11 -0
  4. package/compose/build.gradle.kts +198 -0
  5. package/compose/build.gradle.kts.backup +198 -0
  6. package/compose/compose.podspec +47 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  13. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1071 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +195 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +363 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +308 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +207 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +236 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +17 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +287 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +316 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +393 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +113 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +205 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +422 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +739 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +239 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +389 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +94 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +203 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +455 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +399 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +192 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +92 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +22 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +219 -0
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  133. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +144 -0
  134. package/gradle/libs.versions.toml +69 -0
  135. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  136. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  137. package/gradle.properties +26 -0
  138. package/gradlew +252 -0
  139. package/gradlew.bat +94 -0
  140. package/ios/Application/ApplicationEnvironment.swift +7 -6
  141. package/ios/Application/DesignSystemKits.swift +163 -0
  142. package/ios/Application/DesignSystemKitsPayload.swift +68 -0
  143. package/ios/Badge/BadgeRibbon.swift +8 -1
  144. package/ios/Extensions/Color++.swift +2 -4
  145. package/ios/Input/Input.swift +16 -4
  146. package/ios/Input/InputPhoneNumber.swift +1 -3
  147. package/ios/Input/InputSearch.swift +1 -2
  148. package/ios/Input/InputTextArea.swift +8 -4
  149. package/ios/InputMoney/InputMoney.swift +6 -7
  150. package/ios/Layout/ModalLayout.swift +152 -0
  151. package/ios/Layout/ScreenLayout.swift +77 -18
  152. package/ios/Navigation/BottomSheet.swift +56 -53
  153. package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
  154. package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
  155. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  156. package/ios/Navigation/BottomTab/DuoBarCompression.swift +2 -3
  157. package/ios/Navigation/BottomTab/DuoTabBar.swift +64 -172
  158. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  159. package/ios/Navigation/Component/HeaderBackground.swift +22 -1
  160. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  161. package/ios/Navigation/Component/SnackBar.swift +4 -0
  162. package/ios/Navigation/ModalScreen.swift +20 -5
  163. package/ios/Navigation/StackScreen.swift +6 -8
  164. package/ios/Popup/PopupDisplay.swift +6 -4
  165. package/ios/Popup/PopupInput.swift +6 -4
  166. package/ios/Popup/PopupLayout.swift +17 -11
  167. package/ios/Popup/PopupNotify.swift +32 -25
  168. package/ios/Stepper/Stepper.swift +1 -2
  169. package/ios/Template/TrustBanner/TrustBanner.swift +4 -2
  170. package/ios/Typography/FontScale.swift +29 -15
  171. package/ios/Typography/Text.swift +88 -14
  172. package/ios/Typography/Typography.swift +2 -2
  173. package/ios/native-kits.podspec +1 -1
  174. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  175. package/ios-demo/README.md +120 -0
  176. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  177. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  178. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  179. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  180. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  181. package/package.json +1 -1
  182. package/publish.sh +2 -33
  183. package/settings.gradle.kts +64 -0
  184. package/ios/Typography/FontScaleStore.swift +0 -58
  185. package/ios/Typography/KitDesignSystem.swift +0 -17
@@ -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
  }
@@ -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
  }
@@ -35,8 +35,6 @@ struct DuoBarCompression {
35
35
  static let defaultToolbarHeight = DuoMetrics.controlSize + Spacing.M + 2 * DuoMetrics.itemPitch
36
36
  /// Back, then the single button the toolbar folds into.
37
37
  private static let compressedToolbarHeight = 2 * DuoMetrics.controlSize + Spacing.M
38
- /// Back alone, while a rail opened from the compressed state takes the toolbar slot.
39
- private static let backOnlyHeight = DuoMetrics.controlSize
40
38
 
41
39
  /// - both fit: both stay whole
42
40
  /// - one fits whole beside the other compressed: one is compressed, tapping it swaps them
@@ -72,7 +70,8 @@ struct DuoBarCompression {
72
70
 
73
71
  let expandToolbar = { opened.wrappedValue = .toolbar }
74
72
  let expandTabBar = { opened.wrappedValue = .tabBar }
75
- if opened.wrappedValue == .tabBar && fits(backOnlyHeight, tabBar) {
73
+ // an opened rail always shows, even when only the group gap is short: it closes once a tab is picked
74
+ if opened.wrappedValue == .tabBar {
76
75
  return DuoBarCompression(
77
76
  toolbarCompressed: true,
78
77
  tabBarCompressed: false,