Simplify API of `getReactApplicationContextIfActiveOrWarn`

Summary:
Simplify the API of `getReactApplicationContextIfActiveOrWarn`. We don't need to pass so much information into this method to collect good SoftExceptions.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D18134400

fbshipit-source-id: 0a250ab0252a44121f3339a31506a0a6c4c7cd35
This commit is contained in:
Joshua Gross 2019-10-25 16:14:21 -07:00 коммит произвёл Facebook Github Bot
Родитель a1a56fe4e5
Коммит 9446277fc1
14 изменённых файлов: 23 добавлений и 45 удалений

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

@ -116,8 +116,7 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule
@Override @Override
public void initialize() { public void initialize() {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, "initialize");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
UIManagerModule uiManager = reactApplicationContext.getNativeModule(UIManagerModule.class); UIManagerModule uiManager = reactApplicationContext.getNativeModule(UIManagerModule.class);
@ -179,8 +178,7 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule
private NativeAnimatedNodesManager getNodesManager() { private NativeAnimatedNodesManager getNodesManager() {
if (mNodesManager == null) { if (mNodesManager == null) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, "getNodesManager");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
UIManagerModule uiManager = reactApplicationContext.getNativeModule(UIManagerModule.class); UIManagerModule uiManager = reactApplicationContext.getNativeModule(UIManagerModule.class);
@ -229,8 +227,7 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule
onAnimatedValueData.putDouble("value", value); onAnimatedValueData.putDouble("value", value);
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext =
getReactApplicationContextIfActiveOrWarn( getReactApplicationContextIfActiveOrWarn();
NAME, "startListeningToAnimatedNodeValue.onValueUpdate");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
reactApplicationContext reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)

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

@ -45,15 +45,15 @@ public abstract class ReactContextBaseJavaModule extends BaseJavaModule {
* thread-safe. * thread-safe.
*/ */
@ThreadConfined(ANY) @ThreadConfined(ANY)
protected @Nullable final ReactApplicationContext getReactApplicationContextIfActiveOrWarn( protected @Nullable final ReactApplicationContext getReactApplicationContextIfActiveOrWarn() {
String tag, String reason) {
if (mReactApplicationContext.hasActiveCatalystInstance()) { if (mReactApplicationContext.hasActiveCatalystInstance()) {
return mReactApplicationContext; return mReactApplicationContext;
} }
// We want to collect data about how often this happens, but SoftExceptions will cause a crash // We want to collect data about how often this happens, but SoftExceptions will cause a crash
// in debug mode, which isn't usually desirable. // in debug mode, which isn't usually desirable.
String msg = "Catalyst Instance has already disappeared: " + reason; String msg = "Catalyst Instance has already disappeared: requested by " + this.getName();
String tag = "ReactContextBaseJavaModule";
if (ReactBuildConfig.DEBUG) { if (ReactBuildConfig.DEBUG) {
FLog.w(tag, msg); FLog.w(tag, msg);
} else { } else {

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

@ -56,8 +56,7 @@ public class JSCHeapCapture extends ReactContextBaseJavaModule {
File f = new File(path + "/capture.json"); File f = new File(path + "/capture.json");
f.delete(); f.delete();
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(TAG, "captureHeap");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
HeapCapture heapCapture = reactApplicationContext.getJSModule(HeapCapture.class); HeapCapture heapCapture = reactApplicationContext.getJSModule(HeapCapture.class);

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

@ -54,8 +54,7 @@ public class JSDevSupport extends ReactContextBaseJavaModule {
} }
public synchronized void getJSHierarchy(int reactTag, DevSupportCallback callback) { public synchronized void getJSHierarchy(int reactTag, DevSupportCallback callback) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(MODULE_NAME, "getJSHierarchy");
JSDevSupportModule jsDevSupportModule = null; JSDevSupportModule jsDevSupportModule = null;
if (reactApplicationContext != null) { if (reactApplicationContext != null) {

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

@ -117,8 +117,7 @@ public class AccessibilityInfoModule extends ReactContextBaseJavaModule
if (mReduceMotionEnabled != isReduceMotionEnabled) { if (mReduceMotionEnabled != isReduceMotionEnabled) {
mReduceMotionEnabled = isReduceMotionEnabled; mReduceMotionEnabled = isReduceMotionEnabled;
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, "updateAndSendReduceMotionChangeEvent");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
reactApplicationContext reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
@ -131,9 +130,7 @@ public class AccessibilityInfoModule extends ReactContextBaseJavaModule
if (mTouchExplorationEnabled != enabled) { if (mTouchExplorationEnabled != enabled) {
mTouchExplorationEnabled = enabled; mTouchExplorationEnabled = enabled;
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(
NAME, "updateAndSendTouchExplorationChangeEvent");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
getReactApplicationContext() getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)

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

@ -86,8 +86,7 @@ public class AppearanceModule extends ReactContextBaseJavaModule {
WritableMap appearancePreferences = Arguments.createMap(); WritableMap appearancePreferences = Arguments.createMap();
appearancePreferences.putString("colorScheme", colorScheme); appearancePreferences.putString("colorScheme", colorScheme);
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, "emitAppearanceChanged");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
reactApplicationContext reactApplicationContext

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

@ -93,9 +93,7 @@ public class AppStateModule extends ReactContextBaseJavaModule
} }
private void sendEvent(String eventName, @Nullable Object data) { private void sendEvent(String eventName, @Nullable Object data) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(
TAG, "sendAppStateChangeEvent: trying to update app state");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
reactApplicationContext.getJSModule(RCTDeviceEventEmitter.class).emit(eventName, data); reactApplicationContext.getJSModule(RCTDeviceEventEmitter.class).emit(eventName, data);

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

@ -287,8 +287,7 @@ public class BlobModule extends ReactContextBaseJavaModule {
} }
private WebSocketModule getWebSocketModule(String reason) { private WebSocketModule getWebSocketModule(String reason) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, reason);
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
return reactApplicationContext.getNativeModule(WebSocketModule.class); return reactApplicationContext.getNativeModule(WebSocketModule.class);
@ -299,8 +298,7 @@ public class BlobModule extends ReactContextBaseJavaModule {
@ReactMethod @ReactMethod
public void addNetworkingHandler() { public void addNetworkingHandler() {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, "addNetworkingHandler");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
NetworkingModule networkingModule = NetworkingModule networkingModule =

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

@ -31,8 +31,7 @@ public class FileReaderModule extends ReactContextBaseJavaModule {
} }
private BlobModule getBlobModule(String reason) { private BlobModule getBlobModule(String reason) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, reason);
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
return reactApplicationContext.getNativeModule(BlobModule.class); return reactApplicationContext.getNativeModule(BlobModule.class);

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

@ -47,8 +47,7 @@ public class DeviceEventManagerModule extends ReactContextBaseJavaModule {
/** Sends an event to the JS instance that the hardware back has been pressed. */ /** Sends an event to the JS instance that the hardware back has been pressed. */
public void emitHardwareBackPressed() { public void emitHardwareBackPressed() {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, "emitHardwareBackPressed");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
reactApplicationContext reactApplicationContext
@ -59,8 +58,7 @@ public class DeviceEventManagerModule extends ReactContextBaseJavaModule {
/** Sends an event to the JS instance that a new intent was received. */ /** Sends an event to the JS instance that a new intent was received. */
public void emitNewIntentReceived(Uri uri) { public void emitNewIntentReceived(Uri uri) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, "emitHardwareBackPressed");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
WritableMap map = Arguments.createMap(); WritableMap map = Arguments.createMap();

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

@ -25,8 +25,7 @@ public final class TimingModule extends ReactContextBaseJavaModule
public class BridgeTimerManager implements JavaScriptTimerManager { public class BridgeTimerManager implements JavaScriptTimerManager {
@Override @Override
public void callTimers(WritableArray timerIDs) { public void callTimers(WritableArray timerIDs) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, "callTimers");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
reactApplicationContext.getJSModule(JSTimers.class).callTimers(timerIDs); reactApplicationContext.getJSModule(JSTimers.class).callTimers(timerIDs);
@ -35,8 +34,7 @@ public final class TimingModule extends ReactContextBaseJavaModule
@Override @Override
public void callIdleCallbacks(double frameTime) { public void callIdleCallbacks(double frameTime) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, "callIdleCallbacks");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
reactApplicationContext.getJSModule(JSTimers.class).callIdleCallbacks(frameTime); reactApplicationContext.getJSModule(JSTimers.class).callIdleCallbacks(frameTime);
@ -45,8 +43,7 @@ public final class TimingModule extends ReactContextBaseJavaModule
@Override @Override
public void emitTimeDriftWarning(String warningMessage) { public void emitTimeDriftWarning(String warningMessage) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(NAME, "emitTimeDriftWarning");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
reactApplicationContext.getJSModule(JSTimers.class).emitTimeDriftWarning(warningMessage); reactApplicationContext.getJSModule(JSTimers.class).emitTimeDriftWarning(warningMessage);

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

@ -94,7 +94,7 @@ public class DevSettingsModule extends ReactContextBaseJavaModule {
data.putString("title", title); data.putString("title", title);
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext =
getReactApplicationContextIfActiveOrWarn(NAME, "onOptionSelected"); getReactApplicationContextIfActiveOrWarn();
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
reactApplicationContext reactApplicationContext

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

@ -754,8 +754,7 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
} }
private RCTDeviceEventEmitter getEventEmitter(String reason) { private RCTDeviceEventEmitter getEventEmitter(String reason) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(TAG, reason);
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
return getReactApplicationContext().getJSModule(RCTDeviceEventEmitter.class); return getReactApplicationContext().getJSModule(RCTDeviceEventEmitter.class);

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

@ -59,9 +59,7 @@ public final class WebSocketModule extends NativeWebSocketModuleSpec {
} }
private void sendEvent(String eventName, WritableMap params) { private void sendEvent(String eventName, WritableMap params) {
ReactApplicationContext reactApplicationContext = ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
getReactApplicationContextIfActiveOrWarn(
TAG, "sendAppStateChangeEvent: trying to update app state");
if (reactApplicationContext != null) { if (reactApplicationContext != null) {
reactApplicationContext reactApplicationContext