@momo-kits/native-kits 0.169.15-beta.4 → 0.169.15-beta.5

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.
@@ -107,13 +107,18 @@ public struct BottomTab: View {
107
107
  compression: compression
108
108
  )
109
109
  } else if isLegacyBar {
110
- LegacyBottomTabBar(
111
- items: items,
112
- floatingButton: floatingButton,
113
- selectedIndex: selectedIndex,
114
- onTabSelected: selectTab,
115
- bottomInset: bottomInset
116
- )
110
+ // Tab bar + home-indicator filler.
111
+ VStack(spacing: 0) {
112
+ LegacyBottomTabBar(
113
+ items: items,
114
+ floatingButton: floatingButton,
115
+ selectedIndex: selectedIndex,
116
+ onTabSelected: selectTab
117
+ )
118
+ theme.colors.background.surface
119
+ .frame(height: bottomInset + Spacing.S)
120
+ .ignoresSafeArea(edges: .horizontal)
121
+ }
117
122
  } else {
118
123
  BottomTabBar(
119
124
  items: items,
@@ -1,18 +1,24 @@
1
- // The pre-redesign (DS-984) phone tab bar, kept for `BottomTab(useLegacy: true)`: a full-width surface bar with a
2
- // sliding top indicator, a top shadow, badges and the notched center floating button, over a home-indicator filler.
1
+ //
2
+ // LegacyBottomTabBar.swift
3
+ // MoMoUIKits
4
+ //
5
+ // BottomTabBar.swift from main before the DS-984 redesign (5f31e0d4), verbatim except the Legacy prefix
6
+ // on its names. Used by `BottomTab(useLegacy: true)` on phones.
7
+ //
3
8
 
4
9
  import SwiftUI
5
10
 
11
+ let legacyBottomTabFloatingButtonWidth: CGFloat = 75
6
12
  let LEGACY_BOTTOM_TAB_BAR_HEIGHT: CGFloat = 64
7
- private let legacyFloatingButtonWidth: CGFloat = 75
8
13
 
9
- /// The legacy bar plus its surface filler under it, down to the window bottom.
14
+ // MARK: - Tab bar
15
+
10
16
  struct LegacyBottomTabBar: View {
11
17
  let items: [BottomTabItem]
12
18
  let floatingButton: BottomTabFloatingButton?
13
19
  let selectedIndex: Int
14
20
  let onTabSelected: (Int) -> Void
15
- let bottomInset: CGFloat
21
+ var onTabLongPress: ((Int) -> Void)?
16
22
 
17
23
  @Environment(\.screenLayout) private var layout
18
24
  @Environment(\.appTheme) private var theme
@@ -22,25 +28,18 @@ struct LegacyBottomTabBar: View {
22
28
  private var mid: Int { items.count / 2 }
23
29
 
24
30
  private var tabWidth: CGFloat {
25
- let available = floatingButton != nil ? screenWidth - legacyFloatingButtonWidth : screenWidth
26
- return available / CGFloat(max(items.count, 1))
31
+ if floatingButton != nil {
32
+ return (screenWidth - legacyBottomTabFloatingButtonWidth) / CGFloat(items.count)
33
+ }
34
+ return screenWidth / CGFloat(items.count)
27
35
  }
28
36
 
29
37
  private var indicatorOffset: CGFloat {
30
- let adjust: CGFloat = (floatingButton != nil && selectedIndex >= mid) ? legacyFloatingButtonWidth : 0
38
+ let adjust: CGFloat = (floatingButton != nil && selectedIndex >= mid) ? legacyBottomTabFloatingButtonWidth : 0
31
39
  return tabWidth * CGFloat(selectedIndex) + tabWidth / 2 - screenWidth / 2 + adjust
32
40
  }
33
41
 
34
42
  var body: some View {
35
- VStack(spacing: 0) {
36
- bar
37
- theme.colors.background.surface
38
- .frame(height: bottomInset + Spacing.S)
39
- .ignoresSafeArea(edges: .horizontal)
40
- }
41
- }
42
-
43
- private var bar: some View {
44
43
  ZStack(alignment: .bottom) {
45
44
  HStack(spacing: 0) {
46
45
  if floatingButton == nil {
@@ -48,7 +47,7 @@ struct LegacyBottomTabBar: View {
48
47
  } else {
49
48
  tabItems(from: 0, to: mid)
50
49
  Spacer()
51
- .frame(width: legacyFloatingButtonWidth)
50
+ .frame(width: legacyBottomTabFloatingButtonWidth)
52
51
  .padding(.horizontal, Spacing.XXS)
53
52
  tabItems(from: mid, to: items.count)
54
53
  }
@@ -57,16 +56,22 @@ struct LegacyBottomTabBar: View {
57
56
  .frame(height: LEGACY_BOTTOM_TAB_BAR_HEIGHT)
58
57
  .background(theme.colors.background.surface.ignoresSafeArea(edges: .horizontal))
59
58
 
59
+ // Animated selection indicator.
60
60
  RoundedRectangle(cornerRadius: 2)
61
61
  .fill(theme.colors.primary)
62
62
  .frame(width: 44, height: 2)
63
63
  .offset(x: indicatorOffset, y: -LEGACY_BOTTOM_TAB_BAR_HEIGHT + 2)
64
64
  .animation(.easeInOut(duration: 0.25), value: selectedIndex)
65
65
 
66
- LinearGradient(colors: [Color.black.opacity(0.05), .clear], startPoint: .bottom, endPoint: .top)
67
- .frame(height: 6)
68
- .frame(maxWidth: .infinity)
69
- .offset(y: -LEGACY_BOTTOM_TAB_BAR_HEIGHT)
66
+ // Top shadow.
67
+ LinearGradient(
68
+ colors: [Color.black.opacity(0.05), .clear],
69
+ startPoint: .bottom,
70
+ endPoint: .top
71
+ )
72
+ .frame(height: 6)
73
+ .frame(maxWidth: .infinity)
74
+ .offset(y: -LEGACY_BOTTOM_TAB_BAR_HEIGHT)
70
75
 
71
76
  if let floatingButton {
72
77
  LegacyCenterFloatingButton(data: floatingButton)
@@ -82,27 +87,31 @@ struct LegacyBottomTabBar: View {
82
87
  selected: index == selectedIndex,
83
88
  // from the icon's center to the cell's end edge, inside both XXS paddings
84
89
  badgeMaxWidth: tabWidth / 2 - Spacing.XXS * 2,
85
- onClick: { onTabSelected(index) }
90
+ onClick: { onTabSelected(index) },
91
+ onLongClick: onTabLongPress.map { callback in { callback(index) } }
86
92
  )
87
93
  .frame(maxWidth: .infinity)
88
94
  }
89
95
  }
90
96
  }
91
97
 
98
+ // MARK: - Tab item
99
+
92
100
  private struct LegacyTabBarItem: View {
93
101
  let item: BottomTabItem
94
102
  let selected: Bool
95
103
  let badgeMaxWidth: CGFloat
96
104
  let onClick: () -> Void
105
+ let onLongClick: (() -> Void)?
97
106
 
98
107
  @Environment(\.appTheme) private var theme
99
108
 
100
109
  private var tintColor: Color { selected ? theme.colors.primary : theme.colors.text.hint }
101
110
 
102
- /// Compose's `formatLabel`: a badge that is the number "0" is hidden.
111
+ /// Mirrors Compose's `formatLabel`: hide a badge that is the number "0".
103
112
  private var badgeLabel: String? {
104
113
  guard let label = item.badgeLabel else { return nil }
105
- if let number = Int(label), number == 0 { return nil }
114
+ if let n = Int(label), n == 0 { return nil }
106
115
  return label
107
116
  }
108
117
 
@@ -133,15 +142,31 @@ private struct LegacyTabBarItem: View {
133
142
  .truncationMode(.tail)
134
143
  }
135
144
  .frame(maxWidth: .infinity, maxHeight: .infinity)
136
- .padding(Spacing.S)
145
+ .padding(.horizontal, Spacing.S)
146
+ .padding(.vertical, Spacing.S)
137
147
  .frame(maxWidth: .infinity, maxHeight: .infinity)
138
148
  .padding(.horizontal, Spacing.XXS)
139
149
  .contentShape(Rectangle())
140
150
  .onTapGesture { onClick() }
151
+ .modifier(LegacyTabLongPress(action: onLongClick))
141
152
  }
142
153
  }
143
154
 
144
- /// The 48 primary circle in the bar's notch; `iconContent` replaces the icon, `labelContent` overlays the label.
155
+ /// Only attached with a callback, so a held tab without one still selects on release.
156
+ private struct LegacyTabLongPress: ViewModifier {
157
+ let action: (() -> Void)?
158
+
159
+ func body(content: Content) -> some View {
160
+ if let action {
161
+ content.onLongPressGesture(minimumDuration: 0.5, perform: action)
162
+ } else {
163
+ content
164
+ }
165
+ }
166
+ }
167
+
168
+ // MARK: - Center floating button
169
+
145
170
  private struct LegacyCenterFloatingButton: View {
146
171
  let data: BottomTabFloatingButton
147
172
 
@@ -153,74 +178,18 @@ private struct LegacyCenterFloatingButton: View {
153
178
  Circle()
154
179
  .fill(theme.colors.primary)
155
180
  .frame(width: 48, height: 48)
156
- .overlay(icon)
181
+ .overlay(Icon(source: data.icon, size: 28, color: .white))
157
182
  Spacer().frame(height: 4)
158
183
  MomoText(data.label, typography: .labelXsMedium, color: Colors.black01, textAlign: .center, maxLines: 1)
159
184
  .frame(maxWidth: .infinity)
160
185
  .frame(height: 14)
161
186
  .background(theme.colors.primary)
162
187
  .clipShape(RoundedRectangle(cornerRadius: Radius.XL))
163
- .overlay(data.labelContent)
164
188
  }
165
- .frame(width: legacyFloatingButtonWidth)
189
+ .frame(width: legacyBottomTabFloatingButtonWidth)
166
190
  .padding(.horizontal, Spacing.XXS)
167
191
  .padding(.vertical, Spacing.S)
168
192
  .contentShape(Rectangle())
169
193
  .onTapGesture { data.onPress() }
170
194
  }
171
-
172
- @ViewBuilder
173
- private var icon: some View {
174
- if let iconContent = data.iconContent {
175
- iconContent
176
- } else {
177
- Icon(source: data.icon, size: 28, color: .white)
178
- }
179
- }
180
- }
181
-
182
- /// Compose's legacy `CurvedContainer`: the surface notch carved into the bar's top edge behind the center button.
183
- private struct LegacyCurvedContainer: View {
184
- private let circleSize: CGFloat = 48
185
- private let iconSize: CGFloat = 28
186
- private let circleOverSize: CGFloat = 2
187
- private let width: CGFloat = 71
188
- private let height: CGFloat = 16
189
-
190
- var body: some View {
191
- let circleOverTop = circleSize - iconSize - 10 + circleOverSize
192
- LegacyCurvedShape(circleOverTop: circleOverTop, centerX: width / 2, circleOverR: circleSize / 2 + circleOverSize)
193
- .fill(Colors.black01)
194
- .frame(width: width, height: height)
195
- .offset(y: 24)
196
- .zIndex(-1)
197
- }
198
- }
199
-
200
- /// A flat bar with a smooth circular dip in the middle, sized to cradle the floating button.
201
- private struct LegacyCurvedShape: Shape {
202
- let circleOverTop: CGFloat
203
- let centerX: CGFloat
204
- let circleOverR: CGFloat
205
-
206
- func path(in rect: CGRect) -> Path {
207
- var path = Path()
208
- path.move(to: CGPoint(x: 0, y: circleOverTop))
209
- path.addLine(to: CGPoint(x: centerX - circleOverR - 40, y: circleOverTop))
210
- path.addCurve(
211
- to: CGPoint(x: centerX, y: 0),
212
- control1: CGPoint(x: centerX - circleOverR, y: circleOverTop),
213
- control2: CGPoint(x: centerX - circleOverR, y: 0)
214
- )
215
- path.addCurve(
216
- to: CGPoint(x: centerX + circleOverR + 40, y: circleOverTop),
217
- control1: CGPoint(x: centerX + circleOverR, y: 0),
218
- control2: CGPoint(x: centerX + circleOverR, y: circleOverTop)
219
- )
220
- path.addLine(to: CGPoint(x: rect.width, y: circleOverTop))
221
- path.addLine(to: CGPoint(x: rect.width, y: 60))
222
- path.addLine(to: CGPoint(x: 0, y: 60))
223
- path.closeSubpath()
224
- return path
225
- }
226
195
  }
@@ -0,0 +1,63 @@
1
+ //
2
+ // LegacyCurvedContainer.swift
3
+ // MoMoUIKits
4
+ //
5
+ // CurvedContainer.swift from main before the DS-984 redesign (5f31e0d4), verbatim except the Legacy prefix.
6
+ //
7
+
8
+ import SwiftUI
9
+
10
+ struct LegacyCurvedContainer: View {
11
+ var circleSize: CGFloat = 48
12
+ var tabBarItemIconSize: CGFloat = 28
13
+ var circleOverSize: CGFloat = 2
14
+ var width: CGFloat = 71
15
+ var height: CGFloat = 16
16
+ var color: Color = Colors.black01
17
+
18
+ var body: some View {
19
+ let circlePositionTop = circleSize - tabBarItemIconSize - 10
20
+ let circleOverTop = circlePositionTop + circleOverSize
21
+ let circleR = circleSize / 2
22
+ let circleOverR = circleR + circleOverSize
23
+ let centerX = width / 2
24
+
25
+ LegacyCurvedShape(circleOverTop: circleOverTop, centerX: centerX, circleOverR: circleOverR, width: width)
26
+ .fill(color)
27
+ .frame(width: width, height: height)
28
+ .offset(y: 24)
29
+ .zIndex(-1)
30
+ }
31
+ }
32
+
33
+ /// Mirrors Compose's `getPath`: a flat bar with a smooth circular dip in the
34
+ /// middle, sized to cradle the floating button.
35
+ private struct LegacyCurvedShape: Shape {
36
+ let circleOverTop: CGFloat
37
+ let centerX: CGFloat
38
+ let circleOverR: CGFloat
39
+ let width: CGFloat
40
+
41
+ func path(in rect: CGRect) -> Path {
42
+ var path = Path()
43
+ path.move(to: CGPoint(x: 0, y: circleOverTop))
44
+ path.addLine(to: CGPoint(x: centerX - circleOverR - 40, y: circleOverTop))
45
+
46
+ path.addCurve(
47
+ to: CGPoint(x: centerX, y: 0),
48
+ control1: CGPoint(x: centerX - circleOverR, y: circleOverTop),
49
+ control2: CGPoint(x: centerX - circleOverR, y: 0)
50
+ )
51
+ path.addCurve(
52
+ to: CGPoint(x: centerX + circleOverR + 40, y: circleOverTop),
53
+ control1: CGPoint(x: centerX + circleOverR, y: 0),
54
+ control2: CGPoint(x: centerX + circleOverR, y: circleOverTop)
55
+ )
56
+
57
+ path.addLine(to: CGPoint(x: width, y: circleOverTop))
58
+ path.addLine(to: CGPoint(x: width, y: 60))
59
+ path.addLine(to: CGPoint(x: 0, y: 60))
60
+ path.closeSubpath()
61
+ return path
62
+ }
63
+ }
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |s|
2
2
  s.name = 'MoMoUIKits'
3
- s.version = '0.169.15-beta.4'
3
+ s.version = '0.169.15-beta.5'
4
4
  s.summary = 'MoMoUIKits for iOS'
5
5
  s.homepage = 'https://momo.vn'
6
6
  s.license = { :type => 'MIT' }
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |s|
2
2
  s.name = 'MoMoUIKitsDemo'
3
- s.version = '0.169.15-beta.4'
3
+ s.version = '0.169.15-beta.5'
4
4
  s.summary = 'Demo browser for MoMoUIKits SwiftUI components'
5
5
  s.homepage = 'https://momo.vn'
6
6
  s.license = { :type => 'MIT' }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.169.15-beta.4",
3
+ "version": "0.169.15-beta.5",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "publish:local": "bash publish.sh local"