Skip to content

Commit

Permalink
Adding Dev Loading controller without activity for VR
Browse files Browse the repository at this point in the history
Summary:
Changelog:
    [General][Added] - For supporting Dev Loading View across platforms, adding the DevLoadingViewController without an activity/context.

Differential Revision: D40947239

fbshipit-source-id: bafa6ba0725a1f4edfa034638001664c9cb04145
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Nov 18, 2022
1 parent 4d7ddd4 commit a74781a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import com.facebook.react.devsupport.DevSupportManagerFactory;
import com.facebook.react.devsupport.ReactInstanceDevHelper;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
Expand Down Expand Up @@ -233,7 +234,8 @@ public static ReactInstanceManagerBuilder builder() {
@Nullable JSIModulePackage jsiModulePackage,
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
@Nullable ReactPackageTurboModuleManagerDelegate.Builder tmmDelegateBuilder,
@Nullable SurfaceDelegateFactory surfaceDelegateFactory) {
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
@Nullable DevLoadingViewManager devLoadingViewManager) {
FLog.d(TAG, "ReactInstanceManager.ctor()");
initializeSoLoaderIfNecessary(applicationContext);

Expand Down Expand Up @@ -261,7 +263,8 @@ public static ReactInstanceManagerBuilder builder() {
devBundleDownloadListener,
minNumShakes,
customPackagerCommandHandlers,
surfaceDelegateFactory);
surfaceDelegateFactory,
devLoadingViewManager);
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
mBridgeIdleDebugListener = bridgeIdleDebugListener;
mLifecycleState = initialLifecycleState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.facebook.react.devsupport.DefaultDevSupportManagerFactory;
import com.facebook.react.devsupport.DevSupportManagerFactory;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
import com.facebook.react.jscexecutor.JSCExecutor;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class ReactInstanceManagerBuilder {
private @Nullable Map<String, RequestHandler> mCustomPackagerCommandHandlers;
private @Nullable ReactPackageTurboModuleManagerDelegate.Builder mTMMDelegateBuilder;
private @Nullable SurfaceDelegateFactory mSurfaceDelegateFactory;
private @Nullable DevLoadingViewManager mDevLoadingViewManager;
private JSEngineResolutionAlgorithm jsEngineResolutionAlgorithm = null;

/* package protected */ ReactInstanceManagerBuilder() {}
Expand Down Expand Up @@ -216,6 +218,13 @@ public ReactInstanceManagerBuilder setSurfaceDelegateFactory(
return this;
}

/** Sets the Dev Loading View Manager. */
public ReactInstanceManagerBuilder setDevLoadingViewManager(
@Nullable DevLoadingViewManager devLoadingViewManager) {
mDevLoadingViewManager = devLoadingViewManager;
return this;
}

/**
* Sets the initial lifecycle state of the host. For example, if the host is already resumed at
* creation time, we wouldn't expect an onResume call until we get an onPause call.
Expand Down Expand Up @@ -337,7 +346,8 @@ public ReactInstanceManager build() {
mJSIModulesPackage,
mCustomPackagerCommandHandlers,
mTMMDelegateBuilder,
mSurfaceDelegateFactory);
mSurfaceDelegateFactory,
mDevLoadingViewManager);
}

private JavaScriptExecutorFactory getDefaultJSExecutorFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.facebook.react.common.SurfaceDelegate;
import com.facebook.react.common.SurfaceDelegateFactory;
import com.facebook.react.devsupport.DevSupportManagerFactory;
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
import java.util.List;

Expand Down Expand Up @@ -71,6 +72,7 @@ protected ReactInstanceManager createReactInstanceManager() {
.setJSMainModulePath(getJSMainModuleName())
.setUseDeveloperSupport(getUseDeveloperSupport())
.setDevSupportManagerFactory(getDevSupportManagerFactory())
.setDevLoadingViewManager(getDevLoadingViewManager())
.setRequireActivity(getShouldRequireActivity())
.setSurfaceDelegateFactory(getSurfaceDelegateFactory())
.setLazyViewManagersEnabled(getLazyViewManagersEnabled())
Expand Down Expand Up @@ -149,6 +151,13 @@ public SurfaceDelegateFactory getSurfaceDelegateFactory() {
};
}

/**
* Get the {@link DevLoadingViewManager}. Override this to use a custom dev loading view manager
*/
protected @Nullable DevLoadingViewManager getDevLoadingViewManager() {
return null;
}

/**
* Returns the name of the main module. Determines the URL used to fetch the JS bundle from Metro.
* It is only used when dev support is enabled. This is the first file to be executed once the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.facebook.react.common.SurfaceDelegateFactory;
import com.facebook.react.common.futures.SimpleSettableFuture;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
import com.facebook.react.devsupport.interfaces.DevOptionHandler;
import com.facebook.react.devsupport.interfaces.DevSplitBundleCallback;
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
Expand Down Expand Up @@ -74,7 +75,8 @@ public BridgeDevSupportManager(
@Nullable DevBundleDownloadListener devBundleDownloadListener,
int minNumShakes,
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
@Nullable SurfaceDelegateFactory surfaceDelegateFactory) {
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
@Nullable DevLoadingViewManager devLoadingViewManager) {
super(
applicationContext,
reactInstanceManagerHelper,
Expand All @@ -84,7 +86,8 @@ public BridgeDevSupportManager(
devBundleDownloadListener,
minNumShakes,
customPackagerCommandHandlers,
surfaceDelegateFactory);
surfaceDelegateFactory,
devLoadingViewManager);

if (getDevSettings().isStartSamplingProfilerOnInit()) {
// Only start the profiler. If its already running, there is an error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
import java.util.Locale;

/** Controller to display loading messages on top of the screen. All methods are thread safe. */
public class DevLoadingViewController implements DevLoadingViewManager {
/**
* Default implementation of Dev Loading View Manager to display loading messages on top of the
* screen. All methods are thread safe.
*/
public class DefaultDevLoadingViewImplementation implements DevLoadingViewManager {
private static boolean sEnabled = true;
private final ReactInstanceDevHelper mReactInstanceManagerHelper;
private @Nullable TextView mDevLoadingView;
Expand All @@ -36,7 +39,7 @@ public static void setDevLoadingEnabled(boolean enabled) {
sEnabled = enabled;
}

public DevLoadingViewController(ReactInstanceDevHelper reactInstanceManagerHelper) {
public DefaultDevLoadingViewImplementation(ReactInstanceDevHelper reactInstanceManagerHelper) {
mReactInstanceManagerHelper = reactInstanceManagerHelper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import androidx.annotation.Nullable;
import com.facebook.react.common.SurfaceDelegateFactory;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
import com.facebook.react.packagerconnection.RequestHandler;
Expand Down Expand Up @@ -46,6 +47,7 @@ public DevSupportManager create(
null,
minNumShakes,
null,
null,
null);
}

Expand All @@ -59,7 +61,8 @@ public DevSupportManager create(
@Nullable DevBundleDownloadListener devBundleDownloadListener,
int minNumShakes,
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
@Nullable SurfaceDelegateFactory surfaceDelegateFactory) {
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
@Nullable DevLoadingViewManager devLoadingViewManager) {
if (!enableOnCreate) {
return new DisabledDevSupportManager();
}
Expand Down Expand Up @@ -87,7 +90,8 @@ public DevSupportManager create(
DevBundleDownloadListener.class,
int.class,
Map.class,
SurfaceDelegateFactory.class);
SurfaceDelegateFactory.class,
DevLoadingViewManager.class);
return (DevSupportManager)
constructor.newInstance(
applicationContext,
Expand All @@ -98,7 +102,8 @@ public DevSupportManager create(
devBundleDownloadListener,
minNumShakes,
customPackagerCommandHandlers,
surfaceDelegateFactory);
surfaceDelegateFactory,
devLoadingViewManager);
} catch (Exception e) {
return new PerftestDevSupportManager(applicationContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.facebook.react.devsupport.DevServerHelper.PackagerCommandListener;
import com.facebook.react.devsupport.interfaces.BundleLoadCallback;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
import com.facebook.react.devsupport.interfaces.DevOptionHandler;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.interfaces.ErrorCustomizer;
Expand Down Expand Up @@ -95,7 +96,7 @@ public interface CallbackWithBundleLoader {
private final File mJSBundleDownloadedFile;
private final File mJSSplitBundlesDir;
private final DefaultJSExceptionHandler mDefaultJSExceptionHandler;
private final DevLoadingViewController mDevLoadingViewController;
private final DevLoadingViewManager mDevLoadingViewManager;

private @Nullable SurfaceDelegate mRedBoxSurfaceDelegate;
private @Nullable AlertDialog mDevOptionsDialog;
Expand Down Expand Up @@ -132,7 +133,8 @@ public DevSupportManagerBase(
@Nullable DevBundleDownloadListener devBundleDownloadListener,
int minNumShakes,
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
@Nullable SurfaceDelegateFactory surfaceDelegateFactory) {
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
@Nullable DevLoadingViewManager devLoadingViewManager) {
mReactInstanceDevHelper = reactInstanceDevHelper;
mApplicationContext = applicationContext;
mJSAppBundleName = packagerPathForJSBundleName;
Expand Down Expand Up @@ -206,7 +208,10 @@ public void onReceive(Context context, Intent intent) {
setDevSupportEnabled(enableOnCreate);

mRedBoxHandler = redBoxHandler;
mDevLoadingViewController = new DevLoadingViewController(reactInstanceDevHelper);
mDevLoadingViewManager =
devLoadingViewManager != null
? devLoadingViewManager
: new DefaultDevLoadingViewImplementation(reactInstanceDevHelper);
mSurfaceDelegateFactory = surfaceDelegateFactory;
};

Expand Down Expand Up @@ -766,7 +771,7 @@ private void showDevLoadingViewForUrl(String bundleUrl) {
}

int port = parsedURL.getPort() != -1 ? parsedURL.getPort() : parsedURL.getDefaultPort();
mDevLoadingViewController.showMessage(
mDevLoadingViewManager.showMessage(
mApplicationContext.getString(
R.string.catalyst_loading_from_url, parsedURL.getHost() + ":" + port));
mDevLoadingViewVisible = true;
Expand All @@ -778,14 +783,14 @@ protected void showDevLoadingViewForRemoteJSEnabled() {
return;
}

mDevLoadingViewController.showMessage(
mDevLoadingViewManager.showMessage(
mApplicationContext.getString(R.string.catalyst_debug_connecting));
mDevLoadingViewVisible = true;
}

@UiThread
protected void hideDevLoadingView() {
mDevLoadingViewController.hide();
mDevLoadingViewManager.hide();
mDevLoadingViewVisible = false;
}

Expand Down Expand Up @@ -827,7 +832,7 @@ public void run() {
@Override
public void onProgress(
@Nullable String status, @Nullable Integer done, @Nullable Integer total) {
mDevLoadingViewController.updateProgress(status, done, total);
mDevLoadingViewManager.updateProgress(status, done, total);
}

@Override
Expand Down Expand Up @@ -983,7 +988,7 @@ public void onProgress(
@Nullable final String status,
@Nullable final Integer done,
@Nullable final Integer total) {
mDevLoadingViewController.updateProgress(status, done, total);
mDevLoadingViewManager.updateProgress(status, done, total);
if (mBundleDownloadListener != null) {
mBundleDownloadListener.onProgress(status, done, total);
}
Expand Down Expand Up @@ -1125,7 +1130,7 @@ private void reload() {

// show the dev loading if it should be
if (mDevLoadingViewVisible) {
mDevLoadingViewController.showMessage("Reloading...");
mDevLoadingViewManager.showMessage("Reloading...");
}

mDevServerHelper.openPackagerConnection(
Expand Down Expand Up @@ -1206,7 +1211,7 @@ public void run() {
hideDevOptionsDialog();

// hide loading view
mDevLoadingViewController.hide();
mDevLoadingViewManager.hide();
mDevServerHelper.closePackagerConnection();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import androidx.annotation.Nullable;
import com.facebook.react.common.SurfaceDelegateFactory;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
import com.facebook.react.packagerconnection.RequestHandler;
Expand All @@ -26,5 +27,6 @@ DevSupportManager create(
@Nullable DevBundleDownloadListener devBundleDownloadListener,
int minNumShakes,
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
@Nullable SurfaceDelegateFactory surfaceDelegateFactory);
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
@Nullable DevLoadingViewManager devLoadingViewManager);
}

0 comments on commit a74781a

Please sign in to comment.