Skip to content

Commit

Permalink
Cleanup: Use get/setCurrentActivity in ReactHost
Browse files Browse the repository at this point in the history
Summary:
Instead of using the mActivity reference directly, let's just use getCurrentActivity() and setCurrentActivity().

Changelog: [Internal]

Differential Revision: D48076896

fbshipit-source-id: 6b53f0a7723626b8991d380e44a6d359fe76285d
  • Loading branch information
RSNara authored and facebook-github-bot committed Aug 14, 2023
1 parent da60791 commit d031f57
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ public void onHostResume(final @Nullable Activity activity) {
final String method = "onHostResume(activity)";
log(method);

mActivity.set(activity);
setCurrentActivity(activity);
ReactContext currentContext = getCurrentReactContext();

// TODO(T137233065): Enable DevSupportManager here
mReactLifecycleStateManager.moveToOnHostResume(currentContext, mActivity.get());
mReactLifecycleStateManager.moveToOnHostResume(currentContext, getCurrentActivity());
}

@ThreadConfined(UI)
Expand All @@ -290,7 +290,7 @@ public void onHostPause(final @Nullable Activity activity) {

ReactContext currentContext = getCurrentReactContext();

Activity currentActivity = mActivity.get();
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
String currentActivityClass = currentActivity.getClass().getSimpleName();
String activityClass = activity == null ? "null" : activity.getClass().getSimpleName();
Expand Down Expand Up @@ -320,7 +320,7 @@ public void onHostPause() {

// TODO(T137233065): Disable DevSupportManager here
mDefaultHardwareBackBtnHandler = null;
mReactLifecycleStateManager.moveToOnHostPause(currentContext, mActivity.get());
mReactLifecycleStateManager.moveToOnHostPause(currentContext, getCurrentActivity());
}

/** To be called when the host activity is destroyed. */
Expand All @@ -340,7 +340,7 @@ public void onHostDestroy(@Nullable Activity activity) {
final String method = "onHostDestroy(activity)";
log(method);

Activity currentActivity = mActivity.get();
Activity currentActivity = getCurrentActivity();

// TODO(T137233065): Disable DevSupportManager here
if (currentActivity == activity) {
Expand Down Expand Up @@ -503,6 +503,10 @@ private MemoryPressureListener createMemoryPressureListener(ReactInstance reactI
return mActivity.get();
}

private void setCurrentActivity(@Nullable Activity activity) {
mActivity.set(activity);
}

/**
* Get the {@link EventDispatcher} from the {@link FabricUIManager}. This always returns an
* EventDispatcher, even if the instance isn't alive; in that case, it returns a {@link
Expand Down Expand Up @@ -725,7 +729,7 @@ private Task<Void> newStart() {
@ThreadConfined(UI)
private void moveToHostDestroy(@Nullable ReactContext currentContext) {
mReactLifecycleStateManager.moveToOnHostDestroy(currentContext);
mActivity.set(null);
setCurrentActivity(null);
}

private void raiseSoftException(String method, String message) {
Expand Down Expand Up @@ -923,14 +927,15 @@ class Result {
final boolean isReloading = task.getResult().mIsReloading;

if (isReloading) {
mReactLifecycleStateManager.moveToOnHostResume(reactContext, mActivity.get());
mReactLifecycleStateManager.moveToOnHostResume(
reactContext, getCurrentActivity());
} else {
/**
* Call ReactContext.onHostResume() only when already in the resumed state
* which aligns with the bridge https://fburl.com/diffusion/2qhxmudv.
*/
mReactLifecycleStateManager.resumeReactContextIfHostResumed(
reactContext, mActivity.get());
reactContext, getCurrentActivity());
}

ReactInstanceEventListener[] listeners =
Expand Down Expand Up @@ -1010,7 +1015,7 @@ private Task<ReactInstance> oldGetOrCreateReactInstanceTask() {
aligns with the bridge https://fburl.com/diffusion/2qhxmudv.
*/
mReactLifecycleStateManager.resumeReactContextIfHostResumed(
reactContext, mActivity.get());
reactContext, getCurrentActivity());

ReactInstanceEventListener[] listeners =
new ReactInstanceEventListener[mReactInstanceEventListeners.size()];
Expand Down Expand Up @@ -1382,7 +1387,7 @@ private Task<Void> newGetOrCreateDestroyTask(final String reason, @Nullable Exce
}

// Reset current activity
mActivity.set(null);
setCurrentActivity(null);

// Clear ResourceIdleDrawableIdMap
ResourceDrawableIdHelper.getInstance().clear();
Expand Down

0 comments on commit d031f57

Please sign in to comment.