Introduce mobile config flag to load classes for View Managers
Reviewed By: kathryngray Differential Revision: D6148468 fbshipit-source-id: d0f919f63922dae4b0720f22fa70ab4a7f67b48a
This commit is contained in:
parent
55f75dfd65
commit
f0fb720eaa
|
@ -9,24 +9,22 @@
|
|||
|
||||
package com.facebook.react;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.facebook.react.bridge.ModuleSpec;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.module.annotations.ReactModuleList;
|
||||
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
||||
import com.facebook.react.modules.core.HeadlessJsTaskSupportModule;
|
||||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
import com.facebook.react.modules.core.ExceptionsManagerModule;
|
||||
import com.facebook.react.modules.core.HeadlessJsTaskSupportModule;
|
||||
import com.facebook.react.modules.core.Timing;
|
||||
import com.facebook.react.modules.debug.SourceCodeModule;
|
||||
import com.facebook.react.modules.deviceinfo.DeviceInfoModule;
|
||||
import com.facebook.react.modules.systeminfo.AndroidInfoModule;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Provider;
|
||||
|
||||
/**
|
||||
* Package defining core framework modules for basic JS interop.
|
||||
|
@ -61,54 +59,68 @@ import com.facebook.react.modules.systeminfo.AndroidInfoModule;
|
|||
List<ModuleSpec> moduleSpecList = new ArrayList<>();
|
||||
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(AndroidInfoModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new AndroidInfoModule();
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
AndroidInfoModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new AndroidInfoModule();
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(DeviceEventManagerModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new DeviceEventManagerModule(reactContext, mHardwareBackBtnHandler);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
DeviceEventManagerModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new DeviceEventManagerModule(reactContext, mHardwareBackBtnHandler);
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(ExceptionsManagerModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new ExceptionsManagerModule(mReactInstanceManager.getDevSupportManager());
|
||||
}
|
||||
}));
|
||||
moduleSpecList
|
||||
.add(new ModuleSpec(HeadlessJsTaskSupportModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new HeadlessJsTaskSupportModule(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
ExceptionsManagerModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new ExceptionsManagerModule(mReactInstanceManager.getDevSupportManager());
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(SourceCodeModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new SourceCodeModule(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
HeadlessJsTaskSupportModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new HeadlessJsTaskSupportModule(reactContext);
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(Timing.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new Timing(reactContext, mReactInstanceManager.getDevSupportManager());
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
SourceCodeModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new SourceCodeModule(reactContext);
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(DeviceInfoModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new DeviceInfoModule(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
Timing.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new Timing(reactContext, mReactInstanceManager.getDevSupportManager());
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
DeviceInfoModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new DeviceInfoModule(reactContext);
|
||||
}
|
||||
}));
|
||||
|
||||
return moduleSpecList;
|
||||
}
|
||||
|
|
|
@ -98,16 +98,16 @@ public class CompositeReactPackage extends ReactInstancePackage
|
|||
return new ArrayList<>(viewManagerMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public List<String> getViewManagerNames(ReactApplicationContext reactContext) {
|
||||
public List<String> getViewManagerNames(
|
||||
ReactApplicationContext reactContext, boolean loadClasses) {
|
||||
Set<String> uniqueNames = new HashSet<>();
|
||||
for (ReactPackage reactPackage : mChildReactPackages) {
|
||||
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
|
||||
List<String> names =
|
||||
((ViewManagerOnDemandReactPackage) reactPackage).getViewManagerNames(reactContext);
|
||||
((ViewManagerOnDemandReactPackage) reactPackage)
|
||||
.getViewManagerNames(reactContext, loadClasses);
|
||||
if (names != null) {
|
||||
uniqueNames.addAll(names);
|
||||
}
|
||||
|
@ -116,18 +116,17 @@ public class CompositeReactPackage extends ReactInstancePackage
|
|||
return new ArrayList<>(uniqueNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @Nullable ViewManager createViewManager(
|
||||
ReactApplicationContext reactContext, String viewManagerName) {
|
||||
ReactApplicationContext reactContext, String viewManagerName, boolean loadClasses) {
|
||||
ListIterator<ReactPackage> iterator = mChildReactPackages.listIterator(mChildReactPackages.size());
|
||||
while (iterator.hasPrevious()) {
|
||||
ReactPackage reactPackage = iterator.previous();
|
||||
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
|
||||
ViewManager viewManager =
|
||||
((ViewManagerOnDemandReactPackage) reactPackage).createViewManager(reactContext, viewManagerName);
|
||||
((ViewManagerOnDemandReactPackage) reactPackage)
|
||||
.createViewManager(reactContext, viewManagerName, loadClasses);
|
||||
if (viewManager != null) {
|
||||
return viewManager;
|
||||
}
|
||||
|
|
|
@ -93,86 +93,107 @@ import javax.inject.Provider;
|
|||
List<ModuleSpec> moduleSpecList = new ArrayList<>();
|
||||
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(AndroidInfoModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new AndroidInfoModule();
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
AndroidInfoModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new AndroidInfoModule();
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(AnimationsDebugModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new AnimationsDebugModule(
|
||||
reactContext,
|
||||
mReactInstanceManager.getDevSupportManager().getDevSettings());
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
AnimationsDebugModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new AnimationsDebugModule(
|
||||
reactContext, mReactInstanceManager.getDevSupportManager().getDevSettings());
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(DeviceEventManagerModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new DeviceEventManagerModule(reactContext, mHardwareBackBtnHandler);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
DeviceEventManagerModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new DeviceEventManagerModule(reactContext, mHardwareBackBtnHandler);
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(ExceptionsManagerModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new ExceptionsManagerModule(mReactInstanceManager.getDevSupportManager());
|
||||
}
|
||||
}));
|
||||
moduleSpecList
|
||||
.add(new ModuleSpec(HeadlessJsTaskSupportModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new HeadlessJsTaskSupportModule(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
ExceptionsManagerModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new ExceptionsManagerModule(mReactInstanceManager.getDevSupportManager());
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(SourceCodeModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new SourceCodeModule(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
HeadlessJsTaskSupportModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new HeadlessJsTaskSupportModule(reactContext);
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(Timing.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new Timing(reactContext, mReactInstanceManager.getDevSupportManager());
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
SourceCodeModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new SourceCodeModule(reactContext);
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(UIManagerModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return createUIManager(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
Timing.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new Timing(reactContext, mReactInstanceManager.getDevSupportManager());
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(DeviceInfoModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new DeviceInfoModule(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
UIManagerModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return createUIManager(reactContext);
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
DeviceInfoModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new DeviceInfoModule(reactContext);
|
||||
}
|
||||
}));
|
||||
|
||||
if (ReactBuildConfig.DEBUG) {
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(JSCHeapCapture.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new JSCHeapCapture(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
JSCHeapCapture.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new JSCHeapCapture(reactContext);
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(JSCSamplingProfiler.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new JSCSamplingProfiler(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
JSCSamplingProfiler.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new JSCSamplingProfiler(reactContext);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
return moduleSpecList;
|
||||
|
|
|
@ -9,11 +9,6 @@
|
|||
|
||||
package com.facebook.react;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.facebook.react.bridge.ModuleSpec;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
|
@ -21,6 +16,9 @@ import com.facebook.react.devsupport.JSCHeapCapture;
|
|||
import com.facebook.react.devsupport.JSCSamplingProfiler;
|
||||
import com.facebook.react.module.annotations.ReactModuleList;
|
||||
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Provider;
|
||||
|
||||
/**
|
||||
* Package defining core framework modules (e.g. UIManager). It should be used for modules that
|
||||
|
@ -42,19 +40,23 @@ import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|||
public List<ModuleSpec> getNativeModules(final ReactApplicationContext reactContext) {
|
||||
List<ModuleSpec> moduleSpecList = new ArrayList<>();
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(JSCHeapCapture.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new JSCHeapCapture(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
JSCHeapCapture.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new JSCHeapCapture(reactContext);
|
||||
}
|
||||
}));
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(JSCSamplingProfiler.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new JSCSamplingProfiler(reactContext);
|
||||
}
|
||||
}));
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
JSCSamplingProfiler.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new JSCSamplingProfiler(reactContext);
|
||||
}
|
||||
}));
|
||||
return moduleSpecList;
|
||||
}
|
||||
|
||||
|
|
|
@ -112,27 +112,27 @@ import javax.annotation.Nullable;
|
|||
public class ReactInstanceManager {
|
||||
|
||||
private static final String TAG = ReactInstanceManager.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Listener interface for react instance events.
|
||||
*/
|
||||
public interface ReactInstanceEventListener {
|
||||
|
||||
/**
|
||||
* Called when the react context is initialized (all modules registered). Always called on the
|
||||
* UI thread.
|
||||
*/
|
||||
void onReactContextInitialized(ReactContext context);
|
||||
}
|
||||
|
||||
private final List<ReactRootView> mAttachedRootViews = Collections.synchronizedList(
|
||||
new ArrayList<ReactRootView>());
|
||||
|
||||
private volatile LifecycleState mLifecycleState;
|
||||
|
||||
private @Nullable @ThreadConfined(UI) ReactContextInitParams mPendingReactContextInitParams;
|
||||
private volatile @Nullable Thread mCreateReactContextThread;
|
||||
|
||||
/* accessed from any thread */
|
||||
private final JavaScriptExecutorFactory mJavaScriptExecutorFactory;
|
||||
|
||||
private final @Nullable JSBundleLoader mBundleLoader;
|
||||
private final @Nullable String mJSMainModulePath; /* path to JS bundle root on packager server */
|
||||
private final List<ReactPackage> mPackages;
|
||||
|
@ -157,6 +157,7 @@ public class ReactInstanceManager {
|
|||
private final @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
|
||||
private final boolean mLazyNativeModulesEnabled;
|
||||
private final boolean mLazyViewManagersEnabled;
|
||||
private final boolean mDelayViewManagerClassLoadsEnabled;
|
||||
private final boolean mUseSeparateUIBackgroundThread;
|
||||
private final int mMinNumShakes;
|
||||
private final int mMinTimeLeftInFrameForNonBatchedOperationMs;
|
||||
|
@ -231,6 +232,7 @@ public class ReactInstanceManager {
|
|||
@Nullable RedBoxHandler redBoxHandler,
|
||||
boolean lazyNativeModulesEnabled,
|
||||
boolean lazyViewManagersEnabled,
|
||||
boolean delayViewManagerClassLoadsEnabled,
|
||||
@Nullable DevBundleDownloadListener devBundleDownloadListener,
|
||||
boolean useSeparateUIBackgroundThread,
|
||||
int minNumShakes,
|
||||
|
@ -266,18 +268,19 @@ public class ReactInstanceManager {
|
|||
mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
|
||||
mLazyNativeModulesEnabled = lazyNativeModulesEnabled;
|
||||
mLazyViewManagersEnabled = lazyViewManagersEnabled;
|
||||
mDelayViewManagerClassLoadsEnabled = delayViewManagerClassLoadsEnabled;
|
||||
mMinTimeLeftInFrameForNonBatchedOperationMs = minTimeLeftInFrameForNonBatchedOperationMs;
|
||||
mUseSeparateUIBackgroundThread = useSeparateUIBackgroundThread;
|
||||
mMinNumShakes = minNumShakes;
|
||||
synchronized (mPackages) {
|
||||
if (!splitPackagesEnabled) {
|
||||
CoreModulesPackage coreModulesPackage =
|
||||
new CoreModulesPackage(
|
||||
this,
|
||||
mBackBtnHandler,
|
||||
mUIImplementationProvider,
|
||||
mLazyViewManagersEnabled,
|
||||
mMinTimeLeftInFrameForNonBatchedOperationMs);
|
||||
new CoreModulesPackage(
|
||||
this,
|
||||
mBackBtnHandler,
|
||||
mUIImplementationProvider,
|
||||
mLazyViewManagersEnabled,
|
||||
mMinTimeLeftInFrameForNonBatchedOperationMs);
|
||||
mPackages.add(coreModulesPackage);
|
||||
} else {
|
||||
PrinterHolder.getPrinter().logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: Use Split Packages");
|
||||
|
@ -286,11 +289,12 @@ public class ReactInstanceManager {
|
|||
mPackages.add(new DebugCorePackage());
|
||||
}
|
||||
if (!useOnlyDefaultPackages) {
|
||||
mPackages.add(new ReactNativeCorePackage(
|
||||
this,
|
||||
mUIImplementationProvider,
|
||||
mLazyViewManagersEnabled,
|
||||
mMinTimeLeftInFrameForNonBatchedOperationMs));
|
||||
mPackages.add(
|
||||
new ReactNativeCorePackage(
|
||||
this,
|
||||
mUIImplementationProvider,
|
||||
mLazyViewManagersEnabled,
|
||||
mMinTimeLeftInFrameForNonBatchedOperationMs));
|
||||
}
|
||||
}
|
||||
mPackages.addAll(packages);
|
||||
|
@ -793,8 +797,8 @@ public class ReactInstanceManager {
|
|||
for (ReactPackage reactPackage : mPackages) {
|
||||
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
|
||||
ViewManager viewManager =
|
||||
((ViewManagerOnDemandReactPackage) reactPackage)
|
||||
.createViewManager(context, viewManagerName);
|
||||
((ViewManagerOnDemandReactPackage) reactPackage)
|
||||
.createViewManager(context, viewManagerName, !mDelayViewManagerClassLoadsEnabled);
|
||||
if (viewManager != null) {
|
||||
return viewManager;
|
||||
}
|
||||
|
@ -812,7 +816,8 @@ public class ReactInstanceManager {
|
|||
for (ReactPackage reactPackage : mPackages) {
|
||||
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
|
||||
List<String> names =
|
||||
((ViewManagerOnDemandReactPackage) reactPackage).getViewManagerNames(context);
|
||||
((ViewManagerOnDemandReactPackage) reactPackage)
|
||||
.getViewManagerNames(context, !mDelayViewManagerClassLoadsEnabled);
|
||||
if (names != null) {
|
||||
uniqueNames.addAll(names);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import static com.facebook.react.modules.systeminfo.AndroidInfoHelpers.getFriend
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.os.Build;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.JSBundleLoader;
|
||||
import com.facebook.react.bridge.JSCJavaScriptExecutorFactory;
|
||||
|
@ -44,6 +43,7 @@ public class ReactInstanceManagerBuilder {
|
|||
private @Nullable RedBoxHandler mRedBoxHandler;
|
||||
private boolean mLazyNativeModulesEnabled;
|
||||
private boolean mLazyViewManagersEnabled;
|
||||
private boolean mDelayViewManagerClassLoadsEnabled;
|
||||
private @Nullable DevBundleDownloadListener mDevBundleDownloadListener;
|
||||
private @Nullable JavaScriptExecutorFactory mJavaScriptExecutorFactory;
|
||||
private boolean mUseSeparateUIBackgroundThread;
|
||||
|
@ -204,6 +204,12 @@ public class ReactInstanceManagerBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ReactInstanceManagerBuilder setDelayViewManagerClassLoadsEnabled(
|
||||
boolean delayViewManagerClassLoadsEnabled) {
|
||||
mDelayViewManagerClassLoadsEnabled = delayViewManagerClassLoadsEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReactInstanceManagerBuilder setDevBundleDownloadListener(
|
||||
@Nullable DevBundleDownloadListener listener) {
|
||||
mDevBundleDownloadListener = listener;
|
||||
|
@ -290,6 +296,7 @@ public class ReactInstanceManagerBuilder {
|
|||
mRedBoxHandler,
|
||||
mLazyNativeModulesEnabled,
|
||||
mLazyViewManagersEnabled,
|
||||
mDelayViewManagerClassLoadsEnabled,
|
||||
mDevBundleDownloadListener,
|
||||
mUseSeparateUIBackgroundThread,
|
||||
mMinNumShakes,
|
||||
|
|
|
@ -22,7 +22,7 @@ import com.facebook.react.uimanager.UIImplementationProvider;
|
|||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Provider;
|
||||
|
@ -57,17 +57,15 @@ public class ReactNativeCorePackage extends LazyReactPackage {
|
|||
|
||||
@Override
|
||||
public List<ModuleSpec> getNativeModules(final ReactApplicationContext reactContext) {
|
||||
List<ModuleSpec> moduleSpecList = new ArrayList<>();
|
||||
|
||||
moduleSpecList.add(
|
||||
new ModuleSpec(UIManagerModule.class, new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return createUIManager(reactContext);
|
||||
}
|
||||
}));
|
||||
|
||||
return moduleSpecList;
|
||||
return Collections.singletonList(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
UIManagerModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return createUIManager(reactContext);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,11 +18,17 @@ public interface ViewManagerOnDemandReactPackage {
|
|||
/**
|
||||
* Provides a list of names of ViewManagers with which these modules can be accessed from JS.
|
||||
* Typically, this is ViewManager.getName().
|
||||
*
|
||||
* @param loadClasses defines if View Managers classes should be loaded or be avoided.
|
||||
*/
|
||||
List<String> getViewManagerNames(ReactApplicationContext reactContext);
|
||||
List<String> getViewManagerNames(ReactApplicationContext reactContext, boolean loadClasses);
|
||||
/**
|
||||
* Creates and returns a ViewManager with a specific name {@param viewManagerName}. It's up to
|
||||
* an implementing package how to interpret the name.
|
||||
* Creates and returns a ViewManager with a specific name {@param viewManagerName}. It's up to an
|
||||
* implementing package how to interpret the name.
|
||||
*
|
||||
* @param loadClasses defines if View Managers classes should be loaded or be avoided.
|
||||
*/
|
||||
@Nullable ViewManager createViewManager(ReactApplicationContext reactContext, String viewManagerName);
|
||||
@Nullable
|
||||
ViewManager createViewManager(
|
||||
ReactApplicationContext reactContext, String viewManagerName, boolean loadClasses);
|
||||
}
|
||||
|
|
|
@ -9,13 +9,11 @@
|
|||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.react.common.build.ReactBuildConfig;
|
||||
import java.lang.reflect.Constructor;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Provider;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import com.facebook.react.common.build.ReactBuildConfig;
|
||||
|
||||
/**
|
||||
* A specification for a native module. This exists so that we don't have to pay the cost
|
||||
* for creation until/if the module is used.
|
||||
|
@ -27,7 +25,7 @@ public class ModuleSpec {
|
|||
private static final Class[] EMPTY_SIGNATURE = {};
|
||||
private static final Class[] CONTEXT_SIGNATURE = { ReactApplicationContext.class };
|
||||
|
||||
private final Class<? extends NativeModule> mType;
|
||||
private final @Nullable Class<? extends NativeModule> mType;
|
||||
private final Provider<? extends NativeModule> mProvider;
|
||||
|
||||
/**
|
||||
|
@ -64,12 +62,22 @@ public class ModuleSpec {
|
|||
});
|
||||
}
|
||||
|
||||
public ModuleSpec(Class<? extends NativeModule> type, Provider<? extends NativeModule> provider) {
|
||||
public static ModuleSpec viewManagerSpec(Provider<? extends NativeModule> provider) {
|
||||
return new ModuleSpec(null, provider);
|
||||
}
|
||||
|
||||
public static ModuleSpec nativeModuleSpec(
|
||||
Class<? extends NativeModule> type, Provider<? extends NativeModule> provider) {
|
||||
return new ModuleSpec(type, provider);
|
||||
}
|
||||
|
||||
private ModuleSpec(
|
||||
@Nullable Class<? extends NativeModule> type, Provider<? extends NativeModule> provider) {
|
||||
mType = type;
|
||||
mProvider = provider;
|
||||
}
|
||||
|
||||
public Class<? extends NativeModule> getType() {
|
||||
public @Nullable Class<? extends NativeModule> getType() {
|
||||
return mType;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
@Override
|
||||
public List<ModuleSpec> getNativeModules(final ReactApplicationContext context) {
|
||||
return Arrays.asList(
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
AccessibilityInfoModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -108,7 +108,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new AccessibilityInfoModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
AppStateModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -116,7 +116,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new AppStateModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
BlobModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -124,7 +124,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new BlobModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
AsyncStorageModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -132,7 +132,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new AsyncStorageModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
CameraRollManager.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -140,7 +140,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new CameraRollManager(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
ClipboardModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -148,7 +148,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new ClipboardModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
DatePickerDialogModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -156,7 +156,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new DatePickerDialogModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
DialogModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -164,7 +164,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new DialogModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
FrescoModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -173,7 +173,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
context, true, mConfig != null ? mConfig.getFrescoConfig() : null);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
I18nManagerModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -181,7 +181,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new I18nManagerModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
ImageEditingManager.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -189,7 +189,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new ImageEditingManager(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
ImageLoaderModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -197,7 +197,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new ImageLoaderModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
ImageStoreManager.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -205,7 +205,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new ImageStoreManager(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
IntentModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -213,7 +213,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new IntentModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
LocationModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -221,7 +221,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new LocationModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
NativeAnimatedModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -229,7 +229,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new NativeAnimatedModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
NetworkingModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -237,7 +237,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new NetworkingModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
NetInfoModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -245,7 +245,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new NetInfoModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
PermissionsModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -253,7 +253,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new PermissionsModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
ShareModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -261,7 +261,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new ShareModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
StatusBarModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -269,7 +269,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new StatusBarModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
TimePickerDialogModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -277,7 +277,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new TimePickerDialogModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
ToastModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -285,7 +285,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new ToastModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
VibrationModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
@ -293,7 +293,7 @@ public class MainReactPackage extends LazyReactPackage {
|
|||
return new VibrationModule(context);
|
||||
}
|
||||
}),
|
||||
new ModuleSpec(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
WebSocketModule.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue