In modules or classes that call ReactApplicationContext.getJSModule, ensure that there's still a CatalystInstance alive

Summary:
In D18032458 we introduce getReactApplicationContextIfActiveOrWarn. In this diff, modules that access a JS or Native module through ReactApplicationContext need to check if the CatalystInstance is still alive before continuing.

Modules that don't derive from `ReactContextBaseJavaModule` manually check for the catalyst impl and log their own SoftExceptions.

In this diff we also introduce SoftExceptions that by contract never cause crashes, even in debug mode.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D18112989

fbshipit-source-id: 868f01f388aa2db3518db9f873f2afc2a62eed45
This commit is contained in:
Joshua Gross
2019-10-24 17:25:56 -07:00
committed by Facebook Github Bot
parent 070520beea
commit 94cb4bf90c
5 changed files with 59 additions and 13 deletions
@@ -25,6 +25,8 @@ import com.facebook.react.R;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
@@ -278,9 +280,14 @@ public class ReactAccessibilityDelegate extends AccessibilityDelegateCompat {
final WritableMap event = Arguments.createMap();
event.putString("actionName", mAccessibilityActionsMap.get(action));
ReactContext reactContext = (ReactContext) host.getContext();
reactContext
.getJSModule(RCTEventEmitter.class)
.receiveEvent(host.getId(), "topAccessibilityAction", event);
if (reactContext.hasActiveCatalystInstance()) {
reactContext
.getJSModule(RCTEventEmitter.class)
.receiveEvent(host.getId(), "topAccessibilityAction", event);
} else {
ReactSoftException.logSoftException(
TAG, new ReactNoCrashSoftException("Cannot get RCTEventEmitter, no CatalystInstance"));
}
// In order to make Talkback announce the change of the adjustable's value,
// schedule to send a TYPE_VIEW_SELECTED event after performing the scroll actions.