Skip to content

Commit 7fcf5d3

Browse files
committed
Fix pinch crash in touch-responsive views.
1 parent 33c3d5d commit 7fcf5d3

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

Lines changed: 13 additions & 3 deletions
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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
import android.graphics.Rect;
1919
import android.graphics.drawable.ColorDrawable;
2020
import android.graphics.drawable.Drawable;
21+
import android.graphics.drawable.LayerDrawable;
22+
import android.util.Log;
2123
import android.view.MotionEvent;
2224
import android.view.View;
2325
import android.widget.HorizontalScrollView;
2426

2527
import com.facebook.infer.annotation.Assertions;
28+
import com.facebook.react.common.ReactConstants;
2629
import com.facebook.react.uimanager.MeasureSpecAssertions;
2730
import com.facebook.react.uimanager.events.NativeGestureUtil;
2831
import com.facebook.react.uimanager.ReactClippingViewGroup;
@@ -124,12 +127,19 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
124127
return false;
125128
}
126129

127-
if (super.onInterceptTouchEvent(ev)) {
128-
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
129-
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
130-
mDragging = true;
131-
enableFpsListener();
132-
return true;
130+
try {
131+
if (super.onInterceptTouchEvent(ev)) {
132+
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
133+
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
134+
mDragging = true;
135+
enableFpsListener();
136+
return true;
137+
}
138+
} catch (IllegalArgumentException e) {
139+
// Log and ignore the error. This seems to be a bug in the android SDK and
140+
// this is the commonly accepted workaround.
141+
// https://tinyurl.com/mw6qkod (Stack Overflow)
142+
Log.w(ReactConstants.TAG, "Error intercepting touch event.", e);
133143
}
134144

135145
return false;

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,19 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
166166
return false;
167167
}
168168

169-
if (super.onInterceptTouchEvent(ev)) {
170-
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
171-
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
172-
mDragging = true;
173-
enableFpsListener();
174-
return true;
169+
try {
170+
if (super.onInterceptTouchEvent(ev)) {
171+
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
172+
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
173+
mDragging = true;
174+
enableFpsListener();
175+
return true;
176+
}
177+
} catch (IllegalArgumentException e) {
178+
// Log and ignore the error. This seems to be a bug in the android SDK and
179+
// this is the commonly accepted workaround.
180+
// https://tinyurl.com/mw6qkod (Stack Overflow)
181+
Log.w(ReactConstants.TAG, "Error intercepting touch event.", e);
175182
}
176183

177184
return false;

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414

1515
import android.support.v4.view.PagerAdapter;
1616
import android.support.v4.view.ViewPager;
17+
import android.util.Log;
1718
import android.view.MotionEvent;
1819
import android.view.View;
1920
import android.view.ViewGroup;
2021

2122
import com.facebook.react.bridge.ReactContext;
23+
import com.facebook.react.common.ReactConstants;
2224
import com.facebook.react.uimanager.UIManagerModule;
2325
import com.facebook.react.uimanager.events.EventDispatcher;
2426
import com.facebook.react.uimanager.events.NativeGestureUtil;
@@ -178,10 +180,18 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
178180
return false;
179181
}
180182

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

0 commit comments

Comments
 (0)