Skip to content

feat(ios): add yieldToNestedGestures to let a nested pan keep its drag - #1262

Open
andreialecu wants to merge 1 commit into
callstack:mainfrom
andreialecu:feat/ios-yield-to-nested-gestures
Open

andreialecu wants to merge 1 commit into
callstack:mainfrom
andreialecu:feat/ios-yield-to-nested-gestures

Conversation

@andreialecu

@andreialecu andreialecu commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On iOS the pager's drag is native (since v9 a SwiftUI TabView in page mode, so a UICollectionView pan). A horizontal pan inside a page, such as a swipeable row, a slider or a chat bubble's swipe to reply, races that pan for the drag, and whichever starts first takes it. The pager's pan starts after a few points, so a nested pan that needs to move further always loses, and one that needs about as far wins only some of the time. Today the only control is scrollEnabled, which stops paging everywhere on the page. react-native-gesture-handler can't fix it from JS either: on iOS it only orders its own recognizers, and the pager's pan isn't one of them. Related to #848 (nested gestures inside the pager).

This adds an opt-in iOS prop, yieldToNestedGestures. With it, as the pager's pan would start, the pager declines the drag if a pan recognizer on the view the touch landed on, or on one of that view's ancestors inside the page, is still tracking it. A drag that starts anywhere else still pages. Defaults to false, so nothing changes for existing users. Android gets a no-op setter (the view manager implements the generated interface).

How

  • It builds on the existing arbitration. v10 already overrides gestureRecognizerShouldBegin on the paging scroll view's runtime subclass to yield to the back gesture ([iOS] react-native-screens v4.19.0 breaks the global back swipe gesture on pager views #1050). PagerGestureObserver now also yields to a nested pan from the same override, so there is no new mechanism.
  • No hit-test for the touched view. It comes from the touch itself, through a gestureRecognizer:shouldReceiveTouch: override on the same runtime subclass, which defers to UIScrollView's own answer. Hit-testing re-enters _UIHostingView, as in the stack overflow of [iOS] Stack overflow in _UIHostingView._hitTest with keyboard open on a page (8.0.2 and 9.0.4, New Architecture) #1144. The selector is built with NSSelectorFromString, because #selector(gestureRecognizer(_:shouldReceive:)) is ambiguous between its UITouch, UIPress and UIEvent variants.
  • The decision holds for the whole touch sequence. On iOS 26 the private UIScrollViewPagingSwipeGestureRecognizer asks gestureRecognizerShouldBegin again as the finger lifts on a flick. By then the nested pan may already have ended, and without this the flick would still page. The e2e engine's synthesized flicks never start that recognizer, so this path isn't covered by the new test.
  • Only UIPanGestureRecognizers that aren't a scroll view's own pan count. gesture-handler's pans qualify. A vertical list's pan doesn't, so a list in a page doesn't stop paging. React Native's JS responder system (PanResponder) isn't a recognizer and isn't seen. The docs say so.
  • Prop plumbing follows overdrag/scrollEnabled: codegen prop → RNCPagerViewComponentView → PagerViewProvider → PagerViewProps → PagerView → PagerGestureObserver.

Example and tests

  • Example screen: "Yield to Nested Gestures Example". Each page holds a vertical list of rows, each with a gesture-handler pan (usePanGesture), and a gutter beside the list. A switch toggles the prop.
  • Dependency: the example app now depends on react-native-gesture-handler 3.5.0. The library doesn't.
  • e2e: e2e/tests/yield-to-nested-gestures.e2e.ts, iOS only, covers five cases. With the prop on: a drag and a fast drag on a row move the row and keep the page, and a drag beside the list or on the list below the rows pages. With the prop off: a drag on a row pages, run after the others to show that a fresh pager starts with it off. A busy simulator occasionally drops a synthesized drag before it reaches the app, so a drag that changed nothing is sent once more; a wrong outcome fails both times.
  • Row threshold: the rows start after 24pt, further than the pager's pan needs, so without the prop the pager always wins. With 10pt, gesture-handler's Swipeable default, which one won varied from run to run.

Test Plan

On the iOS 26.5 simulator (iPhone 17 Pro), Debug build. Not tried in a Release build, on iOS 15–25 or on a device:

Prop off: dragging a row pages Prop on: dragging a row moves it Prop on: dragging the gutter pages
screenshot 1 screenshot 2 screenshot 3
  • bun run e2e:test:ios -- --tag yield-to-nested-gestures: 5 tests, passing on 9 consecutive runs of the final build, 6 of them while a Gradle build loaded the machine. Earlier runs with temporary logging in the native code confirmed the decision for each drag that reached the app.
  • bun typecheck, bun lint (no new warnings), bun format:check, bun test (27 passing), and the example's and e2e's tsc.
  • example/android: ./gradlew assembleDebug builds.
  • The docs site builds (docs: bun run build).

What's required for testing (prerequisites)?

bun install, then bun bootstrap (the example now includes RNGestureHandler in its pods). Build the example for iOS.

What are the steps to reproduce (after prerequisites)?

Open "Yield to Nested Gestures Example".

  1. With the switch off, drag a row towards the next page. The pager pages, and the row doesn't move.
  2. Turn the switch on and drag a row. The row moves, and the pager stays.
  3. With the switch on, drag the dashed gutter beside the rows. The pager pages.

Screenshots

1-off-row-drag-pages 2-on-row-drag-moves-row 3-on-gutter-drag-pages

Compatibility

OS Implemented
iOS ✅
Android ❌ (no-op)

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I updated the typed files (TS and Flow)

On iOS the pager's drag is a native UIScrollView pan, so a horizontal pan
inside a page (a swipeable row, a slider, a swipe to reply) races it for the
drag, and the pager's pan, which starts after a few points, usually wins.
scrollEnabled is the only control today and turns paging off everywhere.

With yieldToNestedGestures, the pager declines a drag while a pan recognizer
on the view the touch landed on, or one of its ancestors inside the page, is
still tracking it. A drag that starts anywhere else still pages, and scroll
views' own pans don't count. It extends the gestureRecognizerShouldBegin
arbitration added for the back gesture (callstack#1050). The touched view is recorded
in gestureRecognizer:shouldReceiveTouch: instead of hit-testing, and the
decision holds for the rest of the touch, since iOS 26's paging swipe
recognizer asks again as the finger lifts. Opt-in; a no-op on Android.

Adds an example screen, an iOS e2e test and docs.
Copilot AI balanced review requested due to automatic review settings November 20, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The change alters UIScrollView gesture handling via runtime subclassing and iOS-version-specific (including private paging recognizer) delegate overrides, but has only been exercised on an iOS 26 simulator and needs on-device validation across iOS 15–26 to rule out gesture regressions.

No open issues 🎉

What changed in this PR

Adds an opt-in iOS-only yieldToNestedGestures prop so nested pan gestures inside a page (e.g., swipeable rows/sliders) can keep the drag instead of the pager’s native pan winning, while preserving existing behavior by default.

Changes:

  • Introduces and plumbs the new iOS prop through codegen → Fabric component view → provider/props → SwiftUI view → gesture observer.
  • Extends iOS gesture arbitration by recording the touched view and yielding paging when an eligible nested UIPanGestureRecognizer is still tracking.
  • Adds documentation, an example screen, and iOS-only e2e coverage; Android includes a no-op setter for interface completeness.
File Description
src/​PagerViewNativeComponent.ts Adds the yieldToNestedGestures codegen prop with iOS-only documentation for the native component interface.
README.md Documents the new prop and adds guidance around nested gestures within the pager.
ios/​RNCPagerViewProviding.h Extends the native provider protocol to include the yieldToNestedGestures property.
ios/​RNCPagerViewComponentView.mm Wires the Fabric prop update path to forward yieldToNestedGestures into the native provider.
ios/​PagerViewProvider.swift Stores and forwards yieldToNestedGestures from the provider into the SwiftUI props model.
ios/​PagerViewProps.swift Adds yieldToNestedGestures to the SwiftUI props (published) so updates propagate reactively.
ios/​PagerView.swift Propagates yieldToNestedGestures into the gesture observer and updates it on change.
ios/​PagerGestureObserver.swift Implements the iOS arbitration logic to yield paging when a qualifying nested pan recognizer is still tracking the touch.
example/​src/​YieldToNestedGesturesExample.tsx Adds a new example screen demonstrating nested pan vs pager drag behavior with a toggle for the prop.
example/​src/​App.tsx Registers the new example screen in the example app’s navigation/menu.
example/​package.json Adds react-native-gesture-handler as a dependency for the example app used by the new demo screen.
example/​ios/​Podfile.lock Updates the example iOS pods lockfile to include RNGestureHandler-related pod changes.
e2e/​tests/​yield-to-nested-gestures.e2e.ts Adds iOS-only e2e tests covering expected paging vs nested-pan outcomes with the prop enabled/disabled.
docs/​docs/​docs/​api/​pager-view.md Adds API documentation for yieldToNestedGestures in the pager view docs.
bun.lock Updates the Bun lockfile to reflect new/updated dependencies introduced by the example changes.
android/​src/​main/​java/​com/​reactnativepagerview/​PagerViewViewManager.kt Adds an Android no-op setter for yieldToNestedGestures to satisfy the generated view manager interface.

Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

@andreialecu
andreialecu marked this pull request as ready for review November 20, 2026 13:16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants