Skip to content

Commit 2151d11

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
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
1 parent 08e7677 commit 2151d11

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java

+23-14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.facebook.react.uimanager.UIManagerHelper;
2828
import com.facebook.react.uimanager.common.UIManagerType;
2929
import com.facebook.react.uimanager.common.ViewUtil;
30+
import com.facebook.react.uimanager.events.EventDispatcher;
3031
import java.util.Collections;
3132
import java.util.Set;
3233
import java.util.WeakHashMap;
@@ -107,20 +108,28 @@ private static void emitScrollEvent(
107108

108109
ReactContext reactContext = (ReactContext) scrollView.getContext();
109110
int surfaceId = UIManagerHelper.getSurfaceId(reactContext);
110-
UIManagerHelper.getEventDispatcherForReactTag(reactContext, scrollView.getId())
111-
.dispatchEvent(
112-
ScrollEvent.obtain(
113-
surfaceId,
114-
scrollView.getId(),
115-
scrollEventType,
116-
scrollView.getScrollX(),
117-
scrollView.getScrollY(),
118-
xVelocity,
119-
yVelocity,
120-
contentView.getWidth(),
121-
contentView.getHeight(),
122-
scrollView.getWidth(),
123-
scrollView.getHeight()));
111+
112+
// It's possible for the EventDispatcher to go away - for example,
113+
// if there's a crash initiated from JS and we tap on a ScrollView
114+
// around teardown of RN, this will cause a NPE. We can safely ignore
115+
// this since the crash is usually a red herring.
116+
EventDispatcher eventDispatcher =
117+
UIManagerHelper.getEventDispatcherForReactTag(reactContext, scrollView.getId());
118+
if (eventDispatcher != null) {
119+
eventDispatcher.dispatchEvent(
120+
ScrollEvent.obtain(
121+
surfaceId,
122+
scrollView.getId(),
123+
scrollEventType,
124+
scrollView.getScrollX(),
125+
scrollView.getScrollY(),
126+
xVelocity,
127+
yVelocity,
128+
contentView.getWidth(),
129+
contentView.getHeight(),
130+
scrollView.getWidth(),
131+
scrollView.getHeight()));
132+
}
124133
}
125134

126135
/** This is only for Java listeners. onLayout events emitted to JS are handled elsewhere. */

0 commit comments

Comments
 (0)