Skip to content

Commit 662b51f

Browse files
Adding Dev Loading controller without activity for VR (#35392)
Summary: Pull Request resolved: #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
1 parent 6c315de commit 662b51f

8 files changed

+62
-22
lines changed

ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import com.facebook.react.devsupport.DevSupportManagerFactory;
8383
import com.facebook.react.devsupport.ReactInstanceDevHelper;
8484
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
85+
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
8586
import com.facebook.react.devsupport.interfaces.DevSupportManager;
8687
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
8788
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
@@ -233,7 +234,8 @@ public static ReactInstanceManagerBuilder builder() {
233234
@Nullable JSIModulePackage jsiModulePackage,
234235
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
235236
@Nullable ReactPackageTurboModuleManagerDelegate.Builder tmmDelegateBuilder,
236-
@Nullable SurfaceDelegateFactory surfaceDelegateFactory) {
237+
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
238+
@Nullable DevLoadingViewManager devLoadingViewManager) {
237239
FLog.d(TAG, "ReactInstanceManager.ctor()");
238240
initializeSoLoaderIfNecessary(applicationContext);
239241

@@ -261,7 +263,8 @@ public static ReactInstanceManagerBuilder builder() {
261263
devBundleDownloadListener,
262264
minNumShakes,
263265
customPackagerCommandHandlers,
264-
surfaceDelegateFactory);
266+
surfaceDelegateFactory,
267+
devLoadingViewManager);
265268
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
266269
mBridgeIdleDebugListener = bridgeIdleDebugListener;
267270
mLifecycleState = initialLifecycleState;

ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.facebook.react.devsupport.DefaultDevSupportManagerFactory;
2929
import com.facebook.react.devsupport.DevSupportManagerFactory;
3030
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
31+
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
3132
import com.facebook.react.devsupport.interfaces.DevSupportManager;
3233
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
3334
import com.facebook.react.jscexecutor.JSCExecutor;
@@ -67,6 +68,7 @@ public class ReactInstanceManagerBuilder {
6768
private @Nullable Map<String, RequestHandler> mCustomPackagerCommandHandlers;
6869
private @Nullable ReactPackageTurboModuleManagerDelegate.Builder mTMMDelegateBuilder;
6970
private @Nullable SurfaceDelegateFactory mSurfaceDelegateFactory;
71+
private @Nullable DevLoadingViewManager mDevLoadingViewManager;
7072
private JSEngineResolutionAlgorithm jsEngineResolutionAlgorithm = null;
7173

7274
/* package protected */ ReactInstanceManagerBuilder() {}
@@ -216,6 +218,13 @@ public ReactInstanceManagerBuilder setSurfaceDelegateFactory(
216218
return this;
217219
}
218220

221+
/** Sets the Dev Loading View Manager. */
222+
public ReactInstanceManagerBuilder setDevLoadingViewManager(
223+
@Nullable DevLoadingViewManager devLoadingViewManager) {
224+
mDevLoadingViewManager = devLoadingViewManager;
225+
return this;
226+
}
227+
219228
/**
220229
* Sets the initial lifecycle state of the host. For example, if the host is already resumed at
221230
* creation time, we wouldn't expect an onResume call until we get an onPause call.
@@ -337,7 +346,8 @@ public ReactInstanceManager build() {
337346
mJSIModulesPackage,
338347
mCustomPackagerCommandHandlers,
339348
mTMMDelegateBuilder,
340-
mSurfaceDelegateFactory);
349+
mSurfaceDelegateFactory,
350+
mDevLoadingViewManager);
341351
}
342352

343353
private JavaScriptExecutorFactory getDefaultJSExecutorFactory(

ReactAndroid/src/main/java/com/facebook/react/ReactNativeHost.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.facebook.react.common.SurfaceDelegate;
1919
import com.facebook.react.common.SurfaceDelegateFactory;
2020
import com.facebook.react.devsupport.DevSupportManagerFactory;
21+
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
2122
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
2223
import java.util.List;
2324

@@ -71,6 +72,7 @@ protected ReactInstanceManager createReactInstanceManager() {
7172
.setJSMainModulePath(getJSMainModuleName())
7273
.setUseDeveloperSupport(getUseDeveloperSupport())
7374
.setDevSupportManagerFactory(getDevSupportManagerFactory())
75+
.setDevLoadingViewManager(getDevLoadingViewManager())
7476
.setRequireActivity(getShouldRequireActivity())
7577
.setSurfaceDelegateFactory(getSurfaceDelegateFactory())
7678
.setLazyViewManagersEnabled(getLazyViewManagersEnabled())
@@ -149,6 +151,13 @@ public SurfaceDelegateFactory getSurfaceDelegateFactory() {
149151
};
150152
}
151153

154+
/**
155+
* Get the {@link DevLoadingViewManager}. Override this to use a custom dev loading view manager
156+
*/
157+
protected @Nullable DevLoadingViewManager getDevLoadingViewManager() {
158+
return null;
159+
}
160+
152161
/**
153162
* Returns the name of the main module. Determines the URL used to fetch the JS bundle from Metro.
154163
* It is only used when dev support is enabled. This is the first file to be executed once the

ReactAndroid/src/main/java/com/facebook/react/devsupport/BridgeDevSupportManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.facebook.react.common.SurfaceDelegateFactory;
2626
import com.facebook.react.common.futures.SimpleSettableFuture;
2727
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
28+
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
2829
import com.facebook.react.devsupport.interfaces.DevOptionHandler;
2930
import com.facebook.react.devsupport.interfaces.DevSplitBundleCallback;
3031
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
@@ -74,7 +75,8 @@ public BridgeDevSupportManager(
7475
@Nullable DevBundleDownloadListener devBundleDownloadListener,
7576
int minNumShakes,
7677
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
77-
@Nullable SurfaceDelegateFactory surfaceDelegateFactory) {
78+
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
79+
@Nullable DevLoadingViewManager devLoadingViewManager) {
7880
super(
7981
applicationContext,
8082
reactInstanceManagerHelper,
@@ -84,7 +86,8 @@ public BridgeDevSupportManager(
8486
devBundleDownloadListener,
8587
minNumShakes,
8688
customPackagerCommandHandlers,
87-
surfaceDelegateFactory);
89+
surfaceDelegateFactory,
90+
devLoadingViewManager);
8891

8992
if (getDevSettings().isStartSamplingProfilerOnInit()) {
9093
// Only start the profiler. If its already running, there is an error

ReactAndroid/src/main/java/com/facebook/react/devsupport/DevLoadingViewController.java renamed to ReactAndroid/src/main/java/com/facebook/react/devsupport/DefaultDevLoadingViewImplementation.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
2626
import java.util.Locale;
2727

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

39-
public DevLoadingViewController(ReactInstanceDevHelper reactInstanceManagerHelper) {
42+
public DefaultDevLoadingViewImplementation(ReactInstanceDevHelper reactInstanceManagerHelper) {
4043
mReactInstanceManagerHelper = reactInstanceManagerHelper;
4144
}
4245

ReactAndroid/src/main/java/com/facebook/react/devsupport/DefaultDevSupportManagerFactory.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import androidx.annotation.Nullable;
1212
import com.facebook.react.common.SurfaceDelegateFactory;
1313
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
14+
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
1415
import com.facebook.react.devsupport.interfaces.DevSupportManager;
1516
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
1617
import com.facebook.react.packagerconnection.RequestHandler;
@@ -46,6 +47,7 @@ public DevSupportManager create(
4647
null,
4748
minNumShakes,
4849
null,
50+
null,
4951
null);
5052
}
5153

@@ -59,7 +61,8 @@ public DevSupportManager create(
5961
@Nullable DevBundleDownloadListener devBundleDownloadListener,
6062
int minNumShakes,
6163
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
62-
@Nullable SurfaceDelegateFactory surfaceDelegateFactory) {
64+
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
65+
@Nullable DevLoadingViewManager devLoadingViewManager) {
6366
if (!enableOnCreate) {
6467
return new DisabledDevSupportManager();
6568
}
@@ -87,7 +90,8 @@ public DevSupportManager create(
8790
DevBundleDownloadListener.class,
8891
int.class,
8992
Map.class,
90-
SurfaceDelegateFactory.class);
93+
SurfaceDelegateFactory.class,
94+
DevLoadingViewManager.class);
9195
return (DevSupportManager)
9296
constructor.newInstance(
9397
applicationContext,
@@ -98,7 +102,8 @@ public DevSupportManager create(
98102
devBundleDownloadListener,
99103
minNumShakes,
100104
customPackagerCommandHandlers,
101-
surfaceDelegateFactory);
105+
surfaceDelegateFactory,
106+
devLoadingViewManager);
102107
} catch (Exception e) {
103108
return new PerftestDevSupportManager(applicationContext);
104109
}

ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.facebook.react.devsupport.DevServerHelper.PackagerCommandListener;
4747
import com.facebook.react.devsupport.interfaces.BundleLoadCallback;
4848
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
49+
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
4950
import com.facebook.react.devsupport.interfaces.DevOptionHandler;
5051
import com.facebook.react.devsupport.interfaces.DevSupportManager;
5152
import com.facebook.react.devsupport.interfaces.ErrorCustomizer;
@@ -95,7 +96,7 @@ public interface CallbackWithBundleLoader {
9596
private final File mJSBundleDownloadedFile;
9697
private final File mJSSplitBundlesDir;
9798
private final DefaultJSExceptionHandler mDefaultJSExceptionHandler;
98-
private final DevLoadingViewController mDevLoadingViewController;
99+
private final DevLoadingViewManager mDevLoadingViewManager;
99100

100101
private @Nullable SurfaceDelegate mRedBoxSurfaceDelegate;
101102
private @Nullable AlertDialog mDevOptionsDialog;
@@ -132,7 +133,8 @@ public DevSupportManagerBase(
132133
@Nullable DevBundleDownloadListener devBundleDownloadListener,
133134
int minNumShakes,
134135
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
135-
@Nullable SurfaceDelegateFactory surfaceDelegateFactory) {
136+
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
137+
@Nullable DevLoadingViewManager devLoadingViewManager) {
136138
mReactInstanceDevHelper = reactInstanceDevHelper;
137139
mApplicationContext = applicationContext;
138140
mJSAppBundleName = packagerPathForJSBundleName;
@@ -206,7 +208,10 @@ public void onReceive(Context context, Intent intent) {
206208
setDevSupportEnabled(enableOnCreate);
207209

208210
mRedBoxHandler = redBoxHandler;
209-
mDevLoadingViewController = new DevLoadingViewController(reactInstanceDevHelper);
211+
mDevLoadingViewManager =
212+
devLoadingViewManager != null
213+
? devLoadingViewManager
214+
: new DefaultDevLoadingViewImplementation(reactInstanceDevHelper);
210215
mSurfaceDelegateFactory = surfaceDelegateFactory;
211216
};
212217

@@ -766,7 +771,7 @@ private void showDevLoadingViewForUrl(String bundleUrl) {
766771
}
767772

768773
int port = parsedURL.getPort() != -1 ? parsedURL.getPort() : parsedURL.getDefaultPort();
769-
mDevLoadingViewController.showMessage(
774+
mDevLoadingViewManager.showMessage(
770775
mApplicationContext.getString(
771776
R.string.catalyst_loading_from_url, parsedURL.getHost() + ":" + port));
772777
mDevLoadingViewVisible = true;
@@ -778,14 +783,14 @@ protected void showDevLoadingViewForRemoteJSEnabled() {
778783
return;
779784
}
780785

781-
mDevLoadingViewController.showMessage(
786+
mDevLoadingViewManager.showMessage(
782787
mApplicationContext.getString(R.string.catalyst_debug_connecting));
783788
mDevLoadingViewVisible = true;
784789
}
785790

786791
@UiThread
787792
protected void hideDevLoadingView() {
788-
mDevLoadingViewController.hide();
793+
mDevLoadingViewManager.hide();
789794
mDevLoadingViewVisible = false;
790795
}
791796

@@ -827,7 +832,7 @@ public void run() {
827832
@Override
828833
public void onProgress(
829834
@Nullable String status, @Nullable Integer done, @Nullable Integer total) {
830-
mDevLoadingViewController.updateProgress(status, done, total);
835+
mDevLoadingViewManager.updateProgress(status, done, total);
831836
}
832837

833838
@Override
@@ -983,7 +988,7 @@ public void onProgress(
983988
@Nullable final String status,
984989
@Nullable final Integer done,
985990
@Nullable final Integer total) {
986-
mDevLoadingViewController.updateProgress(status, done, total);
991+
mDevLoadingViewManager.updateProgress(status, done, total);
987992
if (mBundleDownloadListener != null) {
988993
mBundleDownloadListener.onProgress(status, done, total);
989994
}
@@ -1125,7 +1130,7 @@ private void reload() {
11251130

11261131
// show the dev loading if it should be
11271132
if (mDevLoadingViewVisible) {
1128-
mDevLoadingViewController.showMessage("Reloading...");
1133+
mDevLoadingViewManager.showMessage("Reloading...");
11291134
}
11301135

11311136
mDevServerHelper.openPackagerConnection(
@@ -1206,7 +1211,7 @@ public void run() {
12061211
hideDevOptionsDialog();
12071212

12081213
// hide loading view
1209-
mDevLoadingViewController.hide();
1214+
mDevLoadingViewManager.hide();
12101215
mDevServerHelper.closePackagerConnection();
12111216
}
12121217
}

ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import androidx.annotation.Nullable;
1212
import com.facebook.react.common.SurfaceDelegateFactory;
1313
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
14+
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
1415
import com.facebook.react.devsupport.interfaces.DevSupportManager;
1516
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
1617
import com.facebook.react.packagerconnection.RequestHandler;
@@ -26,5 +27,6 @@ DevSupportManager create(
2627
@Nullable DevBundleDownloadListener devBundleDownloadListener,
2728
int minNumShakes,
2829
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
29-
@Nullable SurfaceDelegateFactory surfaceDelegateFactory);
30+
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
31+
@Nullable DevLoadingViewManager devLoadingViewManager);
3032
}

0 commit comments

Comments
 (0)