Skip to content

Conversation

janicduplessis
Copy link
Contributor

Fix a bug that happens when views are added and removed in the same manageChildren block with a delete animation. What happens is that the inserted view is not inserted at the proper index if the deleted view index is smaller than the inserted one. This is because the view is not immediately removed from the subviews array so we need to offset the insert index for each view that is going to be deleted with an animation and is before the inserted view.

To do this I separated _removeChildren into 2 different functions, one for animated delete and one for normal delete. The animated one returns an array of RCTComponent that are going to be animated. We can then use this array to offset the insert index.

Test plan (required)
Tested that this fixed the bug in an app where I noticed it, also tested the UIExplorer example to make sure LayoutAnimations still worked properly.

@ghost ghost added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jun 6, 2016
@janicduplessis
Copy link
Contributor Author

Cc @sahrens @nicklockwood

@ghost
Copy link

ghost commented Jun 7, 2016

@janicduplessis updated the pull request.

@nicklockwood
Copy link
Contributor

@facebook-github-bot shipit

@ghost ghost added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Jun 10, 2016
@ghost
Copy link

ghost commented Jun 10, 2016

Thanks for importing. If you are an FB employee go to Phabricator to review.

@nicklockwood
Copy link
Contributor

nicklockwood commented Jun 10, 2016

I made a couple of small changes such as using an NSMutableSet instead of an array for the deleted views (which means calling containsObject: should be O(1) instead of O(n)), and added a couple of checks to make sure it wasn't being accessed on the shadow thread.

I verified everything is fine for our use cases, but it would be very helpful if you could put up another PR to add/extend the example to include the scenario you encountered, since we don't have any tests for that.

In particular, the code path for the scenario where views are added and removed in the same cycle seems like it could do with some test coverage.

@ghost ghost closed this in 6236a59 Jun 10, 2016
bestander added a commit to bestander/react-native that referenced this pull request Jun 10, 2016
@bestander
Copy link
Contributor

Hey Janic,

I just had to unland the PR because it modified the snapshot tests and it looks like a break.

You can see how the snapshot tests got changed: https://github.com/facebook/react-native/pull/8048/files
Although it is not your fault, the tests were passing in the CI when you submitted the PR.
The break was introduced by Nick with his small changes.

Nick is not available to investigate this at this moment, would you be able to incorporate Nick's changes and investigate why the layout got broken?

Thanks,

@janicduplessis
Copy link
Contributor Author

@bestander Is it possible that this is related to one of the commits that landed right before this one? As far as I can tell there are 2 that seems related to text and by the snapshot test image it seems that is what changed.

@janicduplessis
Copy link
Contributor Author

@nicklockwood I'll try to add some integration tests to layout animation soon as well as modify the UIExplorer example to have a more complex example that used to break without this fix.

@bestander
Copy link
Contributor

Hey @janicduplessis, you are right.
Stupid Travis did not indicate that it aggregated a few commits.
Sorry for confusion, I'll un unland and deal with the breaking change.

bubblesunyum pushed a commit to iodine/react-native that referenced this pull request Aug 23, 2016
…the same time

Summary:
Fix a bug that happens when views are added and removed in the same manageChildren block with a delete animation. What happens is that the inserted view is not inserted at the proper index if the deleted view index is smaller than the inserted one. This is because the view is not immediately removed from the subviews array so we need to offset the insert index for each view that is going to be deleted with an animation and is before the inserted view.

To do this I separated `_removeChildren` into 2 different functions, one for animated delete and one for normal delete. The animated one returns an array of `RCTComponent` that are going to be animated. We can then use this array to offset the insert index.

**Test plan (required)**
Tested that this fixed the bug in an app where I noticed it, also tested the UIExplorer example to make sure LayoutAnimations still worked properly.
Closes facebook#7942

Differential Revision: D3417194

Pulled By: nicklockwood

fbshipit-source-id: 790f4ac15a8552323b359e6466cecfa80418c63c
bubblesunyum pushed a commit to iodine/react-native that referenced this pull request Aug 23, 2016
Summary:
Fix a bug that happens when views are added and removed in the same manageChildren block with a delete animation. What happens is that the inserted view is not inserted at the proper index if the deleted view index is smaller than the inserted one. This is because the view is not immediately removed from the subviews array so we need to offset the insert index for each view that is going to be deleted with an animation and is before the inserted view.

To do this I separated `_removeChildren` into 2 different functions, one for animated delete and one for normal delete. The animated one returns an array of `RCTComponent` that are going to be animated. We can then use this array to offset the insert index.

**Test plan (required)**
Tested that this fixed the bug in an app where I noticed it, also tested the UIExplorer example to make sure LayoutAnimations still worked properly.
Closes facebook#7942

Differential Revision: D3417194

Pulled By: bestander

fbshipit-source-id: 9145a783e520c6718dd023a1e006646acb09cb7c
mpretty-cyro pushed a commit to HomePass/react-native that referenced this pull request Aug 25, 2016
…the same time

Summary:
Fix a bug that happens when views are added and removed in the same manageChildren block with a delete animation. What happens is that the inserted view is not inserted at the proper index if the deleted view index is smaller than the inserted one. This is because the view is not immediately removed from the subviews array so we need to offset the insert index for each view that is going to be deleted with an animation and is before the inserted view.

To do this I separated `_removeChildren` into 2 different functions, one for animated delete and one for normal delete. The animated one returns an array of `RCTComponent` that are going to be animated. We can then use this array to offset the insert index.

**Test plan (required)**
Tested that this fixed the bug in an app where I noticed it, also tested the UIExplorer example to make sure LayoutAnimations still worked properly.
Closes facebook#7942

Differential Revision: D3417194

Pulled By: nicklockwood

fbshipit-source-id: 790f4ac15a8552323b359e6466cecfa80418c63c
mpretty-cyro pushed a commit to HomePass/react-native that referenced this pull request Aug 25, 2016
Summary:
Fix a bug that happens when views are added and removed in the same manageChildren block with a delete animation. What happens is that the inserted view is not inserted at the proper index if the deleted view index is smaller than the inserted one. This is because the view is not immediately removed from the subviews array so we need to offset the insert index for each view that is going to be deleted with an animation and is before the inserted view.

To do this I separated `_removeChildren` into 2 different functions, one for animated delete and one for normal delete. The animated one returns an array of `RCTComponent` that are going to be animated. We can then use this array to offset the insert index.

**Test plan (required)**
Tested that this fixed the bug in an app where I noticed it, also tested the UIExplorer example to make sure LayoutAnimations still worked properly.
Closes facebook#7942

Differential Revision: D3417194

Pulled By: bestander

fbshipit-source-id: 9145a783e520c6718dd023a1e006646acb09cb7c
@nihgwu
Copy link
Contributor

nihgwu commented Sep 8, 2016

I'm suffering this issue for quite a long time, why not reopen this as it has been reverted @janicduplessis

@janicduplessis
Copy link
Contributor Author

It was shipped again but I think there are still other issues with this but I haven't had the time to look into it.

@facebook-github-bot facebook-github-bot added the Contributor A React Native contributor. label Apr 15, 2024
This pull request was closed.
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. Contributor A React Native contributor. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants