Skip to content

Commit 1780da7

Browse files
fkgozalifacebook-github-bot
authored andcommitted
android: worked around onTouchEvent exception
Summary: Catch `IllegalArgumentException: ReactViewPager.onTouchEvent` and ignore it (but log something) to work around this known bug in the Android SDK per Baseflow/PhotoView#31 (comment). Note that `onInterceptTouchEvent()` is already doing the same thing. Reviewed By: yungsters Differential Revision: D13550425 fbshipit-source-id: 9fa3a7a0ca0cd95aafa3bcae6a59e0d1e690b564
1 parent 09dfaf6 commit 1780da7

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rn_android_library(
1111
"PUBLIC",
1212
],
1313
deps = [
14+
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
1415
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
1516
react_native_dep("third-party/java/jsr-305:jsr-305"),
1617
react_native_target("java/com/facebook/react/bridge:bridge"),

ReactViewPager.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
import android.support.v4.view.PagerAdapter;
1111
import android.support.v4.view.ViewPager;
12-
import android.util.Log;
1312
import android.view.MotionEvent;
1413
import android.view.View;
1514
import android.view.ViewGroup;
15+
import com.facebook.common.logging.FLog;
1616
import com.facebook.react.bridge.ReactContext;
1717
import com.facebook.react.common.ReactConstants;
1818
import com.facebook.react.uimanager.UIManagerModule;
@@ -185,7 +185,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
185185
// Log and ignore the error. This seems to be a bug in the android SDK and
186186
// this is the commonly accepted workaround.
187187
// https://tinyurl.com/mw6qkod (Stack Overflow)
188-
Log.w(ReactConstants.TAG, "Error intercepting touch event.", e);
188+
FLog.w(ReactConstants.TAG, "Error intercepting touch event.", e);
189189
}
190190

191191
return false;
@@ -197,7 +197,16 @@ public boolean onTouchEvent(MotionEvent ev) {
197197
return false;
198198
}
199199

200-
return super.onTouchEvent(ev);
200+
try {
201+
return super.onTouchEvent(ev);
202+
} catch (IllegalArgumentException e) {
203+
// Log and ignore the error. This seems to be a bug in the android SDK and
204+
// this is the commonly accepted workaround.
205+
// https://fburl.com/5d3iw7d9
206+
FLog.w(ReactConstants.TAG, "Error handling touch event.", e);
207+
}
208+
209+
return false;
201210
}
202211

203212
public void setCurrentItemFromJs(int item, boolean animated) {

0 commit comments

Comments
 (0)