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 https://github.com/chrisbanes/PhotoView/issues/31#issuecomment-19803926. Note that `onInterceptTouchEvent()` is already doing the same thing.

Reviewed By: yungsters

Differential Revision: D13550425

fbshipit-source-id: 9fa3a7a0ca0cd95aafa3bcae6a59e0d1e690b564
This commit is contained in:
Kevin Gozali 2018-12-26 14:51:50 -08:00 коммит произвёл Facebook Github Bot
Родитель 0b1f74712f
Коммит b748e83fbf
2 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -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"),

Просмотреть файл

@ -9,10 +9,10 @@ package com.facebook.react.views.viewpager;
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;
@ -185,7 +185,7 @@ public class ReactViewPager extends ViewPager {
// 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;
@ -197,7 +197,16 @@ public class ReactViewPager extends ViewPager {
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) {