Skip to content

Commit

Permalink
Fix logic for mKeepActivity (#44139)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #44139

I added logic to make useEffect() work w/ fragment-based nav, but I mixed up some logic. Fixed it here
Changelog: [Internal]

Differential Revision: D56264138

fbshipit-source-id: b551f0cb93cb4a0291733edbd341d3508b61e392
  • Loading branch information
janeli-100005636499545 authored and facebook-github-bot committed Apr 18, 2024
1 parent 72e262e commit b580a07
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,9 @@ public void destroy() {
}

mHasStartedCreatingInitialContext = false;
mCurrentActivity = null;
if (!mKeepActivity) {
mCurrentActivity = null;
}

ResourceDrawableIdHelper.getInstance().clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,21 @@ public void onHostPause() {
/** Should be called by the hosting Fragment in {@link Fragment#onDestroy} */
@ThreadConfined(UI)
public void onHostDestroy() {
onHostDestroyImpl();
mCurrentActivity = null;
}

@ThreadConfined(UI)
public void onHostDestroy(boolean keepActivity) {
if (!keepActivity) {
onHostDestroy();
} else {
onHostDestroyImpl();
}
}

@ThreadConfined(UI)
private void onHostDestroyImpl() {
UiThreadUtil.assertOnUiThread();
mLifecycleState = LifecycleState.BEFORE_CREATE;
for (LifecycleEventListener listener : mLifecycleEventListeners) {
Expand All @@ -370,19 +385,6 @@ public void onHostDestroy() {
handleException(e);
}
}
resetCurrentActivity(false);
}

@ThreadConfined(UI)
public void onHostDestroy(boolean keepActivity) {
onHostDestroy();
resetCurrentActivity(keepActivity);
}

private void resetCurrentActivity(boolean keepActivity) {
if (!keepActivity) {
mCurrentActivity = null;
}
}

/** Destroy this instance, making it unusable. */
Expand Down

0 comments on commit b580a07

Please sign in to comment.