Skip to content

Let iOS scroll views scroll inside a ScrollView JS responder - #60367

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
expo:@ide/ios-block-native-responder
Dec 2, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
expo:@ide/ios-block-native-responder

Conversation

@ide

@ide ide commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

On iOS a scroll view does not scroll while one of its ancestors is the JavaScript responder: RCTScrollViewComponentView answers NO from touchesShouldCancelInContentView:, and a UIScrollView that gets NO from that method does not begin dragging. This is meant for a gesture that JavaScript owns, such as a PanResponder or a Pressable around a list.

A ScrollView also takes the responder itself, for instance when a touch should dismiss the keyboard (with the default keyboardShouldPersistTaps, or with "handled" when nothing inside handled the touch) or while it is animating (_handleStartShouldSetResponderCapture, _handleStartShouldSetResponder). The scroll views inside it then could not be dragged. With the keyboard up, a drag on a horizontal list inside a vertical one did nothing, and the release dismissed the keyboard. On Android the inner list scrolls and the keyboard stays.

This change has two parts.

A scroll view stops only for an ancestor responder that is not a scroll view. That is Android's rule: JSResponderHandler.onInterceptTouchEvent gives the responder's view its descendants' touches, and only a ReactViewGroup asks it; a scroll view does not. A scroll view inside a Pressable, a Touchable or a PanResponder behaves as before on both platforms: it does not scroll, and a Pressable presses on release.

When a drag or a pinch begins on a scroll view under a scroll view that is the responder, the inner scroll view cancels the touches that began inside it. JavaScript receives touchcancel (and pointercancel when W3C pointer events are on) for those touches, and the responder is terminated, so the outer ScrollView does not dismiss the keyboard when the drag ends. The responder system does not do this. For an event that comes from inside the responder, it offers the responder only to the views above the responder, so the inner ScrollView never gets onScrollShouldSetResponder. Android cancels at the same moment, in NativeGestureUtil.notifyNativeGestureStarted.

The cancel is narrower than Android's in one way. Android cancels every touch on the surface and sends JavaScript nothing more until all fingers lift (JSTouchDispatcher.onChildStartedNativeGesture). Here only the inner scroll view's touches are affected. The touches that began inside it are cancelled, and until they have ended a finger that lands inside it is not reported to JavaScript either. A finger resting elsewhere keeps its touch and gets its touchend. The responder is still terminated, because the responder system terminates it on any touchcancel.

How it is built:

  • -[RCTSurfaceTouchHandler cancelTouchesInView:] and -[RCTSurfacePointerHandler cancelPointersInView:] are new and internal, declared in RCTSurfaceTouchHandler+Internal.h and RCTSurfacePointerHandler+Internal.h. No public header and no API snapshot changes.
  • UIKit keeps reporting a touch until it ends, whatever the handler told JavaScript. Both handlers remember the touches they cancelled and drop those touches' later events. Without that, RCTSurfaceTouchHandler logs "Inconsistency between local and UIKit touch registries" for such a touch, and RCTSurfacePointerHandler asserts. They add to that set, without reporting it, a touch that begins inside the same view while one of them is still down. Without that, the new finger makes the outer ScrollView take the responder again and dismiss the keyboard.
  • The scroll view finds the handler by walking up from the responder to the first view that has an RCTSurfaceTouchHandler: the surface's view, a Modal's view, or an InputAccessoryView's content view. The nearest one is the one that sent the responder its touches.
  • A zoom that a command animates (zoomToRect) also reaches scrollViewWillBeginZooming:withView:. It takes no gesture, so the cancel there requires the pinch recognizer to be active.

Not changed, and why:

  • setIsJSResponder's blockNativeResponder argument is still dropped on iOS. On Android it keeps the responder's ancestors from intercepting (JSResponderHandler.setJSResponder); the iOS counterpart would stop the scroll views that enclose a blocking responder, which is a different change. It plays no part in what a responder does to the scroll views inside it, on either platform.
  • A ScrollView inside a Pressable still does not scroll. Letting it scroll and cancelling the press may be the better behavior, but it would have to change on both platforms together, in a separate PR.
  • When two scroll views inside the responder are dragged at once, only the one cancelled last withholds a finger that lands later. A finger that lands on the other one reaches JavaScript, and with the keyboard up it can dismiss the keyboard.
  • A responder granted after the drag began is not terminated. The responder reaches its view asynchronously, and the scroll view checks once, when the drag or the pinch begins.

Changelog:

[IOS] [FIXED] - A ScrollView inside a ScrollView that took the JS responder to dismiss the keyboard can be scrolled, as on Android, and the scroll cancels the JS touch

Test Plan:

Two tests in RCTScrollViewComponentViewTests are new. Both run the real RCTSurfaceTouchHandler. XCTest cannot create a UITouch that carries a view and a phase, so the tests pass the handler's touchesBegan:, touchesMoved:, touchesEnded: and touchesCancelled: a UITouch subclass that overrides the few properties the handler reads, and they read the events from an EventDispatcher listener on each view's TouchEventEmitter.

  • testDragUnderScrollViewJSResponderCancelsOnlyTheTouchesInsideTheScrollView: with one touch inside the inner scroll view and one outside it, scrollViewWillBeginDragging: sends topTouchCancel for the first only; a touch that then begins inside sends nothing; the outside touch goes on to topTouchMove and topTouchEnd; the handler logs no warning for the later events of the touches it dropped; the next touch inside starts and ends as usual; and a zoom callback without a pinch cancels nothing.
  • testViewJSResponderDisablesScrollingAndIsNotCancelled: under a View responder the scroll view still refuses to scroll and cancels nothing.

Each of these makes a test fail: blocking under every responder, as on main; removing the call in scrollViewWillBeginDragging:; cancelling every touch; not dropping the cancelled touch's later events, in touchesMoved: or in touchesCancelled:; reporting a touch that begins inside during the gesture; cancelling for a zoom without a pinch; cancelling under a View responder. The tests do not cover RCTSurfacePointerHandler or the cancel for a real pinch; the simulator check below does. Run with Xcode 27.1 on an iOS 27.0 simulator; RNTester builds:

xcodebuild test -workspace packages/rn-tester/RNTesterPods.xcworkspace -scheme React-RCTFabric-Unit-Tests \
  -destination 'platform=iOS Simulator,id=<iPhone 18 Pro>'

RNTester's Podfile does not install the React-RCTFabric Tests test spec. To run it (locally, not in this change): add :testspecs => ['Tests'] to that pod in scripts/cocoapods/fabric.rb, narrow the test spec's source_files to this test file (RCTSelectableParagraphComponentViewTests.mm does not compile in open source), and add an empty Swift file to it so the bundle links the Swift runtime RCTSwiftUI needs.

Checked on an iPhone 18 Pro simulator with iOS 27.0, on main and on this change, and on an Android 16 emulator at this change, which touches no Android code. A UI test (adb shell input on Android) makes the gesture and reads counters that a page in RNTester's Playground shows: the inner list's contentOffset, onPress, and the touchcancel and touchend events that reach chosen views. No device was used. The nested case is a horizontal ScrollView inside a vertical one (default keyboardShouldPersistTaps), with a TextInput focused and the software keyboard up.

The first row on the simulator, with main on the left and this change on the right. On the left the list stays put and the keyboard goes down on release; on the right the list scrolls and the keyboard stays:

A drag on the horizontal list inside a vertical ScrollView with the keyboard up, on the iOS simulator, main on the left and this change on the right

Case iOS main iOS, this change Android
Nested: drag the horizontal list does not scroll; keyboard dismissed scrolls; one touchcancel; keyboard stays scrolls; one touchcancel; keyboard stays
Nested: one finger rests on a view outside the horizontal list while a second drags the list does not scroll; keyboard dismissed scrolls; one touchcancel, for the dragging finger; the resting finger gets its touchend; keyboard stays not checked
Nested: a second finger taps the horizontal list while the first still drags it does not scroll; keyboard dismissed scrolls; one touchcancel; keyboard stays not checked
Nested, the inner scroll view zoomable: pinch it does not zoom; keyboard dismissed zooms to 2.07; one touchcancel; keyboard stays not checked
The same lists, no keyboard: drag the horizontal list while the outer one decelerates does not scroll does not scroll not checked
The same lists, no keyboard: drag the horizontal list while the outer one runs an animated scrollTo scrolls; no touchcancel scrolls; a touchcancel for some drags not checked
A ScrollView of Text rows inside a Pressable: drag a row does not scroll; one press does not scroll; one press does not scroll; one press
The same, zoomable: pinch does not zoom; one press does not zoom; one press not checked
The same inside a View with PanResponder.create({onStartShouldSetPanResponder: () => true}).panHandlers: drag does not scroll does not scroll does not scroll
Pressable rows inside a ScrollView, nothing above it: drag scrolls; no press; no touchcancel the same scrolls; no press; one touchcancel

In the deceleration case the touch landed while the outer list was still moving (the page counts it), and the inner list did not scroll before or after, so that case does not change. In the animated scrollTo case each run made three drags and the page kept the largest inner offset, not one per drag. On main it was 191 in one run and 382 in the other, so the list scrolled there. On this change it was 382 in both runs, and one drag in one run and two in the other sent a touchcancel: those began while the outer ScrollView held the responder. Whether main let those particular drags scroll was not measured. With W3C pointer events turned on in a local build, the drag in the first two rows sends one pointercancel and the pinch sends two, and the pointer handler's assertions stay quiet.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 28, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 28, 2026
@ide
ide force-pushed the @ide/ios-block-native-responder branch from db36716 to 1d6d309 Compare November 29, 2026 12:02
@ide
ide marked this pull request as ready for review November 29, 2026 13:49
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 29, 2026

@chrfalch chrfalch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good to me: passing blockNativeResponder through to touchesShouldCancelInContentView fixes the root cause, and the new test drives the real mounting path. (Commenting rather than approving since it's still a draft.)

One request for the description: the change also affects nested scroll views. ScrollView can itself become the JS responder (e.g. via its keyboard-tap handling), and its grant handler doesn't return true, so it never blocks native responders. Before this PR, an inner scroll view would refuse to start scrolling while an outer ScrollView held the JS responder; after it, the inner one scrolls. Think of a horizontal carousel inside a vertical list, or a scrollable TextInput in a form.

That's probably the better behavior, and it matches Android, but it's a second behavior change beyond the Pressable case. Could you mention it in the description, and ideally check a nested scroll view on device?

@javache javache 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.

Thanks for fixing this. Let's call out that this brings API parity with Android, which already behaved this way (https://github.com/react/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java#L1441)

@meta-codesync

meta-codesync Bot commented Nov 30, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D135059323.

@zeyap zeyap 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.

Review automatically exported from Phabricator review in Meta.

@ide

ide commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@javache Added to the description, with a link to FabricUIManager.java, and the changelog now says "as on Android".

The internal "Builds & Tests" check fails on this PR, and the internal linter needs action. Neither is visible outside Meta; could you tell me what they report?

@ide

ide commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@chrfalch The description now has a paragraph on nested scroll views: a horizontal list inside a vertical one, and a scrollable multiline TextInput in a form. I haven't checked them on a device or a simulator, and the test plan says so.

ide added a commit to expo/react-native that referenced this pull request Dec 1, 2026
@ide
ide force-pushed the @ide/ios-block-native-responder branch from 1d6d309 to fb1f29d Compare December 1, 2026 10:59
@ide

ide commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@javache @chrfalch I checked this on a simulator and an Android emulator, and two things I told you were wrong. The branch and the description are updated, so please look again: the approval was for a different claim, and the change needs a new import.

The first revision did not cancel the press. With a ScrollView inside a Pressable, the list scrolled and the release still fired onPress. When an event comes from inside the current responder, the responder system offers the responder only to views above it, so the ScrollView never got onScrollShouldSetResponder. The scroll view now cancels JavaScript's touches when a drag or a pinch begins under a responder that does not block, through a new -[RCTSurfaceTouchHandler cancelTouches]. A scroll view with no responder above it is unchanged.

This is not parity with Android for a Pressable. On an Android 16 emulator, the same ScrollView inside a Pressable does not scroll, and the drag ends in a press, as on iOS main. JSResponderHandler.onInterceptTouchEvent gives the responder's view its descendants' touches whether or not it blocks, and blockNativeResponder only keeps the responder's ancestors from intercepting. Parity holds for nested scroll views: with the keyboard up, a horizontal list inside a vertical one scrolls on Android, sends touchcancel and leaves the keyboard up, and iOS now does the same.

So for a View responder this change makes iOS differ from Android. I think scrolling there is the better behavior, but it is your call whether iOS should lead, or whether this PR should be narrowed to the nested scroll view case. The description has an "Android" section, a table of what I ran on both platforms, and a recording of the Pressable case.

@chrfalch The nested case you asked about is in that table, and the keyboard case changes as you described. A touch that lands while the outer list decelerates does not let the inner one scroll, before or after this change, so I removed that claim. I also removed the multiline TextInput example, since the text view never consulted the responder. No device was used.

@chrfalch chrfalch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for checking this on both platforms and for correcting the description. Your analysis holds up: when the target is inside the current responder, the responder system only offers the responder to views above it, so the ScrollView is never asked; and on Android JSResponderHandler intercepts for the responder's view regardless of blockNativeResponder.

I'd suggest narrowing this PR to the nested scroll view case. For a View/Pressable responder, this version makes iOS scroll and cancel where Android doesn't scroll and ends in a press. Scrolling may well be the better behavior, but changing it on one platform only creates a new iOS/Android difference that apps would have to handle. That deserves its own PR, ideally changing both platforms together. Narrowing looks small: in _shouldDisableScrollInteraction, keep blocking when the responder isn't an RCTScrollViewComponentView, and only cancel when the responder is a scroll view. Then both platforms agree in both cases.

Whichever way that goes, three things:

  1. Keep cancelTouches internal. -[RCTSurfaceTouchHandler cancelTouches] is added to the public header, but its only caller is in the same module. A private header or category avoids committing to a public method.
  2. It cancels every touch on the surface. A finger on an unrelated PanResponder (say, a slider dragged with a second finger) is terminated too, without a termination request, and so is a Pressable with cancelable={false}. Can this be limited to the touches inside the scroll view?
  3. Test the real cancel. RCTCancelCountingTouchHandler replaces cancelTouches with a counter, so nothing exercises the actual reset: that JS gets touchcancel and that the next touch still works. A test that runs the real handler would cover the part most likely to break.

ide added a commit to expo/react-native that referenced this pull request Dec 1, 2026
On iOS a scroll view does not scroll while one of its ancestors is the JavaScript responder: `RCTScrollViewComponentView` answers NO from `touchesShouldCancelInContentView:`, and a `UIScrollView` that may not cancel its content's touches does not begin dragging. This is meant for a gesture that JavaScript owns, such as a `PanResponder` or a `Pressable` around a list.

A `ScrollView` also takes the responder itself, for instance when a touch should dismiss the keyboard, and then the scroll views inside it could not be dragged: with the keyboard up, a drag on a horizontal list inside a vertical one did nothing, and the release dismissed the keyboard. On Android the inner list scrolls. Only a view group that is the responder takes its descendants' touches there (`JSResponderHandler`), and a scroll view is not one.

Stop a scroll view only for an ancestor responder that is not a scroll view. A scroll view inside a `Pressable` or a `PanResponder` is unchanged, as on Android.

When a drag or a pinch begins on a scroll view under a scroll view that is the responder, cancel the touches that began inside the inner scroll view, through the `RCTSurfaceTouchHandler` above the responder. The responder is then terminated, so the outer `ScrollView` does not dismiss the keyboard when the drag ends. The responder system does not do this: for an event that comes from inside the responder it offers the responder only to the views above it, so the inner `ScrollView` never gets `onScrollShouldSetResponder`. Android cancels at the same moment, in `NativeGestureUtil.notifyNativeGestureStarted`, and cancels every touch on the surface. Here a finger outside the inner scroll view keeps its touch.

`cancelTouchesInView:` is declared in `RCTSurfaceTouchHandler+Internal.h` and is not public API. UIKit keeps reporting a touch until it ends, whatever the handler told JavaScript, so the touch and pointer handlers drop the later events of the touches they cancelled. Until those touches have ended they also keep from JavaScript a touch that begins inside the same view, which is part of the gesture the view took.
@ide
ide force-pushed the @ide/ios-block-native-responder branch from fb1f29d to ed87f8e Compare December 1, 2026 18:58
@ide ide changed the title Let iOS scroll views scroll inside a non-blocking JS responder Let iOS scroll views scroll inside a ScrollView JS responder Dec 1, 2026

@chrfalch chrfalch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the rework, this addresses everything from my last comment:

  1. Only a scroll-view responder is cancelled; any other JS responder still blocks the nested scroll view.
  2. cancelTouchesInView: now lives in RCTSurfaceTouchHandler+Internal.h, and the public header is unchanged.
  3. Only touches that started inside the inner scroll view are cancelled, so an unrelated PanResponder or slider elsewhere on the surface keeps its gesture.
  4. The tests drive the real RCTSurfaceTouchHandler and assert on the dispatched events instead of a counting subclass.

The pinch check and the non-scroll-view responder case are covered too.

Two optional follow-ups, not blocking:

  • The cancelled-touch bookkeeping (_cancelledTouches, _cancelledTouchesView, _touchesWithoutTouchesBeganInCancelledView:, _touchesWithoutCancelledTouches:forgettingThem:) is duplicated between RCTSurfaceTouchHandler.mm and RCTSurfacePointerHandler.mm. A small shared helper would keep the two from drifting apart.
  • The pointer handler's cancel path has no test, only the simulator check. A test like the touch-handler one would protect it, since that handler asserts on touches it doesn't know about.

Looks good to me.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Visual regression

No visual differences at ed87f8eb805c.

android: no capture

@ide

ide commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@chrfalch Thanks. I'll keep this PR as reviewed and take both follow-ups in a separate PR once it lands: a shared helper for the cancelled-touch bookkeeping, and a test of the pointer handler's cancel path.

@javache The PR has changed since your import. It is narrowed to nested scroll views and no longer changes a public header, so it needs a new import.

@meta-codesync
meta-codesync Bot merged commit 2c52501 into react:main Dec 2, 2026
89 of 93 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @ide in 2c52501

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Dec 2, 2026
@ide
ide deleted the @ide/ios-block-native-responder branch December 2, 2026 23:41
ide added a commit to expo/react-native that referenced this pull request Dec 3, 2026
Summary:

react#60367 lets a scroll view inside a `ScrollView` that is the JavaScript responder cancel the touches that began inside it. `RCTSurfaceTouchHandler` and `RCTSurfacePointerHandler` each kept their own copy of the bookkeeping for those cancelled touches, and only the touch handler's cancel had a test. chrfalch's review of react#60367 suggested sharing the bookkeeping and testing the pointer handler (react#60367 (review)).

This change moves the bookkeeping into `RCTCancelledTouches`, a C++ class both handlers hold. It is declared in `RCTCancelledTouches+Internal.h`, which the C++ API snapshots leave out. Behavior doesn't change.

Changelog:

[Internal] - Share the cancelled-touch bookkeeping of the iOS touch and pointer handlers, and test the pointer handler's cancel

Test Plan:

`RCTScrollViewComponentViewTests` gains `testDragUnderScrollViewJSResponderCancelsOnlyThePointersInsideTheScrollView`. It checks that a drag cancels only the pointers inside the inner scroll view, that the cancelled touch's later events are dropped, that a touch beginning inside waits until the cancelled one ends, and that `reset` clears the state. It and the existing touch-handler test pass before and after the move, and breaking each part of the bookkeeping makes one of them fail. I didn't run the change in RNTester.

```sh
xcodebuild test -workspace packages/rn-tester/RNTesterPods.xcworkspace -scheme React-RCTFabric-Unit-Tests \
  -destination 'platform=iOS Simulator,name=iPhone 18 Pro'
```

RNTester's Podfile doesn't install the `React-RCTFabric` `Tests` spec, so open-source CI doesn't run these tests. `yarn format-check-cpp` passes.

Signed-off-by: James Ide <ide@expo.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants