Begin inverting dependency between new+old bridge

Reviewed By: mhorowitz

Differential Revision: D3306510

fbshipit-source-id: 312a498a4461e980f1f749fe7858a13be14dfa2f
This commit is contained in:
Chris Hopman 2016-06-07 13:25:20 -07:00 committed by Facebook Github Bot 0
parent 26a5b033f8
commit 5b871ad9d7
4 changed files with 47 additions and 85 deletions

View File

@ -1,11 +1,7 @@
include_defs('//ReactAndroid/DEFS')
XREACT_SRCS = [
'XReactInstanceManager.java',
'XReactInstanceManagerImpl.java',
]
DEPS = [
react_native_target('java/com/facebook/react/cxxbridge:bridge'),
react_native_target('java/com/facebook/react/bridge:bridge'),
react_native_target('java/com/facebook/react/common:common'),
react_native_target('java/com/facebook/react/devsupport:devsupport'),
@ -23,25 +19,13 @@ DEPS = [
android_library(
name = 'react',
srcs = glob(['*.java'], excludes=XREACT_SRCS),
srcs = glob(['*.java']),
deps = DEPS,
visibility = [
'PUBLIC',
],
)
android_library(
name = 'xreact',
srcs = XREACT_SRCS,
deps = DEPS + [
':react',
react_native_target('java/com/facebook/react/cxxbridge:bridge'),
],
visibility = [
'PUBLIC',
],
)
project_config(
src_target = ':react',
)

View File

@ -195,6 +195,7 @@ public abstract class ReactInstanceManager {
protected @Nullable Activity mCurrentActivity;
protected @Nullable DefaultHardwareBackBtnHandler mDefaultHardwareBackBtnHandler;
protected @Nullable RedBoxHandler mRedBoxHandler;
protected boolean mUseNewBridge;
protected Builder() {
}
@ -309,6 +310,11 @@ public abstract class ReactInstanceManager {
return this;
}
public Builder setUseNewBridge() {
mUseNewBridge = true;
return this;
}
/**
* Instantiates a new {@link ReactInstanceManagerImpl}.
* Before calling {@code build}, the following must be called:
@ -333,22 +339,41 @@ public abstract class ReactInstanceManager {
mUIImplementationProvider = new UIImplementationProvider();
}
return new ReactInstanceManagerImpl(
Assertions.assertNotNull(
mApplication,
"Application property has not been set with this builder"),
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
mJSBundleFile,
mJSMainModuleName,
mPackages,
mUseDeveloperSupport,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
mNativeModuleCallExceptionHandler,
mJSCConfig,
mRedBoxHandler);
if (mUseNewBridge) {
return new XReactInstanceManagerImpl(
Assertions.assertNotNull(
mApplication,
"Application property has not been set with this builder"),
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
mJSBundleFile,
mJSMainModuleName,
mPackages,
mUseDeveloperSupport,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
mNativeModuleCallExceptionHandler,
mJSCConfig,
mRedBoxHandler);
} else {
return new ReactInstanceManagerImpl(
Assertions.assertNotNull(
mApplication,
"Application property has not been set with this builder"),
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
mJSBundleFile,
mJSMainModuleName,
mPackages,
mUseDeveloperSupport,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
mNativeModuleCallExceptionHandler,
mJSCConfig,
mRedBoxHandler);
}
}
}
}

View File

@ -14,56 +14,9 @@ import com.facebook.react.uimanager.UIImplementationProvider;
public abstract class XReactInstanceManager {
/**
* Creates a builder that is capable of creating an instance of {@link XReactInstanceManagerImpl}.
* Creates a builder that is defaulted to using the new bridge.
*/
public static Builder builder() {
return new Builder();
}
/**
* Builder class for {@link XReactInstanceManagerImpl}
*/
public static class Builder extends ReactInstanceManager.Builder {
/**
* Instantiates a new {@link ReactInstanceManagerImpl}.
* Before calling {@code build}, the following must be called:
* <ul>
* <li> {@link #setApplication}
* <li> {@link #setCurrentActivity} if the activity has already resumed
* <li> {@link #setDefaultHardwareBackBtnHandler} if the activity has already resumed
* <li> {@link #setJSBundleFile} or {@link #setJSMainModuleName}
* </ul>
*/
public ReactInstanceManager build() {
Assertions.assertCondition(
mUseDeveloperSupport || mJSBundleFile != null,
"JS Bundle File has to be provided when dev support is disabled");
Assertions.assertCondition(
mJSMainModuleName != null || mJSBundleFile != null,
"Either MainModuleName or JS Bundle File needs to be provided");
if (mUIImplementationProvider == null) {
// create default UIImplementationProvider if the provided one is null.
mUIImplementationProvider = new UIImplementationProvider();
}
return new XReactInstanceManagerImpl(
Assertions.assertNotNull(
mApplication,
"Application property has not been set with this builder"),
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
mJSBundleFile,
mJSMainModuleName,
mPackages,
mUseDeveloperSupport,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
mNativeModuleCallExceptionHandler,
mJSCConfig,
mRedBoxHandler);
}
public static ReactInstanceManager.Builder builder() {
return new ReactInstanceManager.Builder().setUseNewBridge();
}
}

View File

@ -9,8 +9,8 @@ android_library(
],
proguard_config = 'bridge.pro',
deps = [
'//libraries/fbcore/src/main/java/com/facebook/common/logging:logging',
react_native_dep('java/com/facebook/systrace:systrace'),
react_native_dep('libraries/fbcore/src/main/java/com/facebook/common/logging:logging'),
react_native_dep('libraries/soloader/java/com/facebook/soloader:soloader'),
# TODO mhorowitz:
# java/com/facebook/catalyst/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/bridge/