mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix T110060790
Summary: In the case of T110060790, there is a JavaScript crash that causes RN teardown to race with a ScrollView event being emitted, which ends up being reported as the "real" cause of the crash. This is not correct, and it's better to just ignore this case. If there's no EventDispatcher, it means something has gone wrong (usually teardown) before, RN is in an inconsistent state, and we should not crash here or report here. Changelog: [Android][Fixed] Fix crash from ScrollView that occurs while reporting an error from JS Reviewed By: mdvacca Differential Revision: D33644692 fbshipit-source-id: 41c3defde795b804239cc8401c8aff71d017d59d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
08e76772fe
commit
2151d11527
+23
-14
@@ -27,6 +27,7 @@ import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.UIManagerHelper;
|
||||
import com.facebook.react.uimanager.common.UIManagerType;
|
||||
import com.facebook.react.uimanager.common.ViewUtil;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
@@ -107,20 +108,28 @@ public class ReactScrollViewHelper {
|
||||
|
||||
ReactContext reactContext = (ReactContext) scrollView.getContext();
|
||||
int surfaceId = UIManagerHelper.getSurfaceId(reactContext);
|
||||
UIManagerHelper.getEventDispatcherForReactTag(reactContext, scrollView.getId())
|
||||
.dispatchEvent(
|
||||
ScrollEvent.obtain(
|
||||
surfaceId,
|
||||
scrollView.getId(),
|
||||
scrollEventType,
|
||||
scrollView.getScrollX(),
|
||||
scrollView.getScrollY(),
|
||||
xVelocity,
|
||||
yVelocity,
|
||||
contentView.getWidth(),
|
||||
contentView.getHeight(),
|
||||
scrollView.getWidth(),
|
||||
scrollView.getHeight()));
|
||||
|
||||
// It's possible for the EventDispatcher to go away - for example,
|
||||
// if there's a crash initiated from JS and we tap on a ScrollView
|
||||
// around teardown of RN, this will cause a NPE. We can safely ignore
|
||||
// this since the crash is usually a red herring.
|
||||
EventDispatcher eventDispatcher =
|
||||
UIManagerHelper.getEventDispatcherForReactTag(reactContext, scrollView.getId());
|
||||
if (eventDispatcher != null) {
|
||||
eventDispatcher.dispatchEvent(
|
||||
ScrollEvent.obtain(
|
||||
surfaceId,
|
||||
scrollView.getId(),
|
||||
scrollEventType,
|
||||
scrollView.getScrollX(),
|
||||
scrollView.getScrollY(),
|
||||
xVelocity,
|
||||
yVelocity,
|
||||
contentView.getWidth(),
|
||||
contentView.getHeight(),
|
||||
scrollView.getWidth(),
|
||||
scrollView.getHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
/** This is only for Java listeners. onLayout events emitted to JS are handled elsewhere. */
|
||||
|
||||
Reference in New Issue
Block a user