From 053776338ea44c31f3671cb4502853da0c88e55a Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Tue, 14 Nov 2017 05:43:55 -0800 Subject: [PATCH] Cleanup ReactInstanceManager Reviewed By: kathryngray Differential Revision: D6296922 fbshipit-source-id: 2fbf11f09a3c25ff3e7c222edc2e01b81e687943 --- .../facebook/react/ReactInstanceManager.java | 85 +++++++++---------- 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 0e06dd854916b9..6bb07f30f1d958 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -152,42 +152,12 @@ public interface ReactInstanceEventListener { // Identifies whether the instance manager destroy function is in process, // while true any spawned create thread should wait for proper clean up before initializing private volatile Boolean mHasStartedDestroying = false; - private final UIImplementationProvider mUIImplementationProvider; private final MemoryPressureRouter mMemoryPressureRouter; 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; - - private final ReactInstanceDevCommandsHandler mDevInterface = - new ReactInstanceDevCommandsHandler() { - - @Override - public void onReloadWithJSDebugger(JavaJSExecutor.Factory jsExecutorFactory) { - ReactInstanceManager.this.onReloadWithJSDebugger(jsExecutorFactory); - } - - @Override - public void onJSBundleLoadedFromServer() { - ReactInstanceManager.this.onJSBundleLoadedFromServer(); - } - - @Override - public void toggleElementInspector() { - ReactInstanceManager.this.toggleElementInspector(); - } - }; - - private final DefaultHardwareBackBtnHandler mBackBtnHandler = - new DefaultHardwareBackBtnHandler() { - @Override - public void invokeDefaultOnBackPressed() { - ReactInstanceManager.this.invokeDefaultOnBackPressed(); - } - }; private class ReactContextInitParams { private final JavaScriptExecutorFactory mJsExecutorFactory; @@ -251,34 +221,38 @@ public static ReactInstanceManagerBuilder builder() { mPackages = new ArrayList<>(); mInitFunctions = new ArrayList<>(); mUseDeveloperSupport = useDeveloperSupport; - mDevSupportManager = DevSupportManagerFactory.create( - applicationContext, - mDevInterface, - mJSMainModulePath, - useDeveloperSupport, - redBoxHandler, - devBundleDownloadListener, - minNumShakes); + mDevSupportManager = + DevSupportManagerFactory.create( + applicationContext, + createDevInterface(), + mJSMainModulePath, + useDeveloperSupport, + redBoxHandler, + devBundleDownloadListener, + minNumShakes); mBridgeIdleDebugListener = bridgeIdleDebugListener; mLifecycleState = initialLifecycleState; - mUIImplementationProvider = uiImplementationProvider; mMemoryPressureRouter = new MemoryPressureRouter(applicationContext); mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler; mLazyNativeModulesEnabled = lazyNativeModulesEnabled; - mLazyViewManagersEnabled = lazyViewManagersEnabled; mDelayViewManagerClassLoadsEnabled = delayViewManagerClassLoadsEnabled; - mMinTimeLeftInFrameForNonBatchedOperationMs = minTimeLeftInFrameForNonBatchedOperationMs; mUseSeparateUIBackgroundThread = useSeparateUIBackgroundThread; mMinNumShakes = minNumShakes; synchronized (mPackages) { - PrinterHolder.getPrinter().logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: Use Split Packages"); + PrinterHolder.getPrinter() + .logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: Use Split Packages"); mPackages.add( new CoreModulesPackage( this, - mBackBtnHandler, - mUIImplementationProvider, - mLazyViewManagersEnabled, - mMinTimeLeftInFrameForNonBatchedOperationMs)); + new DefaultHardwareBackBtnHandler() { + @Override + public void invokeDefaultOnBackPressed() { + ReactInstanceManager.this.invokeDefaultOnBackPressed(); + } + }, + uiImplementationProvider, + lazyViewManagersEnabled, + minTimeLeftInFrameForNonBatchedOperationMs)); if (mUseDeveloperSupport) { mPackages.add(new DebugCorePackage()); } @@ -292,6 +266,25 @@ public static ReactInstanceManagerBuilder builder() { } } + private ReactInstanceDevCommandsHandler createDevInterface() { + return new ReactInstanceDevCommandsHandler() { + @Override + public void onReloadWithJSDebugger(JavaJSExecutor.Factory jsExecutorFactory) { + ReactInstanceManager.this.onReloadWithJSDebugger(jsExecutorFactory); + } + + @Override + public void onJSBundleLoadedFromServer() { + ReactInstanceManager.this.onJSBundleLoadedFromServer(); + } + + @Override + public void toggleElementInspector() { + ReactInstanceManager.this.toggleElementInspector(); + } + }; + } + public DevSupportManager getDevSupportManager() { return mDevSupportManager; }