Skip to content

Commit 0d7a92b

Browse files
Add conditional return in handleRemoveView (#43389)
Summary: I was recently working on an [issue](software-mansion/react-native-reanimated#5715) in Reanimated where z-index of some views was broken after a Layout Animation was used. The issue was that in some cases we were calling the `removeView` function on a already removed view. On plain Android this wouldn't be an issue, since the `removeView` function ignores such calls. Unfortunately, the `ReactViewGroup.java` implementation maintains a counter of views with user defined z-index. This counter is decremented whenever a call to `removeView` is made, even if the view is not a child of this `ViewGroup`. This PR adds an additional check in the `handleRemoveView` function to unify the `removeView` behavior between Android and react-native. ## Changelog: [ANDROID] [CHANGED] - Changed the `handleRemoveView` function in `ReactViewGroup.java` to ignore calls for `Views` that are not children of this `ViewGroup` Pull Request resolved: #43389 Test Plan: I tested if the `rn-tester` app behaves correctly after those changes. Reviewed By: NickGerleman Differential Revision: D54874780 Pulled By: javache fbshipit-source-id: f1a34947419ef6106ee73b196ae99b7f8c2f7a77
1 parent 47a3f52 commit 0d7a92b

File tree

1 file changed

+3
-0
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view

1 file changed

+3
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java

+3
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ private void handleRemoveView(View view) {
519519
UiThreadUtil.assertOnUiThread();
520520

521521
if (!customDrawOrderDisabled()) {
522+
if (indexOfChild(view) == -1) {
523+
return;
524+
}
522525
getDrawingOrderHelper().handleRemoveView(view);
523526
setChildrenDrawingOrderEnabled(getDrawingOrderHelper().shouldEnableCustomDrawingOrder());
524527
} else {

0 commit comments

Comments
 (0)