Skip to content

Commit

Permalink
ReactHostInterface & ReactHost refactoring (#38826)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #38826

`ReactHostInterface` -> `ReactHost`
`ReactHost` -> `ReactHostImpl`

changelog: [internal] internal

allow-large-files

Reviewed By: cortinico

Differential Revision: D48054716

fbshipit-source-id: b926877a0119f906ff794a496df4e30351b71423
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Aug 11, 2023
1 parent 75c1422 commit 01b9b50
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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;

/**
Expand Down Expand Up @@ -87,7 +87,7 @@ protected ReactNativeHost getReactNativeHost() {
return ((ReactApplication) getPlainActivity().getApplication()).getReactNativeHost();
}

public ReactHostInterface getReactHost() {
public ReactHost getReactHost() {
return ((ReactApplication) getPlainActivity().getApplication()).getReactHostInterface();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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;

Expand All @@ -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;
Expand All @@ -55,7 +57,7 @@ public ReactDelegate(

public ReactDelegate(
Activity activity,
ReactHostInterface reactHost,
ReactHost reactHost,
@Nullable String appKey,
@Nullable Bundle launchOptions) {
mActivity = activity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
@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),
Expand Down Expand Up @@ -96,7 +96,7 @@ public void handleReloadJS() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
@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;
}
Expand Down Expand Up @@ -104,11 +104,11 @@ public void registerSegment(int segmentId, String path, Callback callback) {
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
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;
Expand Down Expand Up @@ -83,7 +83,7 @@
*/
@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;
Expand Down Expand Up @@ -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,
Expand All @@ -143,7 +143,7 @@ public ReactHost(
useDevSupport);
}

public ReactHost(
public ReactHostImpl(
Context context,
ReactHostDelegate delegate,
ComponentFactory componentFactory,
Expand All @@ -158,7 +158,7 @@ public ReactHost(
mBGExecutor = bgExecutor;
mUIExecutor = uiExecutor;
mReactJsExceptionHandler = reactJsExceptionHandler;
mQueueThreadExceptionHandler = ReactHost.this::handleHostException;
mQueueThreadExceptionHandler = ReactHostImpl.this::handleHostException;
mMemoryPressureRouter = new MemoryPressureRouter(context);
mMemoryPressureListener =
level ->
Expand All @@ -169,7 +169,7 @@ public ReactHost(
if (DEV) {
mDevSupportManager =
new BridgelessDevSupportManager(
ReactHost.this, mContext, mReactHostDelegate.getJsMainModulePath());
ReactHostImpl.this, mContext, mReactHostDelegate.getJsMainModulePath());
} else {
mDevSupportManager = new DisabledDevSupportManager();
}
Expand Down Expand Up @@ -799,7 +799,7 @@ private BridgelessReactContext getOrCreateReactContext() {
return mBridgelessReactContextRef.getOrCreate(
() -> {
log(method, "Creating BridgelessReactContext");
return new BridgelessReactContext(mContext, ReactHost.this);
return new BridgelessReactContext(mContext, ReactHostImpl.this);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -93,7 +93,7 @@ public ReactSurfaceImpl(Context context, String moduleName, @Nullable Bundle ini
*
* @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!");
}
Expand All @@ -118,7 +118,7 @@ public void updateInitProps(Bundle newProps) {
}

@VisibleForTesting
ReactHost getReactHost() {
ReactHostImpl getReactHost() {
// NULLSAFE_FIXME[Return Not Nullable]
return mReactHost.get();
}
Expand All @@ -140,7 +140,7 @@ public SurfaceHandler getSurfaceHandler() {

@Override
public TaskInterface<Void> prerender() {
ReactHost host = mReactHost.get();
ReactHostImpl host = mReactHost.get();
if (host == null) {
return Task.forError(
new IllegalStateException(
Expand All @@ -157,7 +157,7 @@ public TaskInterface<Void> start() {
"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(
Expand All @@ -168,7 +168,7 @@ public TaskInterface<Void> start() {

@Override
public TaskInterface<Void> stop() {
ReactHost host = mReactHost.get();
ReactHostImpl host = mReactHost.get();
if (host == null) {
return Task.forError(
new IllegalStateException(
Expand Down Expand Up @@ -214,7 +214,7 @@ public void clear() {

/* package */ @Nullable
EventDispatcher getEventDispatcher() {
ReactHost host = mReactHost.get();
ReactHostImpl host = mReactHost.get();
if (host == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void onChildEndedNativeGesture(View childView, MotionEvent ev) {

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

/**
* 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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
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)
Expand All @@ -61,15 +61,15 @@
})
@Config(shadows = ShadowSoLoader.class)
@LooperMode(LooperMode.Mode.PAUSED)
@PrepareForTest({ReactHost.class, ComponentFactory.class})
@PrepareForTest({ReactHostImpl.class, ComponentFactory.class})
public class ReactHostTest {

private ReactHostDelegate mReactHostDelegate;
private ReactInstance mReactInstance;
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;
Expand Down Expand Up @@ -98,7 +98,7 @@ public void setUp() throws Exception {
doReturn(mJSBundleLoader).when(mReactHostDelegate).getJsBundleLoader();

mReactHost =
new ReactHost(
new ReactHostImpl(
mActivityController.get().getApplication(),
mReactHostDelegate,
mComponentFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,7 +49,7 @@ public void setUp() {

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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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;
Expand All @@ -27,7 +27,7 @@
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;
Expand All @@ -45,7 +45,7 @@

public class RNTesterApplication extends Application implements ReactApplication {

private ReactHost mReactHost;
private ReactHostImpl mReactHost;

private final ReactNativeHost mReactNativeHost =
new DefaultReactNativeHost(this) {
Expand Down Expand Up @@ -163,7 +163,7 @@ public ReactNativeHost getReactNativeHost() {

@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
Expand All @@ -175,7 +175,7 @@ public ReactHostInterface getReactHostInterface() {
ComponentFactory componentFactory = new ComponentFactory();
DefaultComponentsRegistry.register(componentFactory);
mReactHost =
new ReactHost(
new ReactHostImpl(
this.getApplicationContext(),
reactHostDelegate,
componentFactory,
Expand Down
Loading

0 comments on commit 01b9b50

Please sign in to comment.