mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Adding Dev Loading controller without activity for VR (#35392)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35392 Changelog: [General][Added] - For supporting Dev Loading View across platforms, adding the DevLoadingViewController without an activity/context. Reviewed By: rshest Differential Revision: D40947239 fbshipit-source-id: de124b0a7ee39dc7da3c1c45972a6703eff2f0ef
This commit is contained in:
1 parent
6c315de226
commit
662b51fad2
8 files changed
+62
-22
No files matched your search
+5
-2
@@ -25,6 +25,7 @@ import com.facebook.react.common.ReactConstants;
|
||||
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;
|
||||
@@ -74,7 +75,8 @@ public final class BridgeDevSupportManager extends DevSupportManagerBase {
|
||||
@Nullable DevBundleDownloadListener devBundleDownloadListener,
|
||||
int minNumShakes,
|
||||
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
|
||||
@Nullable SurfaceDelegateFactory surfaceDelegateFactory) {
|
||||
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
|
||||
@Nullable DevLoadingViewManager devLoadingViewManager) {
|
||||
super(
|
||||
applicationContext,
|
||||
reactInstanceManagerHelper,
|
||||
@@ -84,7 +86,8 @@ public final class BridgeDevSupportManager extends DevSupportManagerBase {
|
||||
devBundleDownloadListener,
|
||||
minNumShakes,
|
||||
customPackagerCommandHandlers,
|
||||
surfaceDelegateFactory);
|
||||
surfaceDelegateFactory,
|
||||
devLoadingViewManager);
|
||||
|
||||
if (getDevSettings().isStartSamplingProfilerOnInit()) {
|
||||
// Only start the profiler. If its already running, there is an error
|
||||
|
||||
+6
-3
@@ -25,8 +25,11 @@ import com.facebook.react.common.ReactConstants;
|
||||
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;
|
||||
@@ -36,7 +39,7 @@ public class DevLoadingViewController implements DevLoadingViewManager {
|
||||
sEnabled = enabled;
|
||||
}
|
||||
|
||||
public DevLoadingViewController(ReactInstanceDevHelper reactInstanceManagerHelper) {
|
||||
public DefaultDevLoadingViewImplementation(ReactInstanceDevHelper reactInstanceManagerHelper) {
|
||||
mReactInstanceManagerHelper = reactInstanceManagerHelper;
|
||||
}
|
||||
|
||||
+8
-3
@@ -11,6 +11,7 @@ import android.content.Context;
|
||||
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;
|
||||
@@ -46,6 +47,7 @@ public class DefaultDevSupportManagerFactory implements DevSupportManagerFactory
|
||||
null,
|
||||
minNumShakes,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
@@ -59,7 +61,8 @@ public class DefaultDevSupportManagerFactory implements DevSupportManagerFactory
|
||||
@Nullable DevBundleDownloadListener devBundleDownloadListener,
|
||||
int minNumShakes,
|
||||
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
|
||||
@Nullable SurfaceDelegateFactory surfaceDelegateFactory) {
|
||||
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
|
||||
@Nullable DevLoadingViewManager devLoadingViewManager) {
|
||||
if (!enableOnCreate) {
|
||||
return new DisabledDevSupportManager();
|
||||
}
|
||||
@@ -87,7 +90,8 @@ public class DefaultDevSupportManagerFactory implements DevSupportManagerFactory
|
||||
DevBundleDownloadListener.class,
|
||||
int.class,
|
||||
Map.class,
|
||||
SurfaceDelegateFactory.class);
|
||||
SurfaceDelegateFactory.class,
|
||||
DevLoadingViewManager.class);
|
||||
return (DevSupportManager)
|
||||
constructor.newInstance(
|
||||
applicationContext,
|
||||
@@ -98,7 +102,8 @@ public class DefaultDevSupportManagerFactory implements DevSupportManagerFactory
|
||||
devBundleDownloadListener,
|
||||
minNumShakes,
|
||||
customPackagerCommandHandlers,
|
||||
surfaceDelegateFactory);
|
||||
surfaceDelegateFactory,
|
||||
devLoadingViewManager);
|
||||
} catch (Exception e) {
|
||||
return new PerftestDevSupportManager(applicationContext);
|
||||
}
|
||||
|
||||
+15
-10
@@ -46,6 +46,7 @@ import com.facebook.react.common.SurfaceDelegateFactory;
|
||||
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;
|
||||
@@ -95,7 +96,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
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;
|
||||
@@ -132,7 +133,8 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
@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;
|
||||
@@ -206,7 +208,10 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
setDevSupportEnabled(enableOnCreate);
|
||||
|
||||
mRedBoxHandler = redBoxHandler;
|
||||
mDevLoadingViewController = new DevLoadingViewController(reactInstanceDevHelper);
|
||||
mDevLoadingViewManager =
|
||||
devLoadingViewManager != null
|
||||
? devLoadingViewManager
|
||||
: new DefaultDevLoadingViewImplementation(reactInstanceDevHelper);
|
||||
mSurfaceDelegateFactory = surfaceDelegateFactory;
|
||||
};
|
||||
|
||||
@@ -766,7 +771,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -778,14 +783,14 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
return;
|
||||
}
|
||||
|
||||
mDevLoadingViewController.showMessage(
|
||||
mDevLoadingViewManager.showMessage(
|
||||
mApplicationContext.getString(R.string.catalyst_debug_connecting));
|
||||
mDevLoadingViewVisible = true;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
protected void hideDevLoadingView() {
|
||||
mDevLoadingViewController.hide();
|
||||
mDevLoadingViewManager.hide();
|
||||
mDevLoadingViewVisible = false;
|
||||
}
|
||||
|
||||
@@ -827,7 +832,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
@Override
|
||||
public void onProgress(
|
||||
@Nullable String status, @Nullable Integer done, @Nullable Integer total) {
|
||||
mDevLoadingViewController.updateProgress(status, done, total);
|
||||
mDevLoadingViewManager.updateProgress(status, done, total);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -983,7 +988,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
@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);
|
||||
}
|
||||
@@ -1125,7 +1130,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
|
||||
// show the dev loading if it should be
|
||||
if (mDevLoadingViewVisible) {
|
||||
mDevLoadingViewController.showMessage("Reloading...");
|
||||
mDevLoadingViewManager.showMessage("Reloading...");
|
||||
}
|
||||
|
||||
mDevServerHelper.openPackagerConnection(
|
||||
@@ -1206,7 +1211,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
hideDevOptionsDialog();
|
||||
|
||||
// hide loading view
|
||||
mDevLoadingViewController.hide();
|
||||
mDevLoadingViewManager.hide();
|
||||
mDevServerHelper.closePackagerConnection();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -11,6 +11,7 @@ import android.content.Context;
|
||||
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;
|
||||
@@ -26,5 +27,6 @@ public interface DevSupportManagerFactory {
|
||||
@Nullable DevBundleDownloadListener devBundleDownloadListener,
|
||||
int minNumShakes,
|
||||
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
|
||||
@Nullable SurfaceDelegateFactory surfaceDelegateFactory);
|
||||
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
|
||||
@Nullable DevLoadingViewManager devLoadingViewManager);
|
||||
}
|
||||
Reference in new issue
Block a user