mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-09 17:13:46 +08:00
Check for contentView before emitting scroll event
Summary: I've found that when switching between tabs that each have ScrollViews, sometimes `emitScrollEvent` fires without a `contentView`, which causes the following crash: ``` `D/AndroidRuntime(24496): Shutting down VM E/AndroidRuntime(24496): FATAL EXCEPTION: main E/AndroidRuntime(24496): Process: com.listexp, PID: 24496 E/AndroidRuntime(24496): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getWidth()' on a null object reference E/AndroidRuntime(24496): at com.facebook.react.views.scroll.ReactScrollViewHelper.emitScrollEvent(ReactScrollViewHelper.java:59) E/AndroidRuntime(24496): at com.facebook.react.views.scroll.ReactScrollViewHelper.emitScrollMomentumEndEvent(ReactScrollViewHelper.java:46) E/AndroidRuntime(24496): at com.facebook.react.views.scroll.ReactScrollView$1.run(ReactScrollView.java:159) E/AndroidRuntime(24496): at android.os.Handler.handleCallback(Handler.java:739) E/AndroidRuntime(24496): at android.os.Handler.disp Closes https://github.com/facebook/react-native/pull/5561 Reviewed By: svcscm Differential Revision: D2876385 Pulled By: androidtrunkagent fb-gh-sync-id: 33406eaa96352d5adae857088da09fb446b68440
This commit is contained in:
committed by
facebook-github-bot-3
parent
b55dcbe0af
commit
e9f95c1a7d
@@ -48,6 +48,11 @@ public class ReactScrollViewHelper {
|
||||
|
||||
private static void emitScrollEvent(ViewGroup scrollView, ScrollEventType scrollEventType) {
|
||||
View contentView = scrollView.getChildAt(0);
|
||||
|
||||
if (contentView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ReactContext reactContext = (ReactContext) scrollView.getContext();
|
||||
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
|
||||
ScrollEvent.obtain(
|
||||
|
||||
Reference in New Issue
Block a user