From 2b192a3b3739fe139262134ace08a8cf2ddfe9c5 Mon Sep 17 00:00:00 2001 From: Edwin Cowart Date: Thu, 14 Oct 2021 12:48:21 -0400 Subject: [PATCH] Prevent a Android crash from dispatchTouchEvent try-catch block around call which intermittently throws an IllegalArgumentException Resolves Issues: - https://github.com/software-mansion/react-native-gesture-handler/issues/1679 - https://github.com/facebook/react-native/issues/30320 --- .../react/RNGestureHandlerEnabledRootView.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt index 7de0492f42..d9db1abb9e 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt @@ -21,9 +21,14 @@ class RNGestureHandlerEnabledRootView : ReactRootView { } override fun dispatchTouchEvent(ev: MotionEvent): Boolean { - return if (gestureRootHelper?.dispatchTouchEvent(ev) == true) { - true - } else super.dispatchTouchEvent(ev) + return try { + if (gestureRootHelper?.dispatchTouchEvent(ev) == true) { + true + } else super.dispatchTouchEvent(ev) + } catch (e: IllegalArgumentException) { + e.printStackTrace() + false + } } /**