@momo-kits/native-kits 0.168.1-beta.37-debug → 0.168.1-beta.38-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 (47) hide show
  1. package/CLAUDE.md +2 -3
  2. package/compose/build.gradle.kts +1 -1
  3. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
  4. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +81 -72
  5. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +13 -8
  6. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +163 -54
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +12 -17
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +34 -27
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +319 -167
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +93 -326
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -2
  18. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +3 -2
  19. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +3 -9
  20. package/ios/Input/Input.swift +1 -3
  21. package/ios/Input/InputTextArea.swift +1 -3
  22. package/ios/Layout/ScreenLayout.swift +24 -28
  23. package/ios/Navigation/BottomSheet.swift +157 -29
  24. package/ios/Navigation/BottomTab/BottomTab.swift +48 -67
  25. package/ios/Navigation/BottomTab/BottomTabBar.swift +280 -132
  26. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  27. package/ios/Navigation/BottomTab/DuoTabBar.swift +72 -292
  28. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  29. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  30. package/ios/Navigation/ModalScreen.swift +7 -18
  31. package/ios/Navigation/StackScreen.swift +3 -1
  32. package/ios/Popup/PopupDisplay.swift +2 -4
  33. package/ios/Popup/PopupInput.swift +2 -4
  34. package/ios/Popup/PopupLayout.swift +9 -10
  35. package/ios/Popup/PopupNotify.swift +23 -26
  36. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  37. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  38. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  39. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +0 -103
  40. package/package.json +1 -1
  41. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -187
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoLiquidSelection.kt +0 -380
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
  45. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
  46. package/ios/Layout/ModalLayout.swift +0 -152
  47. package/ios/Navigation/BottomTab/DuoLiquidSelection.swift +0 -364
@@ -16,7 +16,6 @@ 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)?
20
19
 
21
20
  @EnvironmentObject private var navigator: Navigator
22
21
  /// The screen hosting the tabs (Compose's `LocalNavigation` in BottomTab).
@@ -35,32 +34,28 @@ public struct BottomTab: View {
35
34
  /// starts compressed; tapping the compressed one swaps them.
36
35
  /// `onTabPress` gets every tab press with the switch to perform, e.g. after a login gate.
37
36
  /// `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.
39
37
  public init(
40
38
  items: [BottomTabItem],
41
39
  floatingButton: BottomTabFloatingButton? = nil,
42
40
  compressionBehavior: DuoBarCompressionBehavior = .toolbar,
43
41
  initialRouteName: String? = nil,
44
42
  onTabPress: ((_ index: Int, _ switchTab: @escaping () -> Void) -> Void)? = nil,
45
- backToInitialTab: Bool = true,
46
- onTabLongPress: ((_ index: Int) -> Void)? = nil
43
+ backToInitialTab: Bool = true
47
44
  ) {
48
45
  self.items = items
49
46
  self.floatingButton = floatingButton
50
47
  self.compressionBehavior = compressionBehavior
51
48
  self.onTabPress = onTabPress
52
49
  self.backToInitialTab = backToInitialTab
53
- self.onTabLongPress = onTabLongPress
54
50
  let start = items.firstIndex { $0.name == initialRouteName } ?? 0
55
51
  _startIndex = State(initialValue: start)
56
52
  _selectedIndex = State(initialValue: start)
57
53
  }
58
54
 
59
55
  private var bottomInset: CGFloat { safeAreaBottomInset() }
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
- }
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 }
64
59
 
65
60
  private var compression: DuoBarCompression {
66
61
  DuoBarCompression.resolve(
@@ -105,30 +100,16 @@ public struct BottomTab: View {
105
100
  floatingButton: floatingButton,
106
101
  selectedIndex: selectedIndex,
107
102
  onTabSelected: selectTab,
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
- }
103
+ compression: compression
117
104
  )
118
105
  } else {
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
- }
106
+ BottomTabBar(
107
+ items: items,
108
+ floatingButton: floatingButton,
109
+ selectedIndex: selectedIndex,
110
+ onTabSelected: selectTab,
111
+ bottomInset: bottomInset
112
+ )
132
113
  }
133
114
  }
134
115
  .frame(maxWidth: .infinity, maxHeight: .infinity)
@@ -150,6 +131,7 @@ public struct BottomTab: View {
150
131
  }
151
132
 
152
133
  private func selectTab(_ index: Int) {
134
+ navigator.maxApi?.triggerEventVibration("light")
153
135
  let switchTab = { if index != selectedIndex { selectedIndex = index } }
154
136
  if let onTabPress { onTabPress(index, switchTab) } else { switchTab() }
155
137
  }
@@ -221,11 +203,11 @@ private struct TabHost: UIViewControllerRepresentable {
221
203
 
222
204
  private final class TabController: UIViewController {
223
205
  private final class Tab {
224
- let motion = TabMotion()
225
206
  var host: UIHostingController<AnyView>!
226
207
  }
227
208
 
228
- private static let switchDuration: TimeInterval = 0.2
209
+ /// The tab switch: the screens slide in index order over 280ms, CSS `ease`.
210
+ private static let switchDuration: TimeInterval = 0.28
229
211
 
230
212
  private var tabs: [Int: Tab] = [:]
231
213
  private var selectedIndex: Int?
@@ -239,7 +221,7 @@ private final class TabController: UIViewController {
239
221
 
240
222
  override func viewDidLayoutSubviews() {
241
223
  super.viewDidLayoutSubviews()
242
- for subview in view.subviews { subview.frame = view.bounds }
224
+ for subview in view.subviews { place(subview) }
243
225
  }
244
226
 
245
227
  func update(
@@ -256,33 +238,43 @@ private final class TabController: UIViewController {
256
238
  }
257
239
  if let selectedIndex, tabs[selectedIndex] == nil { self.selectedIndex = nil }
258
240
  // hidden tabs too, so a tab coming back already shows the latest items and environment
259
- for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex, existing) }
241
+ for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex) }
260
242
  guard (0..<count).contains(index), index != selectedIndex else { return }
261
243
 
262
- let previous = selectedIndex.flatMap { tabs[$0] }
244
+ let previousIndex = selectedIndex
245
+ let previous = previousIndex.flatMap { tabs[$0] }
263
246
  selectedIndex = index
264
247
  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
265
250
  attach(selected)
266
251
 
267
- guard let previous, view.window != nil else {
268
- selected.motion.visible = true
252
+ guard let previous, let previousIndex, view.window != nil else {
253
+ selected.host.view.transform = .identity
269
254
  previous.map(leave)
270
255
  return
271
256
  }
272
257
  previous.host.view.isUserInteractionEnabled = false
273
- // a frame at the start values first, so a tab created just now fades in too
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
274
261
  DispatchQueue.main.async {
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)
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()
280
272
  }
281
273
  }
282
274
 
283
275
  private func makeTab(_ index: Int) -> Tab {
284
276
  let tab = Tab()
285
- let host = UIHostingController(rootView: rootView(index, tab))
277
+ let host = UIHostingController(rootView: rootView(index))
286
278
  host.view.backgroundColor = .clear
287
279
  addChild(host)
288
280
  host.didMove(toParent: self)
@@ -291,14 +283,20 @@ private final class TabController: UIViewController {
291
283
  return tab
292
284
  }
293
285
 
294
- private func rootView(_ index: Int, _ tab: Tab) -> AnyView {
295
- AnyView(TabCard(motion: tab.motion, content: content(index)).environment(\.self, environment))
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)
296
294
  }
297
295
 
298
296
  private func attach(_ tab: Tab) {
299
297
  let hostView: UIView = tab.host.view
300
298
  hostView.isUserInteractionEnabled = true
301
- hostView.frame = view.bounds
299
+ place(hostView)
302
300
  if hostView.superview === view {
303
301
  view.bringSubviewToFront(hostView)
304
302
  } else {
@@ -310,6 +308,7 @@ private final class TabController: UIViewController {
310
308
  private func leave(_ tab: Tab) {
311
309
  guard selectedIndex.flatMap({ tabs[$0] }) !== tab else { return }
312
310
  tab.host.view.removeFromSuperview()
311
+ tab.host.view.transform = .identity
313
312
  }
314
313
 
315
314
  private func tearDown(_ tab: Tab) {
@@ -319,27 +318,9 @@ private final class TabController: UIViewController {
319
318
  }
320
319
  }
321
320
 
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
-
339
321
  /// Bottom safe-area inset (home indicator).
340
322
  private func safeAreaBottomInset() -> CGFloat {
341
- let bottomInset = UIApplication.shared.connectedScenes
323
+ UIApplication.shared.connectedScenes
342
324
  .compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
343
325
  .first ?? 0
344
- return min(bottomInset, 21)
345
326
  }