Skip to content

Commit cd43de6

Browse files
wschurmanhuntie
authored andcommitted
Fix android root view group removal during instance re-creation (#41678)
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
1 parent 0d5e678 commit cd43de6

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,14 +1278,12 @@ private void detachRootViewFromInstance(ReactRoot reactRoot, ReactContext reactC
12781278
uiManager.stopSurface(surfaceId);
12791279
} else {
12801280
FLog.w(ReactConstants.TAG, "Failed to stop surface, UIManager has already gone away");
1281-
reactRoot.getRootViewGroup().removeAllViews();
12821281
}
12831282
} else {
12841283
ReactSoftExceptionLogger.logSoftException(
12851284
TAG,
12861285
new RuntimeException(
12871286
"detachRootViewFromInstance called with ReactRootView with invalid id"));
1288-
reactRoot.getRootViewGroup().removeAllViews();
12891287
}
12901288
} else {
12911289
reactContext
@@ -1294,8 +1292,7 @@ private void detachRootViewFromInstance(ReactRoot reactRoot, ReactContext reactC
12941292
.unmountApplicationComponentAtRootTag(reactRoot.getRootViewTag());
12951293
}
12961294

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

13011298
@ThreadConfined(UI)

0 commit comments

Comments
 (0)