Skip to content

Commit 67a6abe

Browse files
committed
Fix pinch crash in touch-responsive views.
1 parent a580a44 commit 67a6abe

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
@@ -16,10 +16,13 @@
1616
import android.graphics.Rect;
1717
import android.graphics.drawable.ColorDrawable;
1818
import android.graphics.drawable.Drawable;
19+
import android.graphics.drawable.LayerDrawable;
20+
import android.util.Log;
1921
import android.view.MotionEvent;
2022
import android.view.View;
2123
import android.widget.HorizontalScrollView;
2224
import com.facebook.infer.annotation.Assertions;
25+
import com.facebook.react.common.ReactConstants;
2326
import com.facebook.react.uimanager.MeasureSpecAssertions;
2427
import com.facebook.react.uimanager.ReactClippingViewGroup;
2528
import com.facebook.react.uimanager.ReactClippingViewGroupHelper;
@@ -138,12 +141,19 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
138141
return false;
139142
}
140143

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

149159
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
@@ -180,12 +180,19 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
180180
return false;
181181
}
182182

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

191198
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
@@ -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)