Skip to content

Commit

Permalink
Fix android root view group removal during instance re-creation (#41678)
Browse files Browse the repository at this point in the history
Summary:
This is my proposed solution to #41677.

Fixes #41677.

## Changelog:

[ANDROID] [FIXED] - Fix android root view group removal during instance re-creation

Pull Request resolved: #41678

Test Plan:
Both with fabric enabled and disabled (new architecture):

1. Clone repro repo: https://github.com/wschurman/rn-reload-repro
2. Build and run on android (I use android studio)
3. Click reload button, see timestamp doesn't change (indicating that the view is not removed)
4. Apply this PR as a patch.
5. Re-build and run.
6. Click reload button, see view is correctly disposed of and the new view is set.

Reviewed By: cortinico

Differential Revision: D51658524

Pulled By: javache

fbshipit-source-id: d9a026cde677ad1ec113230bc31bd9297bca8bfc
  • Loading branch information
wschurman authored and facebook-github-bot committed Nov 29, 2023
1 parent dc95568 commit bb075d7
Showing 1 changed file with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1296,14 +1296,12 @@ private void detachRootViewFromInstance(ReactRoot reactRoot, ReactContext reactC
uiManager.stopSurface(surfaceId);
} else {
FLog.w(ReactConstants.TAG, "Failed to stop surface, UIManager has already gone away");
reactRoot.getRootViewGroup().removeAllViews();
}
} else {
ReactSoftExceptionLogger.logSoftException(
TAG,
new RuntimeException(
"detachRootViewFromInstance called with ReactRootView with invalid id"));
reactRoot.getRootViewGroup().removeAllViews();
}
} else {
reactContext
Expand All @@ -1312,8 +1310,7 @@ private void detachRootViewFromInstance(ReactRoot reactRoot, ReactContext reactC
.unmountApplicationComponentAtRootTag(reactRoot.getRootViewTag());
}

// The view is no longer attached, so mark it as such by resetting its ID.
reactRoot.getRootViewGroup().setId(View.NO_ID);
clearReactRoot(reactRoot);
}

@ThreadConfined(UI)
Expand Down

0 comments on commit bb075d7

Please sign in to comment.