Part 2: Make CatalystInstanceImpl.getNativeModule Nullable

Summary:
This is the codemod portion of the parent diff.

I modified all call-sites to `ReactContext.getNativeModule` to do a null check on the returned NativeModule.

Changelog:
[Android][Fixed] - Check if NativeModules returned from CatalystInstanceImpl.getNativeModule are null before using them.

Reviewed By: JoshuaGross

Differential Revision: D21272028

fbshipit-source-id: 6bd16c6bf30605f2dfdf4c481352063712965342
This commit is contained in:
Ramanpreet Nara
2020-04-28 12:14:48 -07:00
committed by Facebook GitHub Bot
parent 1cef72af04
commit 9263eb5d38
20 changed files with 153 additions and 72 deletions
@@ -470,7 +470,9 @@ public class ReactInstanceManager {
} else {
DeviceEventManagerModule deviceEventManagerModule =
reactContext.getNativeModule(DeviceEventManagerModule.class);
deviceEventManagerModule.emitHardwareBackPressed();
if (deviceEventManagerModule != null) {
deviceEventManagerModule.emitHardwareBackPressed();
}
}
}
@@ -497,7 +499,9 @@ public class ReactInstanceManager {
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))) {
DeviceEventManagerModule deviceEventManagerModule =
currentContext.getNativeModule(DeviceEventManagerModule.class);
deviceEventManagerModule.emitNewIntentReceived(uri);
if (deviceEventManagerModule != null) {
deviceEventManagerModule.emitNewIntentReceived(uri);
}
}
currentContext.onNewIntent(mCurrentActivity, intent);
}
@@ -775,9 +779,12 @@ public class ReactInstanceManager {
ReactContext currentReactContext = getCurrentReactContext();
if (currentReactContext != null) {
currentReactContext
.getNativeModule(AppearanceModule.class)
.onConfigurationChanged(updatedContext);
AppearanceModule appearanceModule =
currentReactContext.getNativeModule(AppearanceModule.class);
if (appearanceModule != null) {
appearanceModule.onConfigurationChanged(updatedContext);
}
}
}