@onekeyfe/react-native-bottom-tabs 6.8.0-3 → 6.8.0-31

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.
@@ -150,10 +150,19 @@ class BottomTabsDrawerView(context: Context) : FrameLayout(context) {
150
150
  private var downProgress = 0f
151
151
  private var gestureReturnOpen = false
152
152
  private var eligible = false
153
+ // The touch started inside the open menu, where only a leftward drag moves it.
154
+ private var downInMenu = false
155
+ // The state a user's release or tap has already confirmed with a haptic,
156
+ // so the transition plays it once, when it is decided rather than landed.
157
+ private var hapticTarget: Boolean? = null
153
158
  private var touchedView: WeakReference<View>? = null
154
159
  private val touchMatrix = Matrix()
155
160
  private val touchPoint = FloatArray(2)
156
161
  private var dragging = false
162
+ // A native gesture start sent to React (by a drag, or by a rightward swipe
163
+ // in the menu that only cancels the row's touch), owed its end however the
164
+ // touch stops. React's pointer dispatcher drops input until it gets one.
165
+ private var nativeGestureStarted = false
157
166
  private var tracker: VelocityTracker? = null
158
167
  private var lastNativeEvent: MotionEvent? = null
159
168
  private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop
@@ -205,6 +214,7 @@ class BottomTabsDrawerView(context: Context) : FrameLayout(context) {
205
214
  stopAnimation()
206
215
  drawerEnabled = value
207
216
  stableOpen = false
217
+ hapticTarget = null
208
218
  setProgress(0f)
209
219
  if (value && requestedOpen) settle(true, 0f, false)
210
220
  }
@@ -287,8 +297,11 @@ class BottomTabsDrawerView(context: Context) : FrameLayout(context) {
287
297
  touchedView = touchedViewAt(this, event.x, event.y)?.let(::WeakReference)
288
298
  val systemLeft = ViewCompat.getRootWindowInsets(this)
289
299
  ?.getInsets(WindowInsetsCompat.Type.systemGestures())?.left ?: 0
300
+ downInMenu = progress > 0f && event.x < menuWidth * progress
301
+ // While open, the page beside the menu and the menu itself both take
302
+ // the drag; controls inside the menu keep theirs.
290
303
  eligible = drawerEnabled && event.y < height - bottomBarHeight * density &&
291
- (if (progress > 0f) event.x >= menuWidth * progress
304
+ (if (progress > 0f) !downInMenu || !touchPathHasExclusiveControl()
292
305
  else swipeEnabled && event.x >= systemLeft && !touchPathHasExclusiveControl())
293
306
  if (eligible) tracker = VelocityTracker.obtain().also { it.addMovement(event) }
294
307
  }
@@ -313,14 +326,20 @@ class BottomTabsDrawerView(context: Context) : FrameLayout(context) {
313
326
  eligible = false
314
327
  return false
315
328
  }
329
+ // Inside the open menu only a leftward drag moves it, which closes it.
330
+ // A rightward one is still a swipe, not a tap on the row under it.
331
+ if (abs(dx) > touchSlop && abs(dx) > abs(dy) && downInMenu && dx > 0f) {
332
+ eligible = false
333
+ startNativeGesture(event)
334
+ return false
335
+ }
316
336
  if (abs(dx) > touchSlop && abs(dx) > abs(dy) && (progress > 0f || dx > 0f)) {
317
337
  gestureReturnOpen = if (animator != null && !animationUser) animationTarget else stableOpen
318
338
  stopAnimation()
319
339
  downProgress = progress
320
340
  dragging = true
321
341
  parent?.requestDisallowInterceptTouchEvent(true)
322
- NativeGestureUtil.notifyNativeGestureStarted(this, event)
323
- rememberNativeEvent(event)
342
+ startNativeGesture(event)
324
343
  return true
325
344
  }
326
345
  }
@@ -433,11 +452,18 @@ class BottomTabsDrawerView(context: Context) : FrameLayout(context) {
433
452
  lastNativeEvent = MotionEvent.obtain(event)
434
453
  }
435
454
 
455
+ private fun startNativeGesture(event: MotionEvent) {
456
+ NativeGestureUtil.notifyNativeGestureStarted(this, event)
457
+ nativeGestureStarted = true
458
+ rememberNativeEvent(event)
459
+ }
460
+
436
461
  private fun cancelTouch() {
437
- if (dragging) {
462
+ if (nativeGestureStarted) {
438
463
  lastNativeEvent?.let { NativeGestureUtil.notifyNativeGestureEnded(this, it) }
439
- parent?.requestDisallowInterceptTouchEvent(false)
440
464
  }
465
+ if (dragging) parent?.requestDisallowInterceptTouchEvent(false)
466
+ nativeGestureStarted = false
441
467
  dragging = false
442
468
  eligible = false
443
469
  touchedView = null
@@ -572,6 +598,12 @@ class BottomTabsDrawerView(context: Context) : FrameLayout(context) {
572
598
  // keeps its finger velocity through a slightly underdamped spring.
573
599
  private fun settle(open: Boolean, velocity: Float, user: Boolean, tween: Boolean = true) {
574
600
  val target = drawerEnabled && open
601
+ // The haptic marks the decision: it plays as a user's release or tap
602
+ // commits to the other state, not when the drawer lands there.
603
+ if (user && target != stableOpen && hapticTarget != target) {
604
+ hapticTarget = target
605
+ if (drawerHapticFeedbackEnabled) performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
606
+ }
575
607
  // An animation already heading there keeps running; the newer request
576
608
  // still decides whether its completion is a user event.
577
609
  if (animator != null && animationTarget == target) {
@@ -586,6 +618,7 @@ class BottomTabsDrawerView(context: Context) : FrameLayout(context) {
586
618
  stopAnimation()
587
619
  if (width == 0 || !isAttachedToWindow) {
588
620
  stableOpen = target
621
+ hapticTarget = null
589
622
  setProgress(if (target) 1f else 0f)
590
623
  return
591
624
  }
@@ -650,9 +683,9 @@ class BottomTabsDrawerView(context: Context) : FrameLayout(context) {
650
683
  private fun finish(target: Boolean, user: Boolean) {
651
684
  val changed = stableOpen != target
652
685
  stableOpen = target
686
+ hapticTarget = null
653
687
  setProgress(if (target) 1f else 0f)
654
688
  if (user && (changed || target != requestedOpen)) {
655
- if (drawerHapticFeedbackEnabled && changed) performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
656
689
  onDrawerOpenChange?.invoke(target)
657
690
  }
658
691
  }
@@ -711,6 +744,7 @@ class BottomTabsDrawerView(context: Context) : FrameLayout(context) {
711
744
  detached = true
712
745
  cancelTouch()
713
746
  stopAnimation()
747
+ hapticTarget = null
714
748
  backCallback.remove()
715
749
  backRegistered = false
716
750
  setProgress(if (stableOpen && drawerEnabled) 1f else 0f)
package/docs/SPEC.md CHANGED
@@ -87,8 +87,11 @@ initial layout and cancellation emit no event. A user transition returning to
87
87
  the previous stable state emits only when it overrides an in-flight external
88
88
  target, so the consumer can reconcile that target. `drawerSwipeEnabled?: boolean`
89
89
  defaults to false; callers MUST enable it only where drawer navigation is appropriate (normally a root
90
- screen). Existing `hapticFeedbackEnabled` enables one light native haptic after
91
- a completed user transition changes the stable state. Programmatic updates and
90
+ screen). Existing `hapticFeedbackEnabled` enables one light native haptic when a
91
+ user's release, dim tap or Back/escape commits to the other stable state: it
92
+ plays at that decision, not when the drawer lands, and once per transition, so
93
+ a drag that takes over and releases toward the same target does not repeat it.
94
+ Releases that return to the current stable state, programmatic updates and
92
95
  cancelled gestures do not vibrate.
93
96
 
94
97
  `onDrawerProgress?: (event) => void` receives `{ progress }`, the displayed
@@ -179,9 +182,17 @@ pending direction even when a nested pager initially disallows interception,
179
182
  but stops overriding that request after the child wins. Sliders and editing controls,
180
183
  web/graphics surfaces, system back gestures and starts in the bottom tab-bar
181
184
  footprint take priority. When open, closing gestures
182
- remain enabled even if opening swipes are disabled. Only the exposed
183
- foreground accepts a closing pan; menu scrolling remains the consumer's own.
184
- Vertical gestures fail before taking ownership. Active touches interrupted by
185
+ remain enabled even if opening swipes are disabled. The exposed foreground
186
+ accepts a closing pan in either direction; inside the menu a leftward
187
+ horizontal pan closes it too, while sliders and editing controls keep their
188
+ touches and vertical menu scrolling remains the consumer's own. Inside the
189
+ menu the direction is read from the distance moved as well as the current
190
+ speed, and a horizontal swipe in either direction cancels React touches under
191
+ it, so the row under the finger never fires its press. Whenever a drawer pan
192
+ takes ownership it cancels React touches the same way (iOS cycles the surface
193
+ touch handler, which a descendant recognizer cannot prevent; Android notifies
194
+ the native gesture start, and its end once the touch stops however it stops,
195
+ since React's pointer dispatcher drops input until it does). Vertical gestures fail before taking ownership. Active touches interrupted by
185
196
  a second finger, system cancellation, disabling, detach or a newer prop update
186
197
  cannot later emit an event. Cancellation returns to the previous stable state,
187
198
  or resumes an external target whose programmatic animation the gesture interrupted.
@@ -207,8 +218,8 @@ close or prop change from rest then cross-fades from a snapshot to the final
207
218
  state over 200 ms instead of moving, and a released drag settles critically
208
219
  damped (damping ratio 1) without travelling past its target. A cross-fade is
209
220
  an in-flight transition like an animation: its final state shows at once under
210
- the snapshot, but the stable state, `onDrawerOpenChange` and the haptic follow
211
- only when the fade ends. A newer cross-fade replaces the previous snapshot
221
+ the snapshot, but the stable state and `onDrawerOpenChange` follow only when
222
+ the fade ends. A newer cross-fade replaces the previous snapshot
212
223
  (capturing it as currently shown). A request for the target already being
213
224
  faded to leaves the fade running and only replaces whether its completion is a
214
225
  user transition. A touch, an animated settle, a newer cross-fade, disabling or
@@ -537,6 +548,45 @@ placement and can draw one round accessory button above the vertical bar.
537
548
  layout, tab rebuilds, tab bar hiding, icon loads, and changes to the traits
538
549
  affecting `verticalBarEdge`.
539
550
 
551
+ ## iOS tab scene sizing
552
+
553
+ Each tab's React scene is hosted in the root view of that tab's
554
+ `UIViewController`. Fabric owns the scene's frame, including any offset or size
555
+ from `getSceneStyle`. Native code never writes it. The scene has no
556
+ autoresizing mask and no Auto Layout constraints.
557
+
558
+ - `onNativeLayout` reports the size of the selected tab's page view once it is
559
+ in the window, and the container's size before that. It fires on container
560
+ layout, when the selected page changes size, and when the selected page
561
+ appears or reattaches to a window even if its bounds are unchanged.
562
+ - Loaded scenes and lazy placeholders use the reported page size with either
563
+ a native or custom tab bar. They fill the container until a measurement
564
+ arrives. For loaded scenes, `getSceneStyle` can override the size and position.
565
+ The default frame matches the visible page when the iPad sidebar
566
+ (`sidebarAdaptable`) takes part of the width.
567
+ - Autoresizing is not used because it applies the change in host bounds to the
568
+ frame Fabric already set. A tab view controller's view starts at screen size
569
+ and Fabric sizes the scene to the container. When the container is narrower
570
+ than the screen (an iPad split pane), the first resize to the container width
571
+ subtracted that difference again. The scene became 0 points wide: its content
572
+ still drew outside the scene's bounds, but UIKit hit-testing skipped it, so
573
+ the tab ignored every touch and scroll.
574
+ - A scene that is unmounted and reused by Fabric elsewhere keeps no mask, so it
575
+ is never resized by its next superview.
576
+
577
+ Acceptance:
578
+
579
+ - On an iPad in landscape split view, first-open every tab in each pane after
580
+ another tab, and after rotating. Each tab scene's frame equals its view
581
+ controller's view bounds, and the tab responds to taps and scrolls.
582
+ - With `sidebarAdaptable` and the sidebar shown, the `onNativeLayout` width
583
+ equals the selected page's width. The default scene and placeholder sizes
584
+ follow that width even with a custom tab bar and `tabBarHidden={false}`.
585
+ - Selecting a cached page or reattaching the tab container reports the visible
586
+ page's width and height even when the page and container bounds did not change.
587
+ - A route whose scene style sets its own offset or size keeps that frame after
588
+ UIKit layout passes.
589
+
540
590
  ## Threading and ownership
541
591
 
542
592
  All gesture handling, animations, and timers run on the platform UI thread in
@@ -20,6 +20,60 @@ import React
20
20
  )
21
21
  }
22
22
 
23
+ /// Root view of one tab's view controller. It hosts the React scene but never
24
+ /// writes the scene's frame: Fabric owns it, including any per-route
25
+ /// `getSceneStyle` offset or size.
26
+ ///
27
+ /// The scene used to autoresize with this view. Autoresizing applies the change
28
+ /// in bounds on top of the frame Fabric set: a tab view controller's view
29
+ /// starts at screen size, Fabric sizes the scene to the narrower container (an
30
+ /// iPad split pane), and the first resize to the pane width subtracted the
31
+ /// difference again, leaving the scene 0 points wide. Its content still drew
32
+ /// but no longer received touches. The scene now has no autoresizing mask, and
33
+ /// the container reports the selected page's size to JS so Fabric lays the
34
+ /// scene out at the page size (it differs from the container when the iPad
35
+ /// sidebar takes part of the width).
36
+ final class BottomTabsPageView: UIView {
37
+ var onLayoutChange: ((BottomTabsPageView) -> Void)?
38
+ private var lastSize: CGSize = .zero
39
+
40
+ override func layoutSubviews() {
41
+ super.layoutSubviews()
42
+ let size = bounds.size
43
+ guard size != lastSize else { return }
44
+ lastSize = size
45
+ onLayoutChange?(self)
46
+ }
47
+
48
+ override func didMoveToWindow() {
49
+ super.didMoveToWindow()
50
+ guard window != nil else { return }
51
+ // UIKit can update the page bounds after this attachment callback.
52
+ DispatchQueue.main.async { [weak self] in
53
+ guard let self, self.window != nil else { return }
54
+ self.onLayoutChange?(self)
55
+ }
56
+ }
57
+ }
58
+
59
+ final class BottomTabsPageViewController: UIViewController {
60
+ var pageView: BottomTabsPageView { view as! BottomTabsPageView }
61
+
62
+ override func loadView() {
63
+ let pageView = BottomTabsPageView()
64
+ pageView.backgroundColor = .clear
65
+ pageView.clipsToBounds = true
66
+ view = pageView
67
+ }
68
+
69
+ override func viewDidAppear(_ animated: Bool) {
70
+ super.viewDidAppear(animated)
71
+ // A cached page can become selected without changing bounds or windows.
72
+ let page = pageView
73
+ page.onLayoutChange?(page)
74
+ }
75
+ }
76
+
23
77
  /// Bridges to OneKeyNamedSVG.shared in OneKeyImage without importing the OneKeyImage
24
78
  /// Swift module (which transitively imports NitroModules C++ headers).
25
79
  private enum OneKeyNamedSVGLoader {
@@ -138,7 +192,8 @@ class RCTBottomTabsContainerView: UIView {
138
192
  private var lastPressedTabKey: String?
139
193
  private var lastPressedTabTime: CFTimeInterval = 0
140
194
  /// Cached view controllers keyed by tab key to avoid unnecessary reparenting
141
- private var cachedViewControllers: [String: UIViewController] = [:]
195
+ private var cachedViewControllers: [String: BottomTabsPageViewController] = [:]
196
+ private var isHandlingLayout = false
142
197
  private var pendingIconUpdates = Set<Int>()
143
198
  private var isIconUpdateScheduled = false
144
199
  // Vertical tab bar (iPhone Duo side strip): last reported placement and the
@@ -520,10 +575,36 @@ class RCTBottomTabsContainerView: UIView {
520
575
 
521
576
  setupTabBarControllerIfNeeded()
522
577
  tabBarController?.view.frame = bounds
523
- onNativeLayout?(["width": Double(bounds.width), "height": Double(bounds.height)])
578
+ // Settle the selected page's frame first so the size reported below is
579
+ // the current one, not the page's size before this pass.
580
+ isHandlingLayout = true
581
+ tabBarController?.view.layoutIfNeeded()
582
+ isHandlingLayout = false
583
+ emitSceneLayout()
524
584
  scheduleSideAccessoryLayout()
525
585
  }
526
586
 
587
+ /// Reports the size React lays every tab scene out at: the selected page's
588
+ /// bounds (narrower than the container when the iPad sidebar is shown), or
589
+ /// the container's bounds until that page is in the window.
590
+ private func emitSceneLayout() {
591
+ var size = bounds.size
592
+ if let page = tabBarController?.selectedViewController?.viewIfLoaded,
593
+ page.window != nil,
594
+ page.bounds.width > 0, page.bounds.height > 0 {
595
+ size = page.bounds.size
596
+ }
597
+ guard size.width > 0 && size.height > 0 else { return }
598
+ onNativeLayout?(["width": Double(size.width), "height": Double(size.height)])
599
+ }
600
+
601
+ private func pageDidChangeLayout(_ page: BottomTabsPageView) {
602
+ // handleLayout emits once after its own layout pass.
603
+ guard !isHandlingLayout,
604
+ page === tabBarController?.selectedViewController?.viewIfLoaded else { return }
605
+ emitSceneLayout()
606
+ }
607
+
527
608
  private func setupTabBarControllerIfNeeded() {
528
609
  guard tabBarController == nil else { return }
529
610
  guard let parentVC = self.reactViewController() else { return }
@@ -578,13 +659,11 @@ class RCTBottomTabsContainerView: UIView {
578
659
  usedKeys.insert(tabData.key)
579
660
 
580
661
  // Reuse cached VC or create a new one
581
- let vc: UIViewController
662
+ let vc: BottomTabsPageViewController
582
663
  if let cached = cachedViewControllers[tabData.key] {
583
664
  vc = cached
584
665
  } else {
585
- vc = UIViewController()
586
- vc.view.backgroundColor = .clear
587
- vc.view.clipsToBounds = true
666
+ vc = BottomTabsPageViewController()
588
667
  cachedViewControllers[tabData.key] = vc
589
668
  }
590
669
 
@@ -594,13 +673,16 @@ class RCTBottomTabsContainerView: UIView {
594
673
  if childView.superview !== vc.view {
595
674
  childView.removeFromSuperview()
596
675
  vc.view.addSubview(childView)
597
- // Use autoresizingMask instead of Auto Layout constraints — Fabric sets
598
- // frames directly and constraints conflict with that on subsequent mounts.
676
+ // Neither Auto Layout constraints (they conflict with the frames
677
+ // Fabric sets on later mounts) nor autoresizing (it applies bounds
678
+ // deltas to a frame Fabric already set): the frame stays Fabric's.
599
679
  childView.translatesAutoresizingMaskIntoConstraints = true
600
- childView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
601
- childView.frame = vc.view.bounds
680
+ childView.autoresizingMask = []
602
681
  }
603
682
  }
683
+ vc.pageView.onLayoutChange = { [weak self] page in
684
+ self?.pageDidChangeLayout(page)
685
+ }
604
686
 
605
687
  // Configure tab bar item
606
688
  let icon = loadedIcons[originalIndex]
@@ -10,6 +10,7 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
10
10
  stopAnimation()
11
11
  removeFadeSnapshot()
12
12
  stableOpen = false
13
+ hapticTarget = nil
13
14
  setProgress(0)
14
15
  if enabled && open { settle(to: true, velocity: 0, user: false) }
15
16
  }
@@ -84,10 +85,14 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
84
85
  private var fadeSnapshot: UIView?
85
86
  private var fadeTarget = false
86
87
  private var fadeUser = false
87
- // Hooks for native tests: they set Reduce Motion, and run without an app
88
- // host, where UIKit cannot snapshot a view.
88
+ // The state a user's release or tap has already confirmed with a haptic,
89
+ // so the transition plays it once, when it is decided rather than landed.
90
+ private var hapticTarget: Bool?
91
+ // Hooks for native tests: they set Reduce Motion, run without an app host,
92
+ // where UIKit cannot snapshot a view, and count haptics.
89
93
  var isReduceMotionEnabled: () -> Bool = { UIAccessibility.isReduceMotionEnabled }
90
94
  var makeFadeSnapshot: (UIView) -> UIView? = { $0.snapshotView(afterScreenUpdates: false) }
95
+ var playHaptic: () -> Void = { UIImpactFeedbackGenerator(style: .light).impactOccurred() }
91
96
 
92
97
  // Measured frame by frame from the reference recording: the page travels
93
98
  // 80% of the width, keeps a fixed display-like corner, washes toward the
@@ -203,6 +208,7 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
203
208
  interruptGesture()
204
209
  stopAnimation()
205
210
  removeFadeSnapshot()
211
+ hapticTarget = nil
206
212
  setProgress(stableOpen && enabled ? 1 : 0)
207
213
  } else if enabled && stableOpen != open {
208
214
  settle(to: open, velocity: 0, user: false)
@@ -231,21 +237,30 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
231
237
  guard start.y < bounds.height - CGFloat(max(0, bottomBarHeight)) else { return false }
232
238
  guard !isInsideNativeTabBar(touch.view) else { return false }
233
239
  touchTarget = touch.view
234
- if progress > 0 { return start.x >= menuWidth * progress }
240
+ // While open, the page beside the menu and the menu itself both take the
241
+ // drag; controls inside the menu keep theirs.
242
+ if progress > 0 { return start.x >= menuWidth * progress || !touchPathContainsExclusiveControl() }
235
243
  return swipeEnabled && !touchPathContainsExclusiveControl()
236
244
  }
237
245
 
238
246
  override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
239
247
  guard enabled, bounds.width > 0 else { return false }
240
248
  let velocity = pan.velocity(in: self)
241
- guard abs(velocity.x) > abs(velocity.y) else { return false }
242
249
  let location = pan.location(in: self)
243
250
  let translation = pan.translation(in: self)
244
251
  let start = CGPoint(x: location.x - translation.x, y: location.y - translation.y)
245
252
  guard start.y < bounds.height - CGFloat(max(0, bottomBarHeight)) else { return false }
246
- if progress > 0 {
247
- return start.x >= menuWidth * progress
253
+ if progress > 0 && start.x < menuWidth * progress {
254
+ // Inside the menu a sideways swipe is never a tap on the row under it,
255
+ // so its press is cancelled either way; only a leftward one closes.
256
+ // The distance so far reads the direction more steadily than the speed
257
+ // at this instant.
258
+ guard abs(translation.x) > abs(translation.y) || abs(velocity.x) > abs(velocity.y) else { return false }
259
+ cancelReactTouches()
260
+ return translation.x < 0 || velocity.x < 0
248
261
  }
262
+ guard abs(velocity.x) > abs(velocity.y) else { return false }
263
+ if progress > 0 { return true }
249
264
  return swipeEnabled && velocity.x > 0 && !touchPathCanScrollRight()
250
265
  }
251
266
 
@@ -256,7 +271,7 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
256
271
  guard gestureRecognizer === pan,
257
272
  let scroll = other.view as? UIScrollView,
258
273
  other === scroll.panGestureRecognizer else { return false }
259
- return scroll.isDescendant(of: foregroundContent)
274
+ return scroll.isDescendant(of: foregroundContent) || scroll.isDescendant(of: menu)
260
275
  }
261
276
 
262
277
  func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
@@ -338,6 +353,7 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
338
353
  @objc private func handlePan(_ recognizer: UIPanGestureRecognizer) {
339
354
  switch recognizer.state {
340
355
  case .began:
356
+ cancelReactTouches()
341
357
  // The drag takes over a settle or cross-fade in flight and drops its
342
358
  // completion. Cancelling returns to a programmatic target, else to the
343
359
  // stable state.
@@ -367,6 +383,24 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
367
383
  }
368
384
  }
369
385
 
386
+ // React Native's touch handler sits on the surface above this view, so the
387
+ // drag cannot prevent it, and a row the drag started on would still fire
388
+ // its press on release. Toggling the handler cancels its touches, as a
389
+ // native scroll taking over does.
390
+ private func cancelReactTouches() {
391
+ let handlerClasses = ["RCTSurfaceTouchHandler", "RCTTouchHandler"].compactMap(NSClassFromString)
392
+ guard !handlerClasses.isEmpty else { return }
393
+ var view = superview
394
+ while let current = view {
395
+ for recognizer in current.gestureRecognizers ?? []
396
+ where handlerClasses.contains(where: { recognizer.isKind(of: $0) }) {
397
+ recognizer.isEnabled = false
398
+ recognizer.isEnabled = true
399
+ }
400
+ view = current.superview
401
+ }
402
+ }
403
+
370
404
  private func interruptGesture() {
371
405
  guard pan != nil else { return }
372
406
  suppressCancellation = true
@@ -453,6 +487,12 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
453
487
  // keeps its finger velocity through a slightly underdamped spring.
454
488
  private func settle(to requested: Bool, velocity: CGFloat, user: Bool, tween: Bool = true) {
455
489
  let target = enabled && requested
490
+ // The haptic marks the decision: it plays as a user's release or tap
491
+ // commits to the other state, not when the drawer lands there.
492
+ if user && target != stableOpen && hapticTarget != target {
493
+ hapticTarget = target
494
+ if hapticFeedbackEnabled { playHaptic() }
495
+ }
456
496
  // An animation already heading there keeps running; the newer request
457
497
  // still decides whether its completion is a user event.
458
498
  if displayLink != nil && animationTarget == target {
@@ -468,6 +508,7 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
468
508
  guard bounds.width > 0, window != nil else {
469
509
  removeFadeSnapshot()
470
510
  stableOpen = target
511
+ hapticTarget = nil
471
512
  setProgress(target ? 1 : 0)
472
513
  return
473
514
  }
@@ -515,7 +556,7 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
515
556
  fadeTarget = target
516
557
  fadeUser = user
517
558
  // The final state shows now, under the snapshot. The transition completes
518
- // (stable state, callback and haptic) only when the fade does.
559
+ // (stable state and callback) only when the fade does.
519
560
  setProgress(target ? 1 : 0)
520
561
  UIView.animate(withDuration: 0.2, delay: 0, options: [.curveEaseOut], animations: {
521
562
  snapshot.alpha = 0
@@ -593,13 +634,13 @@ final class RCTBottomTabsDrawerContainerView: UIView, UIGestureRecognizerDelegat
593
634
  private func finish(target: Bool, user: Bool) {
594
635
  let changed = stableOpen != target
595
636
  stableOpen = target
637
+ hapticTarget = nil
596
638
  setProgress(target ? 1 : 0)
597
639
  if user { reportCompletion(target: target, changed: changed) }
598
640
  }
599
641
 
600
642
  private func reportCompletion(target: Bool, changed: Bool) {
601
643
  guard changed || target != open else { return }
602
- if hapticFeedbackEnabled && changed { UIImpactFeedbackGenerator(style: .light).impactOccurred() }
603
644
  onDrawerOpenChange?(target)
604
645
  }
605
646
 
@@ -145,6 +145,63 @@ final class BottomTabsDrawerReduceMotionTests: XCTestCase {
145
145
  XCTAssertEqual(detached.progress, 1)
146
146
  XCTAssertEqual(detached.events, [])
147
147
  }
148
+
149
+ // The haptic marks a user's decision; the faded close reports only later.
150
+ func testHapticPlaysWhenAUserCloseIsDecidedNotWhenItLands() throws {
151
+ let fixture = Fixture(open: true, haptics: true)
152
+ defer { fixture.close() }
153
+
154
+ XCTAssertTrue(fixture.drawer.accessibilityPerformEscape())
155
+ try fixture.requireFade()
156
+ XCTAssertEqual(fixture.hapticCount, 1, "the close is decided, so it plays now")
157
+ XCTAssertEqual(fixture.events, [])
158
+
159
+ XCTAssertTrue(fixture.waitUntil { !fixture.isFading })
160
+ XCTAssertEqual(fixture.events, [false])
161
+ XCTAssertEqual(fixture.hapticCount, 1, "landing does not play it again")
162
+ }
163
+
164
+ func testDragReleasedTowardTheSameTargetDoesNotRepeatTheHaptic() throws {
165
+ let fixture = Fixture(open: true, haptics: true)
166
+ defer { fixture.close() }
167
+ XCTAssertTrue(fixture.drawer.accessibilityPerformEscape())
168
+ try fixture.requireFade()
169
+
170
+ fixture.pan(.began)
171
+ fixture.pan(.changed, dx: fixture.menuWidth * 0.2)
172
+ fixture.pan(.ended)
173
+ XCTAssertTrue(fixture.waitUntil { !fixture.isAnimating })
174
+
175
+ XCTAssertEqual(fixture.events, [false])
176
+ XCTAssertEqual(fixture.hapticCount, 1)
177
+ }
178
+
179
+ func testReleaseBackToTheStableStateDoesNotVibrate() throws {
180
+ let fixture = Fixture(open: true, haptics: true)
181
+ defer { fixture.close() }
182
+
183
+ fixture.pan(.began)
184
+ fixture.pan(.changed, dx: -fixture.menuWidth * 0.1)
185
+ fixture.pan(.ended)
186
+ XCTAssertTrue(fixture.waitUntil { !fixture.isAnimating })
187
+
188
+ XCTAssertEqual(fixture.progress, 1)
189
+ XCTAssertEqual(fixture.events, [])
190
+ XCTAssertEqual(fixture.hapticCount, 0)
191
+ }
192
+
193
+ func testDetachingAfterADecidedCloseLetsTheNextCloseVibrate() throws {
194
+ let fixture = Fixture(open: true, haptics: true)
195
+ defer { fixture.close() }
196
+ XCTAssertTrue(fixture.drawer.accessibilityPerformEscape())
197
+ try fixture.requireFade()
198
+ fixture.drawer.removeFromSuperview()
199
+ fixture.window.addSubview(fixture.drawer)
200
+ XCTAssertEqual(fixture.progress, 1)
201
+
202
+ XCTAssertTrue(fixture.drawer.accessibilityPerformEscape())
203
+ XCTAssertEqual(fixture.hapticCount, 2, "the dropped close does not mute the next one")
204
+ }
148
205
  }
149
206
 
150
207
  @MainActor
@@ -155,12 +212,15 @@ private final class Fixture {
155
212
  let page = UIView()
156
213
  private(set) var events: [Bool] = []
157
214
  private(set) var fadingAtEvent: [Bool] = []
215
+ private(set) var hapticCount = 0
158
216
  private let recognizer = FakePan(target: nil, action: nil)
159
217
 
160
218
  /// An enabled drawer that already rests at `open`, as the prop echo leaves it.
161
- init(open: Bool) {
219
+ init(open: Bool, haptics: Bool = false) {
162
220
  drawer.isReduceMotionEnabled = { true }
163
221
  drawer.makeFadeSnapshot = { _ in UIView() }
222
+ drawer.hapticFeedbackEnabled = haptics
223
+ drawer.playHaptic = { [unowned self] in self.hapticCount += 1 }
164
224
  drawer.insertChild(menu, atIndex: 0)
165
225
  drawer.insertChild(page, atIndex: 1)
166
226
  drawer.swipeEnabled = true
@@ -298,7 +298,7 @@ const BottomTabs = ({
298
298
  width,
299
299
  height
300
300
  } = event.nativeEvent;
301
- setMeasuredDimensions({
301
+ setMeasuredDimensions(previous => previous?.width === width && previous.height === height ? previous : {
302
302
  width,
303
303
  height
304
304
  });
@@ -325,6 +325,7 @@ const BottomTabs = ({
325
325
  });
326
326
  }
327
327
  }, [renderCustomTabBar]);
328
+ const sceneSize = isIOS || !renderCustomTabBar ? measuredDimensions : styles.fullWidth;
328
329
  return /*#__PURE__*/_jsx(BottomTabBarHeightContext.Provider, {
329
330
  value: tabBarHeight,
330
331
  children: /*#__PURE__*/_jsxs(DrawerHostWithProgress, {
@@ -377,7 +378,7 @@ const BottomTabs = ({
377
378
  }) !== false && !loaded.includes(route.key)) {
378
379
  return /*#__PURE__*/_jsx(View, {
379
380
  collapsable: false,
380
- style: styles.fullWidth,
381
+ style: isIOS ? [styles.screen, sceneSize] : styles.fullWidth,
381
382
  children: renderLazyPlaceholder?.({
382
383
  route
383
384
  })
@@ -391,7 +392,7 @@ const BottomTabs = ({
391
392
  route
392
393
  });
393
394
  return /*#__PURE__*/_jsx(View, {
394
- style: [styles.screen, renderCustomTabBar ? styles.fullWidth : measuredDimensions, customStyle],
395
+ style: [styles.screen, sceneSize, customStyle],
395
396
  collapsable: false,
396
397
  pointerEvents: focused ? "auto" : "none",
397
398
  accessibilityElementsHidden: !focused,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-bottom-tabs",
3
- "version": "6.8.0-3",
3
+ "version": "6.8.0-31",
4
4
  "description": "Native bottom tabs (tab bar + scene container) for React Native on iOS and Android",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
@@ -610,7 +610,11 @@ const BottomTabs = <Route extends BaseRoute>({
610
610
  const handleNativeLayout = React.useCallback(
611
611
  (event: NativeSyntheticEvent<{ width: number; height: number }>) => {
612
612
  const { width, height } = event.nativeEvent;
613
- setMeasuredDimensions({ width, height });
613
+ setMeasuredDimensions((previous) =>
614
+ previous?.width === width && previous.height === height
615
+ ? previous
616
+ : { width, height }
617
+ );
614
618
  },
615
619
  [setMeasuredDimensions]
616
620
  );
@@ -646,6 +650,9 @@ const BottomTabs = <Route extends BaseRoute>({
646
650
  }
647
651
  }, [renderCustomTabBar]);
648
652
 
653
+ const sceneSize =
654
+ isIOS || !renderCustomTabBar ? measuredDimensions : styles.fullWidth;
655
+
649
656
  return (
650
657
  <BottomTabBarHeightContext.Provider value={tabBarHeight}>
651
658
  <DrawerHostWithProgress
@@ -707,7 +714,7 @@ const BottomTabs = <Route extends BaseRoute>({
707
714
  <View
708
715
  key={route.key}
709
716
  collapsable={false}
710
- style={styles.fullWidth}
717
+ style={isIOS ? [styles.screen, sceneSize] : styles.fullWidth}
711
718
  >
712
719
  {renderLazyPlaceholder?.({ route })}
713
720
  </View>
@@ -722,11 +729,7 @@ const BottomTabs = <Route extends BaseRoute>({
722
729
  return (
723
730
  <View
724
731
  key={route.key}
725
- style={[
726
- styles.screen,
727
- renderCustomTabBar ? styles.fullWidth : measuredDimensions,
728
- customStyle,
729
- ]}
732
+ style={[styles.screen, sceneSize, customStyle]}
730
733
  collapsable={false}
731
734
  pointerEvents={focused ? "auto" : "none"}
732
735
  accessibilityElementsHidden={!focused}