Skip to content

Commit

Permalink
DevSupportManagerBase: Rename getCurrentContext() -> getCurrentReactC…
Browse files Browse the repository at this point in the history
…ontext() (#47390)

Summary:
Pull Request resolved: #47390

getCurrentContext() is very ambiguous.

Changelog: [Android][Breaking] - Make DevSupportManagerBase.getCurrentReactContext() public

Reviewed By: mdvacca

Differential Revision: D65433217

fbshipit-source-id: a739d206de8085fc5b47b2a31c7e94fe6e71852f
  • Loading branch information
RSNara authored and facebook-github-bot committed Nov 5, 2024
1 parent fe656be commit 5a6a42c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ public abstract class com/facebook/react/devsupport/DevSupportManagerBase : com/
public fun fetchSplitBundleAndCreateBundleLoader (Ljava/lang/String;Lcom/facebook/react/devsupport/DevSupportManagerBase$CallbackWithBundleLoader;)V
protected fun getApplicationContext ()Landroid/content/Context;
public fun getCurrentActivity ()Landroid/app/Activity;
protected fun getCurrentContext ()Lcom/facebook/react/bridge/ReactContext;
protected fun getCurrentReactContext ()Lcom/facebook/react/bridge/ReactContext;
public fun getDevLoadingViewManager ()Lcom/facebook/react/devsupport/interfaces/DevLoadingViewManager;
public fun getDevServerHelper ()Lcom/facebook/react/devsupport/DevServerHelper;
public fun getDevSettings ()Lcom/facebook/react/modules/debug/interfaces/DeveloperSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public void loadSplitBundleFromServer(
new CallbackWithBundleLoader() {
@Override
public void onSuccess(JSBundleLoader bundleLoader) {
bundleLoader.loadScript(getCurrentContext().getCatalystInstance());
getCurrentContext()
bundleLoader.loadScript(getCurrentReactContext().getCatalystInstance());
getCurrentReactContext()
.getJSModule(HMRClient.class)
.registerBundle(getDevServerHelper().getDevServerSplitBundleURL(bundlePath));
callback.onSuccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public interface CallbackWithBundleLoader {
private @Nullable DebugOverlayController mDebugOverlayController;
private boolean mDevLoadingViewVisible = false;
private int mPendingJSSplitBundleRequests = 0;
private @Nullable ReactContext mCurrentContext;
private @Nullable ReactContext mCurrentReactContext;
private final DeveloperSettings mDevSettings;
private boolean mIsReceiverRegistered = false;
private boolean mIsShakeDetectorStarted = false;
Expand Down Expand Up @@ -429,11 +429,11 @@ public void onOptionSelected() {
() -> {
boolean nextEnabled = !mDevSettings.isHotModuleReplacementEnabled();
mDevSettings.setHotModuleReplacementEnabled(nextEnabled);
if (mCurrentContext != null) {
if (mCurrentReactContext != null) {
if (nextEnabled) {
mCurrentContext.getJSModule(HMRClient.class).enable();
mCurrentReactContext.getJSModule(HMRClient.class).enable();
} else {
mCurrentContext.getJSModule(HMRClient.class).disable();
mCurrentReactContext.getJSModule(HMRClient.class).disable();
}
}
if (nextEnabled && !mDevSettings.isJSDevModeEnabled()) {
Expand Down Expand Up @@ -542,8 +542,10 @@ public View getView(int position, @Nullable View convertView, ViewGroup parent)
.setOnCancelListener(dialog -> mDevOptionsDialog = null)
.create();
mDevOptionsDialog.show();
if (mCurrentContext != null) {
mCurrentContext.getJSModule(RCTNativeAppEventEmitter.class).emit("RCTDevMenuShown", null);
if (mCurrentReactContext != null) {
mCurrentReactContext
.getJSModule(RCTNativeAppEventEmitter.class)
.emit("RCTDevMenuShown", null);
}
}

Expand Down Expand Up @@ -588,7 +590,7 @@ public void onNewReactContextCreated(ReactContext reactContext) {

@Override
public void onReactInstanceDestroyed(ReactContext reactContext) {
if (reactContext == mCurrentContext) {
if (reactContext == mCurrentReactContext) {
// only call reset context when the destroyed context matches the one that is currently set
// for this manager
resetCurrentContext(null);
Expand Down Expand Up @@ -664,12 +666,12 @@ public boolean hasUpToDateJSBundleInCache() {
}

private void resetCurrentContext(@Nullable ReactContext reactContext) {
if (mCurrentContext == reactContext) {
if (mCurrentReactContext == reactContext) {
// new context is the same as the old one - do nothing
return;
}

mCurrentContext = reactContext;
mCurrentReactContext = reactContext;

// Recreate debug overlay controller with new CatalystInstance object
if (mDebugOverlayController != null) {
Expand All @@ -679,13 +681,13 @@ private void resetCurrentContext(@Nullable ReactContext reactContext) {
mDebugOverlayController = new DebugOverlayController(reactContext);
}

if (mCurrentContext != null) {
if (mCurrentReactContext != null) {
try {
URL sourceUrl = new URL(getSourceUrl());
String path = sourceUrl.getPath().substring(1); // strip initial slash in path
String host = sourceUrl.getHost();
int port = sourceUrl.getPort() != -1 ? sourceUrl.getPort() : sourceUrl.getDefaultPort();
mCurrentContext
mCurrentReactContext
.getJSModule(HMRClient.class)
.setup("android", path, host, port, mDevSettings.isHotModuleReplacementEnabled());
} catch (MalformedURLException e) {
Expand All @@ -705,8 +707,8 @@ public void reloadSettings() {
}
}

protected @Nullable ReactContext getCurrentContext() {
return mCurrentContext;
protected @Nullable ReactContext getCurrentReactContext() {
return mCurrentReactContext;
}

public @Nullable String getJSAppBundleName() {
Expand Down Expand Up @@ -783,7 +785,7 @@ public void fetchSplitBundleAndCreateBundleLoader(
public void onSuccess() {
UiThreadUtil.runOnUiThread(() -> hideSplitBundleDevLoadingView());

@Nullable ReactContext context = mCurrentContext;
@Nullable ReactContext context = mCurrentReactContext;
if (context == null || !context.hasActiveReactInstance()) {
return;
}
Expand Down Expand Up @@ -864,10 +866,10 @@ public int getLastErrorCookie() {
}

private void handleCaptureHeap(final Responder responder) {
if (mCurrentContext == null) {
if (mCurrentReactContext == null) {
return;
}
JSCHeapCapture heapCapture = mCurrentContext.getNativeModule(JSCHeapCapture.class);
JSCHeapCapture heapCapture = mCurrentReactContext.getNativeModule(JSCHeapCapture.class);

if (heapCapture != null) {
heapCapture.captureHeap(
Expand Down Expand Up @@ -1160,7 +1162,7 @@ private void compatRegisterReceiver(
@Override
public void openDebugger() {
mDevServerHelper.openDebugger(
mCurrentContext, mApplicationContext.getString(R.string.catalyst_open_debugger_error));
mCurrentReactContext, mApplicationContext.getString(R.string.catalyst_open_debugger_error));
}

@Override
Expand Down

0 comments on commit 5a6a42c

Please sign in to comment.