Skip to content

Commit

Permalink
android: worked around onTouchEvent exception
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fkgozali authored and facebook-github-bot committed Dec 26, 2018
1 parent 0b1f747 commit b748e83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rn_android_library(
"PUBLIC",
],
deps = [
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/bridge:bridge"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.uimanager.UIManagerModule;
Expand Down Expand Up @@ -185,7 +185,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
// Log and ignore the error. This seems to be a bug in the android SDK and
// this is the commonly accepted workaround.
// https://tinyurl.com/mw6qkod (Stack Overflow)
Log.w(ReactConstants.TAG, "Error intercepting touch event.", e);
FLog.w(ReactConstants.TAG, "Error intercepting touch event.", e);
}

return false;
Expand All @@ -197,7 +197,16 @@ public boolean onTouchEvent(MotionEvent ev) {
return false;
}

return super.onTouchEvent(ev);
try {
return super.onTouchEvent(ev);
} catch (IllegalArgumentException e) {
// Log and ignore the error. This seems to be a bug in the android SDK and
// this is the commonly accepted workaround.
// https://fburl.com/5d3iw7d9
FLog.w(ReactConstants.TAG, "Error handling touch event.", e);
}

return false;
}

public void setCurrentItemFromJs(int item, boolean animated) {
Expand Down

0 comments on commit b748e83

Please sign in to comment.