From 745181d152ff6bf1d3b6f7e706befed371c2ba32 Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Thu, 21 May 2026 22:18:44 +0200 Subject: [PATCH] Fix IllegalArgumentException crash in ScrollView.onTouchEvent on Android The same IllegalArgumentException thrown by Android's framework ScrollView when its tracked active pointer becomes stale is already caught in onInterceptTouchEvent in all three Android ScrollView variants (ReactScrollView, ReactHorizontalScrollView, ReactNestedScrollView) but not in onTouchEvent. Mirror the existing workaround into onTouchEvent. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../react/views/scroll/ReactHorizontalScrollView.java | 10 +++++++++- .../react/views/scroll/ReactNestedScrollView.java | 10 +++++++++- .../facebook/react/views/scroll/ReactScrollView.java | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java index fb8918fcd0d1..a153bea92bb4 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java @@ -838,7 +838,15 @@ public boolean onTouchEvent(MotionEvent ev) { cancelPostTouchScrolling(); } - return super.onTouchEvent(ev); + try { + return super.onTouchEvent(ev); + } catch (IllegalArgumentException e) { + // Log and ignore the error. This seems to be a bug in the android SDK and + // this is the commonly accepted workaround. + // https://tinyurl.com/mw6qkod (Stack Overflow) + FLog.w(ReactConstants.TAG, "Error handling touch event.", e); + return false; + } } @Override diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactNestedScrollView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactNestedScrollView.java index a49ef0460083..864d365eb1eb 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactNestedScrollView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactNestedScrollView.java @@ -680,7 +680,15 @@ public boolean onTouchEvent(MotionEvent ev) { cancelPostTouchScrolling(); } - return super.onTouchEvent(ev); + try { + return super.onTouchEvent(ev); + } catch (IllegalArgumentException e) { + // Log and ignore the error. This seems to be a bug in the android SDK and + // this is the commonly accepted workaround. + // https://tinyurl.com/mw6qkod (Stack Overflow) + FLog.w(ReactConstants.TAG, "Error handling touch event.", e); + return false; + } } @Override diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java index d263aab7c5a4..1d3c03da6ef3 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java @@ -672,7 +672,15 @@ public boolean onTouchEvent(MotionEvent ev) { cancelPostTouchScrolling(); } - return super.onTouchEvent(ev); + try { + return super.onTouchEvent(ev); + } catch (IllegalArgumentException e) { + // Log and ignore the error. This seems to be a bug in the android SDK and + // this is the commonly accepted workaround. + // https://tinyurl.com/mw6qkod (Stack Overflow) + FLog.w(ReactConstants.TAG, "Error handling touch event.", e); + return false; + } } @Override