-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move BridgelessDevSupportManager to .devsupport package (#46914)
Summary: Pull Request resolved: #46914 The `BridgelessDevSupportManager` should have lived inside the `.devsupport` package alongside all the other devsupport related tooling. It was instead created inside `.runtime` causing a tight coupling with `ReactHostImpl`. This made it impossible for Frameworks to customize it (i.e. in Expo GO) also because there was a circular dependency between ReactHostImpl and BridgelessDevSupportManager In this diff I'm: 1. Breaking the circular dependency by using `ReactHostDevHelper` 2. Updating all the parameters to reference `ReactHost` rather than `ReactHostImpl` 3. Moving BridgelessDevSupportManager to the `.devsupport` package. This is breaking for users that are manually composing a `BridgelessDevSupportManager` or that are extending the `ReactInstanceDevHelper`. - `ReactInstanceDevHelper` has 3 new method which will have to be implemented. - `BridgelessDevSupportManager` is now living in a different package. Changelog: [Android] [Breaking] - Add 3 methods to ReactInstanceDevHelper Reviewed By: rshest Differential Revision: D64105790 fbshipit-source-id: 13478fe1a035adb5b0dc83ebb1daad6cfb243881
- Loading branch information
1 parent
ad6a2fa
commit c867aba
Showing
12 changed files
with
354 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...ReactAndroid/src/main/java/com/facebook/react/devsupport/BridgelessDevSupportManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.devsupport; | ||
|
||
import android.content.Context; | ||
import androidx.annotation.Nullable; | ||
import com.facebook.infer.annotation.Nullsafe; | ||
import com.facebook.react.bridge.JSBundleLoader; | ||
import com.facebook.react.bridge.ReactContext; | ||
import com.facebook.react.bridge.UiThreadUtil; | ||
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.DevSplitBundleCallback; | ||
import com.facebook.react.devsupport.interfaces.PausedInDebuggerOverlayManager; | ||
import com.facebook.react.devsupport.interfaces.RedBoxHandler; | ||
import com.facebook.react.packagerconnection.RequestHandler; | ||
import java.util.Map; | ||
|
||
/** | ||
* An implementation of {@link com.facebook.react.devsupport.interfaces.DevSupportManager} that | ||
* extends the functionality in {@link DevSupportManagerBase} with some additional, more flexible | ||
* APIs for asynchronously loading the JS bundle. | ||
*/ | ||
@Nullsafe(Nullsafe.Mode.LOCAL) | ||
class BridgelessDevSupportManager extends DevSupportManagerBase { | ||
|
||
public BridgelessDevSupportManager( | ||
Context context, | ||
ReactInstanceDevHelper reactInstanceManagerHelper, | ||
@Nullable String packagerPathForJSBundleName) { | ||
this( | ||
context.getApplicationContext(), | ||
reactInstanceManagerHelper, | ||
packagerPathForJSBundleName, | ||
true /* enableOnCreate */, | ||
null /* redBoxHandler */, | ||
null /* devBundleDownloadListener */, | ||
2 /* minNumShakes */, | ||
null /* customPackagerCommandHandlers */, | ||
null /* surfaceDelegateFactory */, | ||
null /* devLoadingViewManager */, | ||
null /* pausedInDebuggerOverlayManager */); | ||
} | ||
|
||
/** | ||
* This constructor mirrors the same constructor we have for {@link BridgeDevSupportManager} and | ||
* is kept for backward compatibility. | ||
*/ | ||
public BridgelessDevSupportManager( | ||
Context applicationContext, | ||
ReactInstanceDevHelper reactInstanceManagerHelper, | ||
@Nullable String packagerPathForJSBundleName, | ||
boolean enableOnCreate, | ||
@Nullable RedBoxHandler redBoxHandler, | ||
@Nullable DevBundleDownloadListener devBundleDownloadListener, | ||
int minNumShakes, | ||
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers, | ||
@Nullable SurfaceDelegateFactory surfaceDelegateFactory, | ||
@Nullable DevLoadingViewManager devLoadingViewManager, | ||
@Nullable PausedInDebuggerOverlayManager pausedInDebuggerOverlayManager) { | ||
super( | ||
applicationContext, | ||
reactInstanceManagerHelper, | ||
packagerPathForJSBundleName, | ||
enableOnCreate, | ||
redBoxHandler, | ||
devBundleDownloadListener, | ||
minNumShakes, | ||
customPackagerCommandHandlers, | ||
surfaceDelegateFactory, | ||
devLoadingViewManager, | ||
pausedInDebuggerOverlayManager); | ||
} | ||
|
||
@Override | ||
protected String getUniqueTag() { | ||
return "Bridgeless"; | ||
} | ||
|
||
@Override | ||
public void loadSplitBundleFromServer( | ||
final String bundlePath, final DevSplitBundleCallback callback) { | ||
fetchSplitBundleAndCreateBundleLoader( | ||
bundlePath, | ||
new CallbackWithBundleLoader() { | ||
@Override | ||
public void onSuccess(final JSBundleLoader bundleLoader) { | ||
try { | ||
mReactInstanceDevHelper.loadBundle(bundleLoader).waitForCompletion(); | ||
String bundleURL = getDevServerHelper().getDevServerSplitBundleURL(bundlePath); | ||
ReactContext reactContext = mReactInstanceDevHelper.getCurrentReactContext(); | ||
if (reactContext != null) { | ||
reactContext.getJSModule(HMRClient.class).registerBundle(bundleURL); | ||
} | ||
callback.onSuccess(); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException( | ||
"[BridgelessDevSupportManager]: Got interrupted while loading bundle", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void onError(String url, Throwable cause) { | ||
callback.onError(url, cause); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void handleReloadJS() { | ||
UiThreadUtil.assertOnUiThread(); | ||
|
||
// dismiss redbox if exists | ||
hideRedboxDialog(); | ||
mReactInstanceDevHelper.reload("BridgelessDevSupportManager.handleReloadJS()"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.