Give ReactContextBaseJavaModule a 0 arg ctor

Summary:
We need to make our ExceptionsManagers into TurboModules. To do so, we need to first make them type-safe. This requires extending the base class code-generated from the NativeModule JavaScript spec. That base class extends `ReactContextBaseJavaModule`, which requires `ReactApplicationContext` to instantiate. Unfortunatley, our ExceptionsManagers need to be created before the `ReactInstanceManager`. This means that the `ReactApplicationContext` isn't available by the time they're created.

In this diff, I make the `ReactContextBaseJavaModule` have a 0 argument constructor that simply sets its ReactApplicationContext to null. This will allow us to eventually migrate our ExceptionsManagers to the TurboModule system.

Changelog:
[Android][Added] - Give ReactContextBaseJavaModule a 0 arg ctor

Reviewed By: mdvacca

Differential Revision: D18717908

fbshipit-source-id: 203ffc49f2ec0b32a809402801795879d3b3a64b
This commit is contained in:
Ramanpreet Nara 2019-11-27 10:36:17 -08:00 коммит произвёл Facebook Github Bot
Родитель 178f126d83
Коммит e69be0ae55
1 изменённых файлов: 9 добавлений и 2 удалений

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

@ -13,6 +13,7 @@ import android.app.Activity;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.ThreadConfined;
import com.facebook.react.common.build.ReactBuildConfig;
@ -21,7 +22,11 @@ import com.facebook.react.common.build.ReactBuildConfig;
*/
public abstract class ReactContextBaseJavaModule extends BaseJavaModule {
private final ReactApplicationContext mReactApplicationContext;
private final @Nullable ReactApplicationContext mReactApplicationContext;
public ReactContextBaseJavaModule() {
mReactApplicationContext = null;
}
public ReactContextBaseJavaModule(@NonNull ReactApplicationContext reactContext) {
mReactApplicationContext = reactContext;
@ -29,7 +34,9 @@ public abstract class ReactContextBaseJavaModule extends BaseJavaModule {
/** Subclasses can use this method to access catalyst context passed as a constructor. */
protected final ReactApplicationContext getReactApplicationContext() {
return mReactApplicationContext;
return Assertions.assertNotNull(
mReactApplicationContext,
"Tried to get ReactApplicationContext even though NativeModule wasn't instantiated with one");
}
/**