@momo-kits/native-kits 0.168.1-beta.32-debug → 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 (31) hide show
  1. package/CLAUDE.md +1 -0
  2. package/compose/build.gradle.kts +1 -1
  3. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +2 -3
  4. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  5. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +9 -9
  6. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +26 -34
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +167 -319
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +71 -79
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +380 -0
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +326 -93
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +2 -3
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +1 -3
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  14. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +2 -3
  15. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  16. package/ios/Input/Input.swift +3 -1
  17. package/ios/Input/InputTextArea.swift +3 -1
  18. package/ios/Navigation/BottomTab/BottomTab.swift +67 -48
  19. package/ios/Navigation/BottomTab/BottomTabBar.swift +131 -281
  20. package/ios/Navigation/BottomTab/CurvedContainer.swift +47 -51
  21. package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +364 -0
  22. package/ios/Navigation/BottomTab/DuoTabBar.swift +292 -72
  23. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  24. package/ios/Navigation/StackScreen.swift +1 -3
  25. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +59 -272
  26. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +90 -0
  27. package/package.json +1 -1
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -106
  29. package/ios/Navigation/BottomTab/TabBarMetrics.swift +0 -88
  30. package/ios-demo/Resources/tabbar_scan_qr_button.json +0 -1
  31. package/ios-demo/Resources/tabbar_scan_qr_label.json +0 -1
@@ -16,6 +16,7 @@ public struct BottomTab: View {
16
16
  private let compressionBehavior: DuoBarCompressionBehavior
17
17
  private let onTabPress: ((_ index: Int, _ switchTab: @escaping () -> Void) -> Void)?
18
18
  private let backToInitialTab: Bool
19
+ private let onTabLongPress: ((_ index: Int) -> Void)?
19
20
 
20
21
  @EnvironmentObject private var navigator: Navigator
21
22
  /// The screen hosting the tabs (Compose's `LocalNavigation` in BottomTab).
@@ -34,28 +35,32 @@ public struct BottomTab: View {
34
35
  /// starts compressed; tapping the compressed one swaps them.
35
36
  /// `onTabPress` gets every tab press with the switch to perform, e.g. after a login gate.
36
37
  /// `backToInitialTab`: back off another tab returns to the initial one before leaving the screen.
38
+ /// `onTabLongPress`: RN `tabLongPress`; on iPhone Duo the held tab is still selected on release.
37
39
  public init(
38
40
  items: [BottomTabItem],
39
41
  floatingButton: BottomTabFloatingButton? = nil,
40
42
  compressionBehavior: DuoBarCompressionBehavior = .toolbar,
41
43
  initialRouteName: String? = nil,
42
44
  onTabPress: ((_ index: Int, _ switchTab: @escaping () -> Void) -> Void)? = nil,
43
- backToInitialTab: Bool = true
45
+ backToInitialTab: Bool = true,
46
+ onTabLongPress: ((_ index: Int) -> Void)? = nil
44
47
  ) {
45
48
  self.items = items
46
49
  self.floatingButton = floatingButton
47
50
  self.compressionBehavior = compressionBehavior
48
51
  self.onTabPress = onTabPress
49
52
  self.backToInitialTab = backToInitialTab
53
+ self.onTabLongPress = onTabLongPress
50
54
  let start = items.firstIndex { $0.name == initialRouteName } ?? 0
51
55
  _startIndex = State(initialValue: start)
52
56
  _selectedIndex = State(initialValue: start)
53
57
  }
54
58
 
55
59
  private var bottomInset: CGFloat { safeAreaBottomInset() }
56
- // the bars float over the content (tab screens keep clear of them through duoTabBarInsets) or sit
57
- // in the side strip, so only the home indicator is kept clear
58
- private var reservedBottom: CGFloat { layout.insets.bottom }
60
+ // the Duo bars overlay the content or sit in the side strip, so only the home indicator is kept clear
61
+ private var reservedBottom: CGFloat {
62
+ layout.isIPhoneDuo ? layout.insets.bottom : BOTTOM_TAB_BAR_HEIGHT + bottomInset + Spacing.S
63
+ }
59
64
 
60
65
  private var compression: DuoBarCompression {
61
66
  DuoBarCompression.resolve(
@@ -100,16 +105,30 @@ public struct BottomTab: View {
100
105
  floatingButton: floatingButton,
101
106
  selectedIndex: selectedIndex,
102
107
  onTabSelected: selectTab,
103
- compression: compression
108
+ compression: compression,
109
+ onTabLongPress: onTabLongPress,
110
+ onTick: { [maxApi = navigator.maxApi] in
111
+ if let maxApi {
112
+ maxApi.triggerEventVibration("light")
113
+ } else {
114
+ UIImpactFeedbackGenerator(style: .light).impactOccurred()
115
+ }
116
+ }
104
117
  )
105
118
  } else {
106
- BottomTabBar(
107
- items: items,
108
- floatingButton: floatingButton,
109
- selectedIndex: selectedIndex,
110
- onTabSelected: selectTab,
111
- bottomInset: bottomInset
112
- )
119
+ // Tab bar + home-indicator filler.
120
+ VStack(spacing: 0) {
121
+ BottomTabBar(
122
+ items: items,
123
+ floatingButton: floatingButton,
124
+ selectedIndex: selectedIndex,
125
+ onTabSelected: selectTab,
126
+ onTabLongPress: onTabLongPress
127
+ )
128
+ theme.colors.background.surface
129
+ .frame(height: bottomInset + Spacing.S)
130
+ .ignoresSafeArea(edges: .horizontal)
131
+ }
113
132
  }
114
133
  }
115
134
  .frame(maxWidth: .infinity, maxHeight: .infinity)
@@ -131,7 +150,6 @@ public struct BottomTab: View {
131
150
  }
132
151
 
133
152
  private func selectTab(_ index: Int) {
134
- navigator.maxApi?.triggerEventVibration("light")
135
153
  let switchTab = { if index != selectedIndex { selectedIndex = index } }
136
154
  if let onTabPress { onTabPress(index, switchTab) } else { switchTab() }
137
155
  }
@@ -203,11 +221,11 @@ private struct TabHost: UIViewControllerRepresentable {
203
221
 
204
222
  private final class TabController: UIViewController {
205
223
  private final class Tab {
224
+ let motion = TabMotion()
206
225
  var host: UIHostingController<AnyView>!
207
226
  }
208
227
 
209
- /// The tab switch: the screens slide in index order over 280ms, CSS `ease`.
210
- private static let switchDuration: TimeInterval = 0.28
228
+ private static let switchDuration: TimeInterval = 0.2
211
229
 
212
230
  private var tabs: [Int: Tab] = [:]
213
231
  private var selectedIndex: Int?
@@ -221,7 +239,7 @@ private final class TabController: UIViewController {
221
239
 
222
240
  override func viewDidLayoutSubviews() {
223
241
  super.viewDidLayoutSubviews()
224
- for subview in view.subviews { place(subview) }
242
+ for subview in view.subviews { subview.frame = view.bounds }
225
243
  }
226
244
 
227
245
  func update(
@@ -238,43 +256,33 @@ private final class TabController: UIViewController {
238
256
  }
239
257
  if let selectedIndex, tabs[selectedIndex] == nil { self.selectedIndex = nil }
240
258
  // hidden tabs too, so a tab coming back already shows the latest items and environment
241
- for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex) }
259
+ for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex, existing) }
242
260
  guard (0..<count).contains(index), index != selectedIndex else { return }
243
261
 
244
- let previousIndex = selectedIndex
245
- let previous = previousIndex.flatMap { tabs[$0] }
262
+ let previous = selectedIndex.flatMap { tabs[$0] }
246
263
  selectedIndex = index
247
264
  let selected = tabs[index] ?? makeTab(index)
248
- // a tab selected again while it leaves carries on from where it is
249
- let entering = selected.host.view.superview == nil
250
265
  attach(selected)
251
266
 
252
- guard let previous, let previousIndex, view.window != nil else {
253
- selected.host.view.transform = .identity
267
+ guard let previous, view.window != nil else {
268
+ selected.motion.visible = true
254
269
  previous.map(leave)
255
270
  return
256
271
  }
257
272
  previous.host.view.isUserInteractionEnabled = false
258
- let offset = index > previousIndex ? view.bounds.width : -view.bounds.width
259
- if entering { selected.host.view.transform = CGAffineTransform(translationX: offset, y: 0) }
260
- // a frame at the start values first, so a tab created just now slides in with its content
273
+ // a frame at the start values first, so a tab created just now fades in too
261
274
  DispatchQueue.main.async {
262
- let animator = UIViewPropertyAnimator(
263
- duration: Self.switchDuration,
264
- controlPoint1: CGPoint(x: 0.25, y: 0.1),
265
- controlPoint2: CGPoint(x: 0.25, y: 1)
266
- ) {
267
- selected.host.view.transform = .identity
268
- previous.host.view.transform = CGAffineTransform(translationX: -offset, y: 0)
269
- }
270
- animator.addCompletion { [weak self] _ in self?.leave(previous) }
271
- animator.startAnimation()
275
+ selected.motion.visible = true
276
+ previous.motion.visible = false
277
+ }
278
+ DispatchQueue.main.asyncAfter(deadline: .now() + Self.switchDuration) { [weak self] in
279
+ self?.leave(previous)
272
280
  }
273
281
  }
274
282
 
275
283
  private func makeTab(_ index: Int) -> Tab {
276
284
  let tab = Tab()
277
- let host = UIHostingController(rootView: rootView(index))
285
+ let host = UIHostingController(rootView: rootView(index, tab))
278
286
  host.view.backgroundColor = .clear
279
287
  addChild(host)
280
288
  host.didMove(toParent: self)
@@ -283,20 +291,14 @@ private final class TabController: UIViewController {
283
291
  return tab
284
292
  }
285
293
 
286
- private func rootView(_ index: Int) -> AnyView {
287
- AnyView(content(index).environment(\.self, environment))
288
- }
289
-
290
- /// Bounds and center, a sliding tab carries a transform that frame doesn't work with.
291
- private func place(_ subview: UIView) {
292
- subview.bounds = view.bounds
293
- subview.center = CGPoint(x: view.bounds.midX, y: view.bounds.midY)
294
+ private func rootView(_ index: Int, _ tab: Tab) -> AnyView {
295
+ AnyView(TabCard(motion: tab.motion, content: content(index)).environment(\.self, environment))
294
296
  }
295
297
 
296
298
  private func attach(_ tab: Tab) {
297
299
  let hostView: UIView = tab.host.view
298
300
  hostView.isUserInteractionEnabled = true
299
- place(hostView)
301
+ hostView.frame = view.bounds
300
302
  if hostView.superview === view {
301
303
  view.bringSubviewToFront(hostView)
302
304
  } else {
@@ -308,7 +310,6 @@ private final class TabController: UIViewController {
308
310
  private func leave(_ tab: Tab) {
309
311
  guard selectedIndex.flatMap({ tabs[$0] }) !== tab else { return }
310
312
  tab.host.view.removeFromSuperview()
311
- tab.host.view.transform = .identity
312
313
  }
313
314
 
314
315
  private func tearDown(_ tab: Tab) {
@@ -318,9 +319,27 @@ private final class TabController: UIViewController {
318
319
  }
319
320
  }
320
321
 
322
+ private final class TabMotion: ObservableObject {
323
+ @Published var visible = false
324
+ }
325
+
326
+ /// The tab switch: 0.97 scale + fade over 200ms, both ways (Compose's tab enter / exit transitions).
327
+ private struct TabCard: View {
328
+ @ObservedObject var motion: TabMotion
329
+ let content: AnyView
330
+
331
+ var body: some View {
332
+ content
333
+ .opacity(motion.visible ? 1 : 0)
334
+ .scaleEffect(motion.visible ? 1 : 0.97)
335
+ .animation(.easeInOut(duration: 0.2), value: motion.visible)
336
+ }
337
+ }
338
+
321
339
  /// Bottom safe-area inset (home indicator).
322
340
  private func safeAreaBottomInset() -> CGFloat {
323
- UIApplication.shared.connectedScenes
341
+ let bottomInset = UIApplication.shared.connectedScenes
324
342
  .compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
325
343
  .first ?? 0
344
+ return min(bottomInset, 21)
326
345
  }