Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conditional return in handleRemoveView #43389

Conversation

bartlomiejbloniarz
Copy link
Contributor

Summary:

I was recently working on an issue 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

Test Plan:

I tested if the rn-tester app behaves correctly after those changes.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Mar 8, 2024
@javache
Copy link
Member

javache commented Mar 8, 2024

Does this issue only affect the old architecture or does it repro on the new arch too? (zonder is handled differently there)

@analysis-bot
Copy link

analysis-bot commented Mar 8, 2024

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 18,012,530 -40,959
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 21,371,043 -36,878
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 1ea269f
Branch: main

@bartlomiejbloniarz
Copy link
Contributor Author

I tested it only on the old architecture, but I think this issue should only be present there.

@fabriziocucci
Copy link
Contributor

Hey @bartlomiejbloniarz, thanks for submitting this! 🙂

I was just trying to repro on a physical Android device using rn-tester and your Expo snack but I've encountered a couple of problems:

  1. when running react-native run-android --mode HermesDebug I'm hitting this as soon I tap on the Trigger Layout Animation button:
  1. when running react-native run-android --mode JscDebug, I can't repro the issue!

NOTE: the react-native-reanimated is the one in the Expo snack, i.e. 3.6.2.

Do you happen to have a branch where you added an exemple in rn-tester for testing purposes?

@bartlomiejbloniarz
Copy link
Contributor Author

Hi @fabriziocucci. There might have been a small miscommunication on my part. I tested the code from the snack only within our ReanimatedExampleApp. Then I applied those changes in the forked react-native repo and tested if the rn-tester app still behaves correctly (i.e. if views are removed normally).

After some testing I think the issue that you are seeing is caused by the fact that our compatibility with bridgeless is still work in progress, so using reanmiated in the rn-tester app will produce those errors.

@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@javache merged this pull request in 0d7a92b.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 14, 2024
rozele added a commit to rozele/react-native-macos that referenced this pull request Mar 10, 2025
Summary:

This appears to fix an issue where removing a sibling with zIndex breaks drawing of the next sibling. The theory is that eager return in `onViewRemoved` prevents the view from reverting into a state where it no longer uses custom draw order. However, tracing back history, this eager return was [added](facebook#43389) to fix a bug in Reanimated. cc bartlomiejbloniarz to confirm if [this Reanimated issue](software-mansion/react-native-reanimated#5715) resurfaces from this change.

Fixes facebook#49838

## Changelog

[Android][Fixed] Fixes issue with z-indexed sibling removal

Differential Revision: D70795631
facebook-github-bot pushed a commit that referenced this pull request Mar 10, 2025
Summary:
Pull Request resolved: #49900

This appears to fix an issue where removing a sibling with zIndex breaks drawing of the next sibling. The theory is that eager return in `onViewRemoved` prevents the view from reverting into a state where it no longer uses custom draw order. However, tracing back history, this eager return was [added](#43389) to fix a bug in Reanimated. cc bartlomiejbloniarz to confirm if [this Reanimated issue](software-mansion/react-native-reanimated#5715) resurfaces from this change.

Fixes #49838

## Changelog

[Android][Fixed] Fixes issue with z-indexed sibling removal

Reviewed By: NickGerleman, cipolleschi

Differential Revision: D70795631

fbshipit-source-id: 500af92226be29af73f36f911ffff27a0c083ae9
react-native-bot pushed a commit that referenced this pull request Apr 1, 2025
Summary:
Pull Request resolved: #49900

This appears to fix an issue where removing a sibling with zIndex breaks drawing of the next sibling. The theory is that eager return in `onViewRemoved` prevents the view from reverting into a state where it no longer uses custom draw order. However, tracing back history, this eager return was [added](#43389) to fix a bug in Reanimated. cc bartlomiejbloniarz to confirm if [this Reanimated issue](software-mansion/react-native-reanimated#5715) resurfaces from this change.

Fixes #49838

## Changelog

[Android][Fixed] Fixes issue with z-indexed sibling removal

Reviewed By: NickGerleman, cipolleschi

Differential Revision: D70795631

fbshipit-source-id: 500af92226be29af73f36f911ffff27a0c083ae9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants