-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Closed
Labels
Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.
Description
Description
When remove items with LayoutAnimation, the adjacent views/texts should not be impacted. But they disappear on Android.
In the following screenshot of the sample app, we can see some texts/buttons disappeared when we press Remove with opacity animation
button and Remove with scaleXY animation
button. I found this issue when I worked on #11769.
Reproduction
Reproduced on rnplay.org https://rnplay.org/apps/JbdOpQ
The sample project I created: https://github.com/vinceyuan/ReactNativeOpacityBugDemo
Solution
N/A
Update on Jan 18, 2017:
I figured out a solution. See below.
Additional Information
- React Native version: 0.33+
- Platform: Android
- Operating System: MacOS
t-fritsch, nico1510, Antoine-C, FatalTouch, dblachut-adb and 1 more
Metadata
Metadata
Assignees
Labels
Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]Removing items with LayoutAnimation causes adjacent views/texts to disappear[/-][+]Removing items with LayoutAnimation causes adjacent views/texts to disappear on Android[/+]vinceyuan commentedon Jan 18, 2017
Cause
When LayoutAnimation is enabled, indices of to-be-removed items are incorrect (to reproduce it, we need to delete at least two items). So the adjacent items are removed. In uimanager/NativeViewHierarchyManager.java#L364-L373 because
indexToRemove
is wrong, we get wrongviewToRemove
.arrayContains(tagsToDelete, viewToRemove.getId())
returnsfalse
. That view is removed immediately inviewManager.removeViewAt(viewToManage, indexToRemove);
.Essential Cause
The essential cause is in uimanager/NativeViewHierarchyOptimizer.java#L278-L285. It gets the index of a
ReactShadowNode
and adds a managing children operation into a queue.Says we want to delete 2 items
i0
andi2
from[i0, i1, i2, i3]
. It creates two operationsop0
andop1
.op0
is created with index0
for deletingi0
, andop1
is created with index1
fori2
.op1
's index is1
, instead of2
, becauseReactShadowNode
ofi0
has been deleted.When LayoutAnimation is not enabled,
NativeViewHierarchyManager
gets the view by index and deletes it in the same sequence. There is no problem in deletingi2
with index1
.But when LayoutAnimation is enabled, the problem happens in deleting
i2
with index1
. Because the animation is running,i0
still exists.i2
's index is2
, instead of1
. So wrong item is deleted. [See Note below]Solution
Skip deleting items by index when LayoutAnimation is enabled. These items will be deleted by correct
tagsToDelete
. PR: #11962It's hard to correct index at uimanager/NativeViewHierarchyOptimizer.java#L278-L285, because we don't know if we are using LayoutAnimation.
Note
Actually it tries to skip deleting in the existing code uimanager/NativeViewHierarchyManager.java#L364-L373. But because the index is wrong,
arrayContains(tagsToDelete, viewToRemove.getId())
is alwaysfalse
.viewManager.removeViewAt(viewToManage, indexToRemove);
is always executed.Question
Why do we need to pass in both index and tag in uimanager/NativeViewHierarchyOptimizer.java#L278-L285? I tried simply using
null
in L283. Removing item with LayoutAnimation works well. But it does not work well without animation. Some views are not removed.hramos commentedon Jul 20, 2017
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
Fix view indices with Android LayoutAnimation
Fix view indices with Android LayoutAnimation
Fix view indices with Android LayoutAnimation
Fix view indices with Android LayoutAnimation
Fix view indices with Android LayoutAnimation