@momo-kits/native-kits 0.168.1-beta.31 → 0.168.1-beta.32

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.
package/CLAUDE.md CHANGED
@@ -71,13 +71,12 @@ Publishing is automated (`publish.sh` + GitLab CI on `[ci build]` / `main`). Do
71
71
  ## Screen layout / iPhone Duo (port of RN `useScreenLayout`, momo-kits !664)
72
72
 
73
73
  - `layout/ScreenLayout.kt`: `getScreenLayout()` returns window size, raw top/bottom + side insets, `contentWidth`, header geometry, the iPhone Duo `sideBar` and `duoTopInset`. `NavigationContainer` computes it once and provides `LocalScreenLayout`; reactive to fold/unfold and rotation (window size + `WindowInsets`). Metrics (`DuoMetrics`, 72pt iPhone header floor, 20pt status-bar threshold) mirror RN `Layout/utils.ts` — change both together.
74
- - iPhone-only: everything gates on `isPhoneIdiom()` (`platform/`), never on "iOS", so iPad windows keep the regular layout. Two detectors, as in RN: `isIPhoneDuo` (window aspect < 1.6 or asymmetric side insets) drives layout; `isIPhoneDuoDevice` (Apple's foldable check: a `.division` reserved region, queried with include-inactive; Swift also latches on `UIHingeInteraction`; or asymmetric side insets, since the outer display reports no hinge; on Android the hinge angle sensor feature, so foldables get the sizes but no side strip or side column) drives popups, modal and bottom sheet.
74
+ - iPhone-only: everything gates on `isPhoneIdiom()` (`platform/`), never on "iOS", so iPad windows keep the regular layout. Two detectors, as in RN: `isIPhoneDuo` (window aspect < 1.6 or asymmetric side insets) drives layout; `isIPhoneDuoDevice` (Apple's foldable check: a `.division` reserved region, queried with include-inactive; Swift also latches on `UIHingeInteraction`; or asymmetric side insets, since the outer display reports no hinge) drives popups, modal and bottom sheet.
75
75
  - Header height is `headerHeight` (not `AppStatusBar + HEADER_HEIGHT`); the bar row is `headerBarHeight` and starts `headerStatusBarHeight` below the window top. When the status bar is off the top edge (iPhone landscape, iPhone Duo) `headerStatusBarHeight` is 0 so the title stays centered — except on the Duo outer display: in portrait the header is 76pt and the row starts at 14pt so the title centers on the camera punchout; in landscape the row centers on the camera when it sits at the top end of the strip (else on the back button) and the header reaches 8pt below the back button.
76
76
  - iPhone Duo inner display in portrait (status bar on top): the header row shares the status bar band — `headerHeight` 94pt (2 × the clock digits' y 47), `headerStatusBarHeight` 0 — and `ScreenLayout.statusBarClearance` keeps it between the clock / battery clusters (from reserved regions, else 128pt on the right). Back and toolkit use the 48pt side bar controls laid out horizontally (`ToolkitLayout.SideBarRow`); the collapsed search and a centered title stay clear of the clusters. Port of momo-kits `90af33ba2`.
77
77
  - iPhone Duo with a side strip ≥ 60pt: back + toolkit leave the bar for `HeaderSideBar` (`navigation/component/SideBar.kt`, 48pt glass controls); custom header-right stays in the bar. `sideBar.top` is 170pt in portrait, 120pt on the inner display in landscape (height ≥ 600), 24pt on the outer display in landscape, or below the header when the status bar is on top; UIKit's `statusBarFrame` is useless on Duo. Unlike RN the column is clamped above footer (24pt gap) / rail (12pt gap).
78
78
  - Reserved regions (iOS 27.1 `reservedRegionsOfKind:`, reached through the ObjC runtime so older SDKs still build): a probe `UIView` (`platform/ReservedRegions.ios.kt` on the Compose root view; `ReservedRegionsProbe` inside SwiftUI `momoScreenLayout()`) re-reads them in `layoutSubviews`, which UIKit re-runs when they change. They push `sideBar.top` below the status cluster as it grows for calls / Live Activities, and `sideBar.bottom` (≥ 24pt) above a camera at the bottom end of the strip.
79
79
  - Tab bar on Duo is `bottomtab/DuoTabBar.kt`: a rail in the side strip (`sideBar.bottom` above the window bottom, QR below it) or, without a side bar, a floating bar spanning 6/8 grid columns. Both overlay the content; `duoFloatingTabBarInset` pads tab content, footer and FAB.
80
- - Duo tab selection motion (`bottomtab/DuoLiquidSelection.kt` / `ios/Navigation/BottomTab/DuoLiquidSelection.swift`, port of RN `useLiquidSelection.ts`, momo-kits !682): press lifts the lens, a drag past 10pt takes over (Compose: the bar's `pointerInput` consumes and so cancels the tab's clickable; SwiftUI: one `DragGesture` over the bar, tabs are not `Button`s), long press calls `BottomTab(onTabLongPress)` and release still selects, Reduce Motion (`platform/ReduceMotion`) falls back to a plain slide. SwiftUI integrates the lens spring on a display link because the stretch and the tabs' active tint read it every frame. Constants mirror RN — change both together.
81
80
  - Bar compression (`bottomtab/DuoBarCompression.kt`, HIG "Vertical controls"): when toolbar + rail don't fit in the strip, one is compressed — the toolkit into a `navigation_menu` button, the rail into one button showing the current tab — and tapping it swaps them; `BottomTab(compressionBehavior)` picks which starts compressed. If neither fits beside the other compressed, both rest compressed and a tap opens one for a moment. Side bar columns report their full height (0 when the screen puts nothing there) so the decision follows each screen's toolkit.
82
81
  - Glass header: on Duo with a side bar, Default/Extended headers without search and with a `ScrollState` let content scroll under the bar (`usesDuoGlassHeader`); the bar fades in a translucent surface + hairline over 16pt (Compose has no backdrop blur — RN's fallback look), the gradient leaves with the content.
83
82
  - Quick return header: glass headers and Animated headers (with a `ScrollState`) on the Duo side bar layout slide out with the content and back in on a reverse scroll; a half-shown header settles in or out once the scroll stops. The side bar is drawn apart from the header, so it stays put.
@@ -252,9 +252,7 @@ public struct Input: View {
252
252
  }
253
253
  .padding(.horizontal, Spacing.S)
254
254
  .background(theme.colors.background.surface)
255
- // A zero-height frame on the top edge centers the label on the border, re-laid out with font scale.
256
- .fixedSize(horizontal: false, vertical: true)
257
- .frame(height: 0)
255
+ .alignmentGuide(.top) { $0[VerticalAlignment.center] }
258
256
  .offset(x: Spacing.S)
259
257
  }
260
258
  }
@@ -279,9 +279,7 @@ public struct InputTextArea: View {
279
279
  }
280
280
  .padding(.horizontal, Spacing.S)
281
281
  .background(theme.colors.background.surface)
282
- // A zero-height frame on the top edge centers the label on the border, re-laid out with font scale.
283
- .fixedSize(horizontal: false, vertical: true)
284
- .frame(height: 0)
282
+ .alignmentGuide(.top) { $0[VerticalAlignment.center] }
285
283
  .offset(x: Spacing.S)
286
284
  }
287
285
  }
@@ -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
  }