@momo-kits/native-kits 0.168.1-beta.32 → 0.168.1-beta.33-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 (154) hide show
  1. package/CLAUDE.md +1 -0
  2. package/build.gradle.kts +11 -0
  3. package/compose/build.gradle.kts +198 -0
  4. package/compose/build.gradle.kts.backup +198 -0
  5. package/compose/compose.podspec +47 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +20 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +153 -0
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +62 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1071 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +189 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +478 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +265 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +235 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +265 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +370 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +308 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +330 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +207 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +92 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +560 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +501 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +236 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +17 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +287 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +321 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +502 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +148 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +116 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +205 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +422 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +732 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +232 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +237 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +97 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +380 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +436 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +455 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +399 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +192 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +74 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +20 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +118 -0
  124. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +218 -0
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +138 -0
  132. package/gradle/libs.versions.toml +69 -0
  133. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  134. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  135. package/gradle.properties +26 -0
  136. package/gradlew +252 -0
  137. package/gradlew.bat +94 -0
  138. package/ios/Input/Input.swift +3 -1
  139. package/ios/Input/InputTextArea.swift +3 -1
  140. package/ios/Navigation/BottomTab/BottomTab.swift +67 -48
  141. package/ios/Navigation/BottomTab/BottomTabBar.swift +131 -281
  142. package/ios/Navigation/BottomTab/CurvedContainer.swift +47 -51
  143. package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +364 -0
  144. package/ios/Navigation/BottomTab/DuoTabBar.swift +292 -72
  145. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  146. package/ios/Navigation/StackScreen.swift +1 -3
  147. package/ios-demo/README.md +120 -0
  148. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +59 -272
  149. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +90 -0
  150. package/package.json +1 -1
  151. package/settings.gradle.kts +64 -0
  152. package/ios/Navigation/BottomTab/TabBarMetrics.swift +0 -88
  153. package/ios-demo/Resources/tabbar_scan_qr_button.json +0 -1
  154. package/ios-demo/Resources/tabbar_scan_qr_label.json +0 -1
@@ -3,8 +3,8 @@
3
3
  // MoMoUIKits
4
4
  //
5
5
  // SwiftUI mirror of Compose's `navigation/bottomtab/BottomTabBar.kt`.
6
- // Horizontal navigation bar (Figma "Specs Navigation", DS-984): floating container, items split
7
- // evenly with a tonal active indicator, badges/dots, and the Special type's center action in a notch.
6
+ // Renders the row of tab items, an animated selection indicator, a top shadow,
7
+ // badges/dots, and an optional center floating button (with the curved notch).
8
8
  //
9
9
 
10
10
  import SwiftUI
@@ -49,346 +49,196 @@ 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?
56
52
 
57
53
  public init(icon: String, label: String, onPress: @escaping () -> Void) {
58
54
  self.icon = icon
59
55
  self.label = label
60
56
  self.onPress = onPress
61
- self.iconContent = nil
62
- self.labelContent = nil
63
57
  }
64
-
65
- /// The button and label parts given separately, e.g. a Lottie split into both.
66
- public init<IconContent: View, LabelContent: View>(
67
- label: String,
68
- onPress: @escaping () -> Void,
69
- @ViewBuilder iconContent: () -> IconContent,
70
- @ViewBuilder labelContent: () -> LabelContent
71
- ) {
72
- self.icon = ""
73
- self.label = label
74
- self.onPress = onPress
75
- self.iconContent = AnyView(iconContent())
76
- self.labelContent = AnyView(labelContent())
77
- }
78
-
79
58
  }
80
59
 
81
- let BOTTOM_TAB_BAR_HEIGHT: CGFloat = TabBarMetrics.height
60
+ let bottomTabFloatingButtonWidth: CGFloat = 75
61
+ let BOTTOM_TAB_BAR_HEIGHT: CGFloat = 64
82
62
 
83
63
  // MARK: - Tab bar
84
64
 
85
- /// Phone tab bar: the horizontal navigation bar filling the window, above the home indicator.
86
65
  struct BottomTabBar: View {
87
66
  let items: [BottomTabItem]
88
67
  let floatingButton: BottomTabFloatingButton?
89
68
  let selectedIndex: Int
90
69
  let onTabSelected: (Int) -> Void
91
- let bottomInset: CGFloat
70
+ var onTabLongPress: ((Int) -> Void)?
92
71
 
93
72
  @Environment(\.screenLayout) private var layout
73
+ @Environment(\.appTheme) private var theme
94
74
 
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
- }
107
-
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
- }
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 }
122
78
 
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)
79
+ private var tabWidth: CGFloat {
80
+ if floatingButton != nil {
81
+ return (screenWidth - bottomTabFloatingButtonWidth) / CGFloat(items.count)
82
+ }
83
+ return screenWidth / CGFloat(items.count)
128
84
  }
129
85
 
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)
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
134
89
  }
135
90
 
136
91
  var body: some View {
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
- }
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)
161
102
  }
162
- .padding(.horizontal, TabBarMetrics.paddingHorizontal)
163
- .padding(.vertical, TabBarMetrics.paddingVertical)
164
103
  }
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)
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)
170
124
 
171
- if let cta {
172
- CenterAction(data: cta, fixedFontScale: fixedFontScale)
125
+ if let floatingButton {
126
+ CenterFloatingButton(data: floatingButton)
173
127
  }
174
128
  }
175
- .frame(width: width)
176
129
  }
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
185
130
 
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)
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) } }
203
141
  )
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)
142
+ .frame(maxWidth: .infinity)
143
+ }
216
144
  }
217
145
  }
218
146
 
219
147
  // MARK: - Tab item
220
148
 
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 {
149
+ private struct TabBarItem: View {
224
150
  let item: BottomTabItem
225
151
  let selected: Bool
226
- var vertical = false
227
- var showLabel = true
228
- var fixedFontScale = false
152
+ let badgeMaxWidth: CGFloat
153
+ let onClick: () -> Void
154
+ let onLongClick: (() -> Void)?
229
155
 
230
156
  @Environment(\.appTheme) private var theme
231
157
 
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
- }
158
+ private var tintColor: Color { selected ? theme.colors.primary : theme.colors.text.hint }
257
159
 
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
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
266
165
  }
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
278
166
 
279
167
  var body: some View {
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)
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
+ }
298
177
  }
299
- }
300
- }
301
- }
302
- }
303
-
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
308
-
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))
324
- }
325
- }
326
-
327
- // MARK: - Center action
328
-
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
338
-
339
- @Environment(\.appTheme) private var theme
340
-
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)
178
+ .overlay(alignment: .topTrailing) {
179
+ if badgeLabel?.isEmpty == true || (badgeLabel == nil && item.showDot) {
180
+ BadgeDot(size: .small).offset(x: 4, y: -4)
181
+ }
356
182
  }
357
- }
358
- .frame(width: size, height: size)
359
- .scaleEffect(pressed ? TabBarMetrics.ctaPressedScale : 1)
360
- .animation(TabBarMetrics.ctaPressMotion, value: pressed)
183
+ .padding(Spacing.XS)
361
184
  MomoText(
362
- label,
363
- typography: vertical ? .labelXsMedium : .labelSMedium,
364
- color: theme.colors.text.secondary,
185
+ item.label,
186
+ typography: selected ? .labelXsMedium : .descriptionXsRegular,
187
+ color: tintColor,
365
188
  textAlign: .center,
366
189
  maxLines: 1
367
190
  )
368
191
  .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))
373
192
  }
374
- // the whole slot is the hit area, not just the button and label
375
- .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
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)
376
198
  .contentShape(Rectangle())
199
+ .onTapGesture { onClick() }
200
+ .modifier(TabLongPress(action: onLongClick))
377
201
  }
378
202
  }
379
203
 
380
- /// Center action (.Nav/CTA): button rising out of the notch, label under it.
381
- private struct CenterAction: View {
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)?
207
+
208
+ func body(content: Content) -> some View {
209
+ if let action {
210
+ content.onLongPressGesture(minimumDuration: 0.5, perform: action)
211
+ } else {
212
+ content
213
+ }
214
+ }
215
+ }
216
+
217
+ // MARK: - Center floating button
218
+
219
+ private struct CenterFloatingButton: View {
382
220
  let data: BottomTabFloatingButton
383
- var fixedFontScale = false
221
+
222
+ @Environment(\.appTheme) private var theme
384
223
 
385
224
  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)
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))
237
+ }
238
+ .frame(width: bottomTabFloatingButtonWidth)
239
+ .padding(.horizontal, Spacing.XXS)
240
+ .padding(.vertical, Spacing.S)
241
+ .contentShape(Rectangle())
242
+ .onTapGesture { data.onPress() }
393
243
  }
394
244
  }
@@ -2,68 +2,64 @@
2
2
  // CurvedContainer.swift
3
3
  // MoMoUIKits
4
4
  //
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.
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.
7
8
  //
8
9
 
9
10
  import SwiftUI
10
11
 
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?
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
16
19
 
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
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
24
26
 
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)
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)
45
32
  }
46
33
  }
47
34
 
48
- /// Navigation bar container: surface fill with the floating shadow following the shape.
49
- struct TabBarContainer<S: Shape>: ViewModifier {
50
- let shape: S
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
51
42
 
52
- @Environment(\.appTheme) private var theme
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))
53
47
 
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)
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)
67
57
  )
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
68
64
  }
69
65
  }