Skip to content

Fix LayoutAnimation Android bug when adding and removing views at the same time #7959

New issue

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

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

Already on GitHub? # to your account

Conversation

janicduplessis
Copy link
Contributor

Similar to #7942 but for android

Fix a bug that happens when views are added during a delete layout 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.

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
Copy link

ghost commented Jun 6, 2016

By analyzing the blame information on this pull request, we identified @dmmiller and @korDen to be potential reviewers.

@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 @astreet

@@ -352,6 +352,7 @@ public void manageChildren(
arrayContains(tagsToDelete, viewToRemove.getId())) {
// The view will be removed and dropped by the 'delete' layout animation
// instead, so do nothing
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment probably needs to be updated. Since do nothing now looks like doing something.

@astreet
Copy link
Contributor

astreet commented Jun 7, 2016

Kinda unfortunate we have to do this, but I don't see another easy way. Would be amazing if we could add an integration test for this case as well layout animation in general since it seems somewhat easy to break!

@janicduplessis
Copy link
Contributor Author

I found other issues that this doesn't fix so I'll have to debug this more and find a better solution. We may want to consider disabling delete animations for now.

@astreet
Copy link
Contributor

astreet commented Jun 9, 2016

Oli committed a couple fixes for this, not sure if they're relevant to what you were thinking (I'm guessing not, but you might want to rebase?):

bb9ed2d
c0ac0d5

@janicduplessis
Copy link
Contributor Author

Yes I saw those commit but the problem is that views get added at the wrong index when doing some more complex animations. I managed to fix some of the issues by removing views based on their tags instead of their index but this doesn't work for adding views. I'll have to figure out why the index passed to manageChildren are not good.

I'm using this modified UIExplorer example to reproduce this issue https://gist.github.com/janicduplessis/211d78c5408ab17dee7ad2e381648a48 and also increasing the LayoutAnimation duration to make it more obvious.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 12, 2016
@ghost
Copy link

ghost commented Jul 17, 2016

@janicduplessis do you have any updates for this pull request? It's been a while since the last update so wanted to check in and see if you've looked at the requested changes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 17, 2016
@robclouth
Copy link
Contributor

robclouth commented Sep 16, 2016

Any news on this? I'm getting

com.facebook.react.uimanager.IllegalViewOperationException: Trying to remove a view index above child count 0 view tag: 999

When using LayoutAnimation on Android when removing and adding items to a wrapped row.

@robclouth
Copy link
Contributor

Occasionally this too:

java.lang.IndexOutOfBoundsException: index=23 count=22
                                                            at android.view.ViewGroup.addInArray(ViewGroup.java:4027)
                                                            at android.view.ViewGroup.addViewInner(ViewGroup.java:3958)
                                                            at android.view.ViewGroup.addView(ViewGroup.java:3786)
                                                            at android.view.ViewGroup.addView(ViewGroup.java:3727)
                                                            at com.facebook.react.views.view.ReactViewManager.addView(ReactViewManager.java:196)
                                                            at com.facebook.react.views.view.ReactViewManager.addView(ReactViewManager.java:39)
                                                            at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:387)

@hramos
Copy link
Contributor

hramos commented Nov 7, 2016

@janicduplessis still planning to ship this PR?

@janicduplessis
Copy link
Contributor Author

I don't think I'll have time to work on this any time soon, sadly this PR didn't completely fix the issue and I couldn't figure out a way to have a proper fix.

@lacker
Copy link
Contributor

lacker commented Nov 30, 2016

OK, I am going to close this pull request because it seems like everyone is stalled, but if someone wants to continue working on this then please feel free to spin it back up again!

# for free to join this conversation on GitHub. Already have an account? # 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants