mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-03 22:48:25 +08:00
android: add ReactInstancePackage abstract class to pass down ReactInstanceManager to create modules
Summary: At times, ReactPackage needs to get information from the ReactInstanceManager, e.g. to get the DevSupportManager for debugging purpose. This allows passing down the instance manager to create the native modules, in addition to just ReactApplicationContext. It is then up to the Package to use it or not. To use this, you must make your package class extends ReactInstancePackage, instead of just implementing ReactPackage interface. Reviewed By: mmmulani Differential Revision: D4641997 fbshipit-source-id: 497c4408a7d2b773c49f08bff7c1bf8f9d372edb
This commit is contained in:
committed by
Facebook Github Bot
parent
4c79df9970
commit
7acf74122d
@@ -26,6 +26,7 @@ import com.facebook.react.module.model.ReactModuleInfo;
|
||||
public class NativeModuleRegistryBuilder {
|
||||
|
||||
private final ReactApplicationContext mReactApplicationContext;
|
||||
private final ReactInstanceManager mReactInstanceManager;
|
||||
private final boolean mLazyNativeModulesEnabled;
|
||||
|
||||
private final Map<Class<? extends NativeModule>, ModuleHolder> mModules = new HashMap<>();
|
||||
@@ -33,8 +34,10 @@ public class NativeModuleRegistryBuilder {
|
||||
|
||||
public NativeModuleRegistryBuilder(
|
||||
ReactApplicationContext reactApplicationContext,
|
||||
ReactInstanceManager reactInstanceManager,
|
||||
boolean lazyNativeModulesEnabled) {
|
||||
mReactApplicationContext = reactApplicationContext;
|
||||
mReactInstanceManager = reactInstanceManager;
|
||||
mLazyNativeModulesEnabled = lazyNativeModulesEnabled;
|
||||
}
|
||||
|
||||
@@ -94,7 +97,16 @@ public class NativeModuleRegistryBuilder {
|
||||
ReactConstants.TAG,
|
||||
reactPackage.getClass().getSimpleName() +
|
||||
" is not a LazyReactPackage, falling back to old version.");
|
||||
for (NativeModule nativeModule : reactPackage.createNativeModules(mReactApplicationContext)) {
|
||||
List<NativeModule> nativeModules;
|
||||
if (reactPackage instanceof ReactInstancePackage) {
|
||||
ReactInstancePackage reactInstancePackage = (ReactInstancePackage) reactPackage;
|
||||
nativeModules = reactInstancePackage.createNativeModules(
|
||||
mReactApplicationContext,
|
||||
mReactInstanceManager);
|
||||
} else {
|
||||
nativeModules = reactPackage.createNativeModules(mReactApplicationContext);
|
||||
}
|
||||
for (NativeModule nativeModule : nativeModules) {
|
||||
addNativeModule(nativeModule);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user