Repository navigation
feat(ios): add yieldToNestedGestures to let a nested pan keep its drag - #1262
Open
andreialecu wants to merge 1 commit into
Open
andreialecu wants to merge 1 commit into
andreialecu wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
🔵 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
UIPanGestureRecognizeris 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
marked this pull request as ready for review
November 20, 2026 13:16
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On iOS the pager's drag is native (since v9 a SwiftUI
TabViewin page mode, so aUICollectionViewpan). 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 isscrollEnabled, 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 tofalse, so nothing changes for existing users. Android gets a no-op setter (the view manager implements the generated interface).How
gestureRecognizerShouldBeginon the paging scroll view's runtime subclass to yield to the back gesture ([iOS]react-native-screensv4.19.0 breaks the global back swipe gesture on pager views #1050).PagerGestureObservernow also yields to a nested pan from the same override, so there is no new mechanism.gestureRecognizer:shouldReceiveTouch:override on the same runtime subclass, which defers toUIScrollView'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 withNSSelectorFromString, because#selector(gestureRecognizer(_:shouldReceive:))is ambiguous between itsUITouch,UIPressandUIEventvariants.UIScrollViewPagingSwipeGestureRecognizerasksgestureRecognizerShouldBeginagain 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.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.overdrag/scrollEnabled: codegen prop →RNCPagerViewComponentView→PagerViewProvider→PagerViewProps→PagerView→PagerGestureObserver.Example and tests
usePanGesture), and a gutter beside the list. A switch toggles the prop.react-native-gesture-handler3.5.0. The library doesn't.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.Swipeabledefault, 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:
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'stsc.example/android:./gradlew assembleDebugbuilds.docs:bun run build).What's required for testing (prerequisites)?
bun install, thenbun bootstrap(the example now includesRNGestureHandlerin its pods). Build the example for iOS.What are the steps to reproduce (after prerequisites)?
Open "Yield to Nested Gestures Example".
Screenshots
Compatibility
Checklist
README.md