mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
ReactHostInterface & ReactHost refactoring (#38826)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38826 `ReactHostInterface` -> `ReactHost` `ReactHost` -> `ReactHostImpl` changelog: [internal] internal allow-large-files Reviewed By: cortinico Differential Revision: D48054716 fbshipit-source-id: b926877a0119f906ff794a496df4e30351b71423
This commit is contained in:
committed by
Facebook GitHub Bot
parent
75c1422286
commit
01b9b509cf
+2
-2
@@ -19,7 +19,7 @@ import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import com.facebook.react.interfaces.ReactHostInterface;
|
||||
import com.facebook.react.interfaces.ReactHost;
|
||||
import com.facebook.react.modules.core.PermissionListener;
|
||||
|
||||
/**
|
||||
@@ -87,7 +87,7 @@ public class ReactActivityDelegate {
|
||||
return ((ReactApplication) getPlainActivity().getApplication()).getReactNativeHost();
|
||||
}
|
||||
|
||||
public ReactHostInterface getReactHost() {
|
||||
public ReactHost getReactHost() {
|
||||
return ((ReactApplication) getPlainActivity().getApplication()).getReactHostInterface();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@
|
||||
package com.facebook.react
|
||||
|
||||
import com.facebook.react.common.annotations.UnstableReactNativeAPI
|
||||
import com.facebook.react.interfaces.ReactHostInterface
|
||||
import com.facebook.react.interfaces.ReactHost
|
||||
|
||||
@OptIn(UnstableReactNativeAPI::class)
|
||||
/** Interface that represents an instance of a React Native application */
|
||||
@@ -20,6 +20,6 @@ interface ReactApplication {
|
||||
* Get the default [ReactHostInterface] for this app. This method will be used by the new
|
||||
* architecture of react native
|
||||
*/
|
||||
val reactHostInterface: ReactHostInterface?
|
||||
val reactHostInterface: ReactHost?
|
||||
get() = null
|
||||
}
|
||||
|
||||
+5
-3
@@ -16,7 +16,7 @@ import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import com.facebook.react.devsupport.DoubleTapReloadRecognizer;
|
||||
import com.facebook.react.interfaces.ReactHostInterface;
|
||||
import com.facebook.react.interfaces.ReactHost;
|
||||
import com.facebook.react.interfaces.fabric.ReactSurface;
|
||||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
||||
|
||||
@@ -36,7 +36,9 @@ public class ReactDelegate {
|
||||
@Nullable private DoubleTapReloadRecognizer mDoubleTapReloadRecognizer;
|
||||
|
||||
@Nullable private ReactNativeHost mReactNativeHost;
|
||||
@Nullable private ReactHostInterface mReactHost;
|
||||
|
||||
@Nullable private ReactHost mReactHost;
|
||||
|
||||
@Nullable private ReactSurface mReactSurface;
|
||||
|
||||
private boolean mFabricEnabled = false;
|
||||
@@ -55,7 +57,7 @@ public class ReactDelegate {
|
||||
|
||||
public ReactDelegate(
|
||||
Activity activity,
|
||||
ReactHostInterface reactHost,
|
||||
ReactHost reactHost,
|
||||
@Nullable String appKey,
|
||||
@Nullable Bundle launchOptions) {
|
||||
mActivity = activity;
|
||||
|
||||
+3
-3
@@ -32,10 +32,10 @@ import javax.annotation.Nullable;
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
class BridgelessDevSupportManager extends DevSupportManagerBase {
|
||||
|
||||
private final ReactHost mReactHost;
|
||||
private final ReactHostImpl mReactHost;
|
||||
|
||||
public BridgelessDevSupportManager(
|
||||
ReactHost host, Context context, @Nullable String packagerPathForJSBundleName) {
|
||||
ReactHostImpl host, Context context, @Nullable String packagerPathForJSBundleName) {
|
||||
super(
|
||||
context.getApplicationContext(),
|
||||
createInstanceDevHelper(host),
|
||||
@@ -96,7 +96,7 @@ class BridgelessDevSupportManager extends DevSupportManagerBase {
|
||||
mReactHost.reload("BridgelessDevSupportManager.handleReloadJS()");
|
||||
}
|
||||
|
||||
private static ReactInstanceDevHelper createInstanceDevHelper(final ReactHost reactHost) {
|
||||
private static ReactInstanceDevHelper createInstanceDevHelper(final ReactHostImpl reactHost) {
|
||||
return new ReactInstanceDevHelper() {
|
||||
@Override
|
||||
public void onReloadWithJSDebugger(JavaJSExecutor.Factory proxyExecutorFactory) {
|
||||
|
||||
+4
-4
@@ -42,11 +42,11 @@ import javax.annotation.Nullable;
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
class BridgelessReactContext extends ReactApplicationContext implements EventDispatcherProvider {
|
||||
|
||||
private final ReactHost mReactHost;
|
||||
private final ReactHostImpl mReactHost;
|
||||
private final AtomicReference<String> mSourceURL = new AtomicReference<>();
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
|
||||
BridgelessReactContext(Context context, ReactHost host) {
|
||||
BridgelessReactContext(Context context, ReactHostImpl host) {
|
||||
super(context);
|
||||
mReactHost = host;
|
||||
}
|
||||
@@ -104,11 +104,11 @@ class BridgelessReactContext extends ReactApplicationContext implements EventDis
|
||||
}
|
||||
|
||||
private static class BridgelessJSModuleInvocationHandler implements InvocationHandler {
|
||||
private final ReactHost mReactHost;
|
||||
private final ReactHostImpl mReactHost;
|
||||
private final Class<? extends JavaScriptModule> mJSModuleInterface;
|
||||
|
||||
public BridgelessJSModuleInvocationHandler(
|
||||
ReactHost reactHost, Class<? extends JavaScriptModule> jsModuleInterface) {
|
||||
ReactHostImpl reactHost, Class<? extends JavaScriptModule> jsModuleInterface) {
|
||||
mReactHost = reactHost;
|
||||
mJSModuleInterface = jsModuleInterface;
|
||||
}
|
||||
|
||||
+7
-7
@@ -50,7 +50,7 @@ import com.facebook.react.devsupport.DisabledDevSupportManager;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.fabric.ComponentFactory;
|
||||
import com.facebook.react.fabric.FabricUIManager;
|
||||
import com.facebook.react.interfaces.ReactHostInterface;
|
||||
import com.facebook.react.interfaces.ReactHost;
|
||||
import com.facebook.react.interfaces.TaskInterface;
|
||||
import com.facebook.react.interfaces.exceptionmanager.ReactJsExceptionHandler;
|
||||
import com.facebook.react.interfaces.fabric.ReactSurface;
|
||||
@@ -83,7 +83,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
*/
|
||||
@ThreadSafe
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public class ReactHost implements ReactHostInterface {
|
||||
public class ReactHostImpl implements ReactHost {
|
||||
|
||||
// TODO T61403233 Make this configurable by product code
|
||||
private static final boolean DEV = ReactBuildConfig.DEBUG;
|
||||
@@ -125,7 +125,7 @@ public class ReactHost implements ReactHostInterface {
|
||||
private MemoryPressureListener mMemoryPressureListener;
|
||||
private @Nullable DefaultHardwareBackBtnHandler mDefaultHardwareBackBtnHandler;
|
||||
|
||||
public ReactHost(
|
||||
public ReactHostImpl(
|
||||
Context context,
|
||||
ReactHostDelegate delegate,
|
||||
ComponentFactory componentFactory,
|
||||
@@ -143,7 +143,7 @@ public class ReactHost implements ReactHostInterface {
|
||||
useDevSupport);
|
||||
}
|
||||
|
||||
public ReactHost(
|
||||
public ReactHostImpl(
|
||||
Context context,
|
||||
ReactHostDelegate delegate,
|
||||
ComponentFactory componentFactory,
|
||||
@@ -158,7 +158,7 @@ public class ReactHost implements ReactHostInterface {
|
||||
mBGExecutor = bgExecutor;
|
||||
mUIExecutor = uiExecutor;
|
||||
mReactJsExceptionHandler = reactJsExceptionHandler;
|
||||
mQueueThreadExceptionHandler = ReactHost.this::handleHostException;
|
||||
mQueueThreadExceptionHandler = ReactHostImpl.this::handleHostException;
|
||||
mMemoryPressureRouter = new MemoryPressureRouter(context);
|
||||
mMemoryPressureListener =
|
||||
level ->
|
||||
@@ -169,7 +169,7 @@ public class ReactHost implements ReactHostInterface {
|
||||
if (DEV) {
|
||||
mDevSupportManager =
|
||||
new BridgelessDevSupportManager(
|
||||
ReactHost.this, mContext, mReactHostDelegate.getJsMainModulePath());
|
||||
ReactHostImpl.this, mContext, mReactHostDelegate.getJsMainModulePath());
|
||||
} else {
|
||||
mDevSupportManager = new DisabledDevSupportManager();
|
||||
}
|
||||
@@ -799,7 +799,7 @@ public class ReactHost implements ReactHostInterface {
|
||||
return mBridgelessReactContextRef.getOrCreate(
|
||||
() -> {
|
||||
log(method, "Creating BridgelessReactContext");
|
||||
return new BridgelessReactContext(mContext, ReactHost.this);
|
||||
return new BridgelessReactContext(mContext, ReactHostImpl.this);
|
||||
});
|
||||
}
|
||||
|
||||
+7
-7
@@ -38,7 +38,7 @@ public class ReactSurfaceImpl implements ReactSurface {
|
||||
|
||||
private final AtomicReference<ReactSurfaceView> mSurfaceView = new AtomicReference<>(null);
|
||||
|
||||
private final AtomicReference<ReactHost> mReactHost = new AtomicReference<>(null);
|
||||
private final AtomicReference<ReactHostImpl> mReactHost = new AtomicReference<>(null);
|
||||
|
||||
private final SurfaceHandler mSurfaceHandler;
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ReactSurfaceImpl implements ReactSurface {
|
||||
*
|
||||
* @param host The ReactHost to attach.
|
||||
*/
|
||||
public void attach(ReactHost host) {
|
||||
public void attach(ReactHostImpl host) {
|
||||
if (!mReactHost.compareAndSet(null, host)) {
|
||||
throw new IllegalStateException("This surface is already attached to a host!");
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class ReactSurfaceImpl implements ReactSurface {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ReactHost getReactHost() {
|
||||
ReactHostImpl getReactHost() {
|
||||
// NULLSAFE_FIXME[Return Not Nullable]
|
||||
return mReactHost.get();
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class ReactSurfaceImpl implements ReactSurface {
|
||||
|
||||
@Override
|
||||
public TaskInterface<Void> prerender() {
|
||||
ReactHost host = mReactHost.get();
|
||||
ReactHostImpl host = mReactHost.get();
|
||||
if (host == null) {
|
||||
return Task.forError(
|
||||
new IllegalStateException(
|
||||
@@ -157,7 +157,7 @@ public class ReactSurfaceImpl implements ReactSurface {
|
||||
"Trying to call ReactSurface.start(), but view is not created."));
|
||||
}
|
||||
|
||||
ReactHost host = mReactHost.get();
|
||||
ReactHostImpl host = mReactHost.get();
|
||||
if (host == null) {
|
||||
return Task.forError(
|
||||
new IllegalStateException(
|
||||
@@ -168,7 +168,7 @@ public class ReactSurfaceImpl implements ReactSurface {
|
||||
|
||||
@Override
|
||||
public TaskInterface<Void> stop() {
|
||||
ReactHost host = mReactHost.get();
|
||||
ReactHostImpl host = mReactHost.get();
|
||||
if (host == null) {
|
||||
return Task.forError(
|
||||
new IllegalStateException(
|
||||
@@ -214,7 +214,7 @@ public class ReactSurfaceImpl implements ReactSurface {
|
||||
|
||||
/* package */ @Nullable
|
||||
EventDispatcher getEventDispatcher() {
|
||||
ReactHost host = mReactHost.get();
|
||||
ReactHostImpl host = mReactHost.get();
|
||||
if (host == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+1
-1
@@ -169,7 +169,7 @@ public class ReactSurfaceView extends ReactRootView {
|
||||
|
||||
@Override
|
||||
public void handleException(Throwable t) {
|
||||
ReactHost reactHost = mSurface.getReactHost();
|
||||
ReactHostImpl reactHost = mSurface.getReactHost();
|
||||
if (reactHost != null) {
|
||||
String errorMessage = Objects.toString(t.getMessage(), "");
|
||||
Exception e = new IllegalViewOperationException(errorMessage, this, t);
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ import com.facebook.react.bridge.JavaScriptExecutorFactory;
|
||||
|
||||
/**
|
||||
* Interface used by {@link DevSupportManager} for accessing some fields and methods of {@link
|
||||
* ReactInstanceManager} or {@link ReactHost} for the purpose of displaying and handling developer
|
||||
* menu options.
|
||||
* ReactInstanceManager} or {@link ReactHostImpl} for the purpose of displaying and handling
|
||||
* developer menu options.
|
||||
*/
|
||||
public interface ReactInstanceDevHelper {
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler
|
||||
* The implementation of this interface should be Thread Safe
|
||||
*/
|
||||
@UnstableReactNativeAPI
|
||||
interface ReactHostInterface {
|
||||
interface ReactHost {
|
||||
|
||||
/** The current [LifecycleState] for React Host */
|
||||
val lifecycleState: LifecycleState
|
||||
+2
-2
@@ -27,13 +27,13 @@ import org.robolectric.RobolectricTestRunner;
|
||||
public class BridgelessReactContextTest {
|
||||
|
||||
private Context mContext;
|
||||
private ReactHost mReactHost;
|
||||
private ReactHostImpl mReactHost;
|
||||
private BridgelessReactContext mBridgelessReactContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = Robolectric.buildActivity(Activity.class).create().get();
|
||||
mReactHost = Mockito.mock(ReactHost.class);
|
||||
mReactHost = Mockito.mock(ReactHostImpl.class);
|
||||
mBridgelessReactContext = new BridgelessReactContext(mContext, mReactHost);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -48,7 +48,7 @@ import org.robolectric.android.controller.ActivityController;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.LooperMode;
|
||||
|
||||
/** Tests {@linkcom.facebook.react.bridgeless.ReactHost} */
|
||||
/** Tests {@linkcom.facebook.react.bridgeless.ReactHostImpl} */
|
||||
@Ignore("Ignore for now as these tests fail in OSS only")
|
||||
@SuppressStaticInitializationFor("com.facebook.react.fabric.ComponentFactory")
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@@ -61,7 +61,7 @@ import org.robolectric.annotation.LooperMode;
|
||||
})
|
||||
@Config(shadows = ShadowSoLoader.class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
@PrepareForTest({ReactHost.class, ComponentFactory.class})
|
||||
@PrepareForTest({ReactHostImpl.class, ComponentFactory.class})
|
||||
public class ReactHostTest {
|
||||
|
||||
private ReactHostDelegate mReactHostDelegate;
|
||||
@@ -69,7 +69,7 @@ public class ReactHostTest {
|
||||
private MemoryPressureRouter mMemoryPressureRouter;
|
||||
private BridgelessDevSupportManager mDevSupportManager;
|
||||
private JSBundleLoader mJSBundleLoader;
|
||||
private ReactHost mReactHost;
|
||||
private ReactHostImpl mReactHost;
|
||||
private ActivityController<Activity> mActivityController;
|
||||
private ComponentFactory mComponentFactory;
|
||||
private BridgelessReactContext mBridgelessReactContext;
|
||||
@@ -98,7 +98,7 @@ public class ReactHostTest {
|
||||
doReturn(mJSBundleLoader).when(mReactHostDelegate).getJsBundleLoader();
|
||||
|
||||
mReactHost =
|
||||
new ReactHost(
|
||||
new ReactHostImpl(
|
||||
mActivityController.get().getApplication(),
|
||||
mReactHostDelegate,
|
||||
mComponentFactory,
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ public class ReactSurfaceTest {
|
||||
@Mock ReactHostDelegate mReactHostDelegate;
|
||||
@Mock EventDispatcher mEventDispatcher;
|
||||
|
||||
private ReactHost mReactHost;
|
||||
private ReactHostImpl mReactHost;
|
||||
private Context mContext;
|
||||
private ReactSurfaceImpl mReactSurface;
|
||||
private TestSurfaceHandler mSurfaceHandler;
|
||||
@@ -49,7 +49,7 @@ public class ReactSurfaceTest {
|
||||
|
||||
mContext = Robolectric.buildActivity(Activity.class).create().get();
|
||||
|
||||
mReactHost = spy(new ReactHost(mContext, mReactHostDelegate, null, false, null, false));
|
||||
mReactHost = spy(new ReactHostImpl(mContext, mReactHostDelegate, null, false, null, false));
|
||||
doAnswer(mockedStartSurface()).when(mReactHost).startSurface(any(ReactSurfaceImpl.class));
|
||||
doAnswer(mockedStartSurface()).when(mReactHost).prerenderSurface(any(ReactSurfaceImpl.class));
|
||||
doAnswer(mockedStopSurface()).when(mReactHost).stopSurface(any(ReactSurfaceImpl.class));
|
||||
|
||||
+5
-5
@@ -17,7 +17,7 @@ import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.TurboReactPackage;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridgeless.ReactHost;
|
||||
import com.facebook.react.bridgeless.ReactHostImpl;
|
||||
import com.facebook.react.common.annotations.UnstableReactNativeAPI;
|
||||
import com.facebook.react.common.assets.ReactFontManager;
|
||||
import com.facebook.react.common.mapbuffer.ReadableMapBuffer;
|
||||
@@ -27,7 +27,7 @@ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
|
||||
import com.facebook.react.defaults.DefaultReactNativeHost;
|
||||
import com.facebook.react.fabric.ComponentFactory;
|
||||
import com.facebook.react.flipper.ReactNativeFlipper;
|
||||
import com.facebook.react.interfaces.ReactHostInterface;
|
||||
import com.facebook.react.interfaces.ReactHost;
|
||||
import com.facebook.react.interfaces.exceptionmanager.ReactJsExceptionHandler;
|
||||
import com.facebook.react.module.model.ReactModuleInfo;
|
||||
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
||||
@@ -45,7 +45,7 @@ import java.util.Map;
|
||||
|
||||
public class RNTesterApplication extends Application implements ReactApplication {
|
||||
|
||||
private ReactHost mReactHost;
|
||||
private ReactHostImpl mReactHost;
|
||||
|
||||
private final ReactNativeHost mReactNativeHost =
|
||||
new DefaultReactNativeHost(this) {
|
||||
@@ -163,7 +163,7 @@ public class RNTesterApplication extends Application implements ReactApplication
|
||||
|
||||
@Override
|
||||
@UnstableReactNativeAPI
|
||||
public ReactHostInterface getReactHostInterface() {
|
||||
public ReactHost getReactHostInterface() {
|
||||
if (mReactHost == null) {
|
||||
// Create an instance of ReactHost to manager the instance of ReactInstance,
|
||||
// which is similar to how we use ReactNativeHost to manager instance of ReactInstanceManager
|
||||
@@ -175,7 +175,7 @@ public class RNTesterApplication extends Application implements ReactApplication
|
||||
ComponentFactory componentFactory = new ComponentFactory();
|
||||
DefaultComponentsRegistry.register(componentFactory);
|
||||
mReactHost =
|
||||
new ReactHost(
|
||||
new ReactHostImpl(
|
||||
this.getApplicationContext(),
|
||||
reactHostDelegate,
|
||||
componentFactory,
|
||||
|
||||
+3
-3
@@ -21,8 +21,8 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridgeless.BindingsInstaller;
|
||||
import com.facebook.react.bridgeless.JSCInstance;
|
||||
import com.facebook.react.bridgeless.JSEngineInstance;
|
||||
import com.facebook.react.bridgeless.ReactHost;
|
||||
import com.facebook.react.bridgeless.ReactHostDelegate;
|
||||
import com.facebook.react.bridgeless.ReactHostImpl;
|
||||
import com.facebook.react.bridgeless.hermes.HermesInstance;
|
||||
import com.facebook.react.common.annotations.UnstableReactNativeAPI;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
@@ -45,14 +45,14 @@ import java.util.Map;
|
||||
@UnstableReactNativeAPI
|
||||
public class RNTesterReactHostDelegate implements ReactHostDelegate {
|
||||
private final Context mContext;
|
||||
private @Nullable ReactHost mReactHost;
|
||||
private @Nullable ReactHostImpl mReactHost;
|
||||
private @Nullable List<ReactPackage> mReactPackages;
|
||||
|
||||
RNTesterReactHostDelegate(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public void setReactHost(ReactHost reactHost) {
|
||||
public void setReactHost(ReactHostImpl reactHost) {
|
||||
mReactHost = reactHost;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user