Skip to content

Commit 67c3ad4

Browse files
tobycoxfacebook-github-bot
authored andcommittedFeb 17, 2018
Fix pinch crash in touch-responsive views.
Summary: Fork and rebase of gillessed's PR #13166 which has gotten stale. From original PR: Motivation (required) Multiple react native developer (including myself) have run into a crash with the react-native-photo-view library (and possibly others). The common solution to this problem lies in the underlying java code, and thus requires a change in the react native source. The stack trace I am getting is the same as listed here alwx/react-native-photo-view#15. There was a PR to fix this (#12085) but it was closed. In response to the comments there, in my PR, I do log the exceptions. I don't think we can get any closer to the exception because in the next level of the stack trace, we are in the android sdk code. Looking at some stack overflow pages and the android bug tracker, it seems that this is the common solution to this bug, and does not cause any impact any functionality. https://code.google.com/p/android/issues/list?can=1&q=pointerindex+out+of+range&colspec=ID+Status+Priority+Owner+Summary+Stars+Reporter+Opened&cells=tiles Test Plan (required) I have manually tested this by compiling react native android from source and have confirmed the exception still gets hit and logged, but does not cause the app to terminate. Closes #17167 Differential Revision: D7014296 Pulled By: hramos fbshipit-source-id: 06b4a31062a591b726d2021e877d16f49881dcfd
1 parent d16ff3b commit 67c3ad4

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed
 

‎ReactAndroid/src/main/java/com/facebook/react/views/drawer/ReactDrawerLayout.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
import android.support.v4.widget.DrawerLayout;
1313
import android.view.Gravity;
14+
import android.util.Log;
1415
import android.view.MotionEvent;
1516
import android.view.View;
1617

1718
import com.facebook.react.bridge.ReactContext;
19+
import com.facebook.react.common.ReactConstants;
1820
import com.facebook.react.uimanager.PixelUtil;
1921
import com.facebook.react.uimanager.events.NativeGestureUtil;
2022

@@ -34,10 +36,18 @@ public ReactDrawerLayout(ReactContext reactContext) {
3436

3537
@Override
3638
public boolean onInterceptTouchEvent(MotionEvent ev) {
37-
if (super.onInterceptTouchEvent(ev)) {
38-
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
39-
return true;
39+
try {
40+
if (super.onInterceptTouchEvent(ev)) {
41+
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
42+
return true;
43+
}
44+
} catch (IllegalArgumentException e) {
45+
// Log and ignore the error. This seems to be a bug in the android SDK and
46+
// this is the commonly accepted workaround.
47+
// https://tinyurl.com/mw6qkod (Stack Overflow)
48+
Log.w(ReactConstants.TAG, "Error intercepting touch event.", e);
4049
}
50+
4151
return false;
4252
}
4353

‎ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

+16-6
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
import android.graphics.drawable.ColorDrawable;
1818
import android.graphics.drawable.Drawable;
1919
import android.support.v4.view.ViewCompat;
20+
import android.graphics.drawable.LayerDrawable;
21+
import android.util.Log;
2022
import android.view.MotionEvent;
2123
import android.view.View;
2224
import android.widget.HorizontalScrollView;
2325
import com.facebook.infer.annotation.Assertions;
26+
import com.facebook.react.common.ReactConstants;
2427
import com.facebook.react.uimanager.MeasureSpecAssertions;
2528
import com.facebook.react.uimanager.ReactClippingViewGroup;
2629
import com.facebook.react.uimanager.ReactClippingViewGroupHelper;
@@ -140,12 +143,19 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
140143
return false;
141144
}
142145

143-
if (super.onInterceptTouchEvent(ev)) {
144-
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
145-
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
146-
mDragging = true;
147-
enableFpsListener();
148-
return true;
146+
try {
147+
if (super.onInterceptTouchEvent(ev)) {
148+
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
149+
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
150+
mDragging = true;
151+
enableFpsListener();
152+
return true;
153+
}
154+
} catch (IllegalArgumentException e) {
155+
// Log and ignore the error. This seems to be a bug in the android SDK and
156+
// this is the commonly accepted workaround.
157+
// https://tinyurl.com/mw6qkod (Stack Overflow)
158+
Log.w(ReactConstants.TAG, "Error intercepting touch event.", e);
149159
}
150160

151161
return false;

‎ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,19 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
190190
return false;
191191
}
192192

193-
if (super.onInterceptTouchEvent(ev)) {
194-
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
195-
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
196-
mDragging = true;
197-
enableFpsListener();
198-
return true;
193+
try {
194+
if (super.onInterceptTouchEvent(ev)) {
195+
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
196+
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
197+
mDragging = true;
198+
enableFpsListener();
199+
return true;
200+
}
201+
} catch (IllegalArgumentException e) {
202+
// Log and ignore the error. This seems to be a bug in the android SDK and
203+
// this is the commonly accepted workaround.
204+
// https://tinyurl.com/mw6qkod (Stack Overflow)
205+
Log.w(ReactConstants.TAG, "Error intercepting touch event.", e);
199206
}
200207

201208
return false;

‎ReactAndroid/src/main/java/com/facebook/react/views/viewpager/ReactViewPager.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
import android.support.v4.view.PagerAdapter;
1313
import android.support.v4.view.ViewPager;
14+
import android.util.Log;
1415
import android.view.MotionEvent;
1516
import android.view.View;
1617
import android.view.ViewGroup;
1718
import com.facebook.react.bridge.ReactContext;
19+
import com.facebook.react.common.ReactConstants;
1820
import com.facebook.react.uimanager.UIManagerModule;
1921
import com.facebook.react.uimanager.events.EventDispatcher;
2022
import com.facebook.react.uimanager.events.NativeGestureUtil;
@@ -176,10 +178,18 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
176178
return false;
177179
}
178180

179-
if (super.onInterceptTouchEvent(ev)) {
180-
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
181-
return true;
181+
try {
182+
if (super.onInterceptTouchEvent(ev)) {
183+
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
184+
return true;
185+
}
186+
} catch (IllegalArgumentException e) {
187+
// Log and ignore the error. This seems to be a bug in the android SDK and
188+
// this is the commonly accepted workaround.
189+
// https://tinyurl.com/mw6qkod (Stack Overflow)
190+
Log.w(ReactConstants.TAG, "Error intercepting touch event.", e);
182191
}
192+
183193
return false;
184194
}
185195

0 commit comments

Comments
 (0)
Please sign in to comment.