From 06eb1fefabc17816d23fa7393667277bcc684d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Thu, 20 Aug 2026 01:04:12 -0700 Subject: [PATCH] fix: prevent programmatic scrolls from cancelling active touches on iOS (#57546) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: On iOS, a programmatic non-animated scroll — `scrollTo` / `scrollToOffset({ animated: false })`, or any library driving the offset frame-by-frame — cancels every active touch in enclosing scroll views. Two mechanisms combine into this: 1. `scrollToOffset:animated:` calls `_forceDispatchNextScrollEvent` and, for non-animated scrolls, `_handleFinishedScrolling` — so every call emits `onScroll` (twice) plus `onMomentumScrollEnd`, bypassing `scrollEventThrottle` entirely. A per-frame driver produces a continuous stream of unthrottled `topScroll` events (~60/s measured with `scrollEventThrottle={2000}`). 2. In the responder system, any `topScroll` event without `responderIgnoreScroll: true` starts a responder negotiation, and `ScrollView`'s `onScrollShouldSetResponder` answers `true` whenever a finger is down inside it. Each event therefore steals the responder from a pressed `Pressable`/`Touchable` and the press is cancelled — `onPressIn` fires, `onPress` never does. On Android scroll events carry `responderIgnoreScroll: true`. I added `responderIgnoreScroll` to the C++ `ScrollEvent` payload and set it to `!_isUserTriggeredScrolling` in `_scrollViewMetrics`. Programmatic scrolls no longer transfer the responder, while user-initiated scrolls (drag, deceleration, scroll-to-top) keep today's behavior. ## Changelog: [IOS] [FIXED] - Programmatic (non-user-initiated) scrolls no longer cancel active touches in enclosing scroll views Pull Request resolved: https://github.com/react/react-native/pull/57546 Test Plan: Reproducible code — an endless marquee `FlatList` nested in a `ScrollView`, driven by `requestAnimationFrame` + `scrollToOffset({ animated: false })`, with a sibling `TouchableOpacity` and a counter proving the touches reach JS:
App.tsx ```tsx import { useEffect, useMemo, useRef, useState } from 'react'; import { FlatList, ScrollView, Text, TouchableOpacity, View, } from 'react-native'; const dpPerSecond = 20; const size = 80; const gap = 8; const data = Array.from({ length: 6 }).map((_, i) => ({ id: `id-${i}`, n: i + 1, })); const renderItem = ({ item }: { item: (typeof data)[0] }) => ( #{item.n} ); const Carousel = ({ paused }: { paused: boolean }) => { const ref = useRef(null); const [width, setWidth] = useState(0); const offset = useRef(0); useEffect(() => { if (paused) return; const x = (size + gap) * data.length; let last = Date.now(); let raf: number; const loop = () => { const now = Date.now(); offset.current = (offset.current + (dpPerSecond * (now - last)) / 1000) % x; last = now; ref.current?.scrollToOffset({ offset: offset.current, animated: false }); raf = requestAnimationFrame(loop); }; raf = requestAnimationFrame(loop); return () => cancelAnimationFrame(raf); }, [paused]); const neededToFill = Math.ceil(width / (size + gap)); const extendedData = useMemo( () => [ ...data, ...data.slice(0, neededToFill).map((d) => ({ ...d, id: d.id + '-dup' })), ], [neededToFill] ); return ( setWidth(e.nativeEvent.layout.width)} contentContainerStyle={{ gap }} ref={ref} horizontal data={extendedData} keyExtractor={(item) => item.id} renderItem={renderItem} /> ); }; export default () => { const [paused, setPaused] = useState(true); const [touches, setTouches] = useState(0); return ( setTouches((t) => t + 1)}> setPaused((p) => !p)}> Try tapping me {paused ? '▶️' : '⏸️'} touches seen by JS: {touches} ); }; ```
Before this change, only the first tap works (it starts the marquee); every following tap increments the touch counter but never toggles the button — the press is cancelled by the responder transfer. After this change, every tap toggles the marquee. Recordings of the repro above (every touch is marked with a blue ring and counted on screen): Before: https://github.com/user-attachments/assets/bc5a8764-efe3-40ba-a9cb-a5023d140369 After: https://github.com/user-attachments/assets/b2c1eea1-dcab-422c-9a4a-90fd69061e9d Reviewed By: cipolleschi Differential Revision: D116453881 Pulled By: j-piasecki fbshipit-source-id: eb72fb0f1a4ac9fdde15f621201009d855d63890 --- .../ComponentViews/ScrollView/RCTScrollViewComponentView.mm | 1 + .../ComponentViews/TextInput/RCTTextInputComponentView.mm | 4 +++- .../react/renderer/components/scrollview/ScrollEvent.cpp | 4 +++- .../react/renderer/components/scrollview/ScrollEvent.h | 1 + .../renderer/components/textinput/TextInputEventEmitter.cpp | 3 +++ .../renderer/components/textinput/TextInputEventEmitter.h | 1 + .../Libraries/Components/TextInput/TextInput.d.ts | 1 + scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api | 2 ++ scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api | 2 ++ scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api | 2 ++ scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api | 2 ++ scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api | 2 ++ scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api | 2 ++ scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api | 2 ++ scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api | 2 ++ scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api | 2 ++ 16 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm index 54a14a0b864..14a08b49cb7 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -597,6 +597,7 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu metrics.containerSize = RCTSizeFromCGSize(_scrollView.bounds.size); metrics.zoomScale = _scrollView.zoomScale; metrics.timestamp = CACurrentMediaTime(); + metrics.responderIgnoreScroll = !_isUserTriggeredScrolling; if (_layoutMetrics.layoutDirection == LayoutDirection::RightToLeft) { metrics.contentOffset.x = metrics.contentSize.width - metrics.containerSize.width - metrics.contentOffset.x; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index bcda83e61ba..8f55121cd23 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -539,7 +539,9 @@ static NSSet *returnKeyTypesSet; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (_eventEmitter) { - static_cast(*_eventEmitter).onScroll([self _textInputMetrics]); + auto metrics = [self _textInputMetrics]; + metrics.responderIgnoreScroll = !(scrollView.isDragging || scrollView.isDecelerating); + static_cast(*_eventEmitter).onScroll(metrics); } } diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.cpp b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.cpp index 7adacc57527..5307df67ff6 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.cpp @@ -44,6 +44,7 @@ jsi::Value ScrollEvent::asJSIValue(jsi::Runtime& runtime) const { payload.setProperty(runtime, "zoomScale", zoomScale); payload.setProperty(runtime, "timestamp", timestamp * 1000); + payload.setProperty(runtime, "responderIgnoreScroll", responderIgnoreScroll); return payload; } @@ -67,7 +68,8 @@ folly::dynamic ScrollEvent::asDynamic() const { "contentInset", std::move(contentInsetObj))( "contentSize", std::move(contentSizeObj))( "layoutMeasurement", std::move(containerSizeObj))( - "zoomScale", zoomScale)("timestamp", timestamp * 1000); + "zoomScale", zoomScale)("timestamp", timestamp * 1000)( + "responderIgnoreScroll", responderIgnoreScroll); return metrics; }; diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.h b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.h index fb2cd8b44fd..c3fd9583828 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.h +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollEvent.h @@ -21,6 +21,7 @@ struct ScrollEvent : public EventPayload { EdgeInsets contentInset; Size containerSize; Float zoomScale{}; + bool responderIgnoreScroll{false}; /* * The time in seconds when the touch occurred or when it was last mutated. diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp index 2982b12fe01..7da2622926d 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp @@ -86,6 +86,9 @@ static jsi::Value textInputMetricsScrollPayload( "zoomScale", textInputMetrics.zoomScale != 0.0f ? textInputMetrics.zoomScale : 1); + payload.setProperty( + runtime, "responderIgnoreScroll", textInputMetrics.responderIgnoreScroll); + return payload; }; diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h index d85b76e806b..8c1a443f9e5 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h @@ -29,6 +29,7 @@ class TextInputEventEmitter : public ViewEventEmitter { int eventCount; Size layoutMeasurement; Float zoomScale; + bool responderIgnoreScroll{false}; Tag target; }; diff --git a/packages/react-native/types_DEPRECATED/Libraries/Components/TextInput/TextInput.d.ts b/packages/react-native/types_DEPRECATED/Libraries/Components/TextInput/TextInput.d.ts index cc5dc34dd6b..21bb5c60658 100644 --- a/packages/react-native/types_DEPRECATED/Libraries/Components/TextInput/TextInput.d.ts +++ b/packages/react-native/types_DEPRECATED/Libraries/Components/TextInput/TextInput.d.ts @@ -440,6 +440,7 @@ export type TextInputFocusEvent = NativeSyntheticEvent; */ export interface TextInputScrollEventData { contentOffset: {x: number; y: number}; + responderIgnoreScroll?: boolean | undefined; } /** diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api index 5eb6faa7d0f..2e6dc7e0b4e 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api @@ -5118,6 +5118,7 @@ struct facebook::react::TextInputEventEmitter::KeyPressMetrics { } struct facebook::react::TextInputEventEmitter::Metrics { + public bool responderIgnoreScroll; public facebook::react::AttributedString::Range selectionRange; public facebook::react::EdgeInsets contentInset; public facebook::react::Float zoomScale; @@ -7971,6 +7972,7 @@ struct facebook::react::ScrollEndDragEvent : public facebook::react::ScrollEvent struct facebook::react::ScrollEvent : public facebook::react::EventPayload { public ScrollEvent() = default; + public bool responderIgnoreScroll; public facebook::react::EdgeInsets contentInset; public facebook::react::Float timestamp; public facebook::react::Float zoomScale; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api index 33d2a212b96..7ec351405ee 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api @@ -4928,6 +4928,7 @@ struct facebook::react::TextInputEventEmitter::KeyPressMetrics { } struct facebook::react::TextInputEventEmitter::Metrics { + public bool responderIgnoreScroll; public facebook::react::AttributedString::Range selectionRange; public facebook::react::EdgeInsets contentInset; public facebook::react::Float zoomScale; @@ -7731,6 +7732,7 @@ struct facebook::react::ScrollEndDragEvent : public facebook::react::ScrollEvent struct facebook::react::ScrollEvent : public facebook::react::EventPayload { public ScrollEvent() = default; + public bool responderIgnoreScroll; public facebook::react::EdgeInsets contentInset; public facebook::react::Float timestamp; public facebook::react::Float zoomScale; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api index f47b1abfdbb..6843410835c 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api @@ -5109,6 +5109,7 @@ struct facebook::react::TextInputEventEmitter::KeyPressMetrics { } struct facebook::react::TextInputEventEmitter::Metrics { + public bool responderIgnoreScroll; public facebook::react::AttributedString::Range selectionRange; public facebook::react::EdgeInsets contentInset; public facebook::react::Float zoomScale; @@ -7962,6 +7963,7 @@ struct facebook::react::ScrollEndDragEvent : public facebook::react::ScrollEvent struct facebook::react::ScrollEvent : public facebook::react::EventPayload { public ScrollEvent() = default; + public bool responderIgnoreScroll; public facebook::react::EdgeInsets contentInset; public facebook::react::Float timestamp; public facebook::react::Float zoomScale; diff --git a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api index e1c2982613a..d6dc3f80a6a 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api @@ -7292,6 +7292,7 @@ struct facebook::react::TextInputEventEmitter::KeyPressMetrics { } struct facebook::react::TextInputEventEmitter::Metrics { + public bool responderIgnoreScroll; public facebook::react::AttributedString::Range selectionRange; public facebook::react::EdgeInsets contentInset; public facebook::react::Float zoomScale; @@ -9990,6 +9991,7 @@ struct facebook::react::ScrollEndDragEvent : public facebook::react::ScrollEvent struct facebook::react::ScrollEvent : public facebook::react::EventPayload { public ScrollEvent() = default; + public bool responderIgnoreScroll; public facebook::react::EdgeInsets contentInset; public facebook::react::Float timestamp; public facebook::react::Float zoomScale; diff --git a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api index 95c65c5ed1b..da7a542fd69 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api @@ -7134,6 +7134,7 @@ struct facebook::react::TextInputEventEmitter::KeyPressMetrics { } struct facebook::react::TextInputEventEmitter::Metrics { + public bool responderIgnoreScroll; public facebook::react::AttributedString::Range selectionRange; public facebook::react::EdgeInsets contentInset; public facebook::react::Float zoomScale; @@ -9806,6 +9807,7 @@ struct facebook::react::ScrollEndDragEvent : public facebook::react::ScrollEvent struct facebook::react::ScrollEvent : public facebook::react::EventPayload { public ScrollEvent() = default; + public bool responderIgnoreScroll; public facebook::react::EdgeInsets contentInset; public facebook::react::Float timestamp; public facebook::react::Float zoomScale; diff --git a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api index 0f9ef238b70..a92742d8c14 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api @@ -7283,6 +7283,7 @@ struct facebook::react::TextInputEventEmitter::KeyPressMetrics { } struct facebook::react::TextInputEventEmitter::Metrics { + public bool responderIgnoreScroll; public facebook::react::AttributedString::Range selectionRange; public facebook::react::EdgeInsets contentInset; public facebook::react::Float zoomScale; @@ -9981,6 +9982,7 @@ struct facebook::react::ScrollEndDragEvent : public facebook::react::ScrollEvent struct facebook::react::ScrollEvent : public facebook::react::EventPayload { public ScrollEvent() = default; + public bool responderIgnoreScroll; public facebook::react::EdgeInsets contentInset; public facebook::react::Float timestamp; public facebook::react::Float zoomScale; diff --git a/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api index 411d5c80a1c..763c902b2e2 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api @@ -3609,6 +3609,7 @@ struct facebook::react::TextInputEventEmitter::KeyPressMetrics { struct facebook::react::TextInputEventEmitter::Metrics { public Float zoomScale; + public bool responderIgnoreScroll; public facebook::react::AttributedString::Range selectionRange; public facebook::react::EdgeInsets contentInset; public facebook::react::Point contentOffset; @@ -6092,6 +6093,7 @@ struct facebook::react::ScrollEvent : public facebook::react::EventPayload { public Float timestamp; public Float zoomScale; public ScrollEvent() = default; + public bool responderIgnoreScroll; public facebook::react::EdgeInsets contentInset; public facebook::react::Point contentOffset; public facebook::react::Size containerSize; diff --git a/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api index 1d027d31af2..abad9815f5c 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api @@ -3459,6 +3459,7 @@ struct facebook::react::TextInputEventEmitter::KeyPressMetrics { struct facebook::react::TextInputEventEmitter::Metrics { public Float zoomScale; + public bool responderIgnoreScroll; public facebook::react::AttributedString::Range selectionRange; public facebook::react::EdgeInsets contentInset; public facebook::react::Point contentOffset; @@ -5916,6 +5917,7 @@ struct facebook::react::ScrollEvent : public facebook::react::EventPayload { public Float timestamp; public Float zoomScale; public ScrollEvent() = default; + public bool responderIgnoreScroll; public facebook::react::EdgeInsets contentInset; public facebook::react::Point contentOffset; public facebook::react::Size containerSize; diff --git a/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api index 937203e41aa..0c58351b5c0 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api @@ -3600,6 +3600,7 @@ struct facebook::react::TextInputEventEmitter::KeyPressMetrics { struct facebook::react::TextInputEventEmitter::Metrics { public Float zoomScale; + public bool responderIgnoreScroll; public facebook::react::AttributedString::Range selectionRange; public facebook::react::EdgeInsets contentInset; public facebook::react::Point contentOffset; @@ -6083,6 +6084,7 @@ struct facebook::react::ScrollEvent : public facebook::react::EventPayload { public Float timestamp; public Float zoomScale; public ScrollEvent() = default; + public bool responderIgnoreScroll; public facebook::react::EdgeInsets contentInset; public facebook::react::Point contentOffset; public facebook::react::Size containerSize;