Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.

mLayoutAnimator.addViewAnimatingDeletion(viewToRemove);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should happen automatically within the LayoutAnimation code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to do that initially but I need to do this before the code that add views.

I could move up the block of code that drop views and start the layout animation before adding views.

Now: remove -> add -> drop
After: remove -> drop -> add

} else {
viewManager.removeViewAt(viewToManage, indexToRemove);
}
Expand All @@ -375,7 +376,20 @@ public void manageChildren(
viewsToAdd,
tagsToDelete));
}
viewManager.addView(viewToManage, viewToAdd, viewAtIndex.mIndex);

// When performing layout delete animations views are not removed immediately
// from their container so we need to offset the insert index if a view
// that is going to be removed is before the view we want to insert.
int addViewIndex = viewAtIndex.mIndex;
if (mLayoutAnimator.isAnimatingViewDeletion()) {
for(int index = 0; index < viewAtIndex.mIndex; index++) {
if (mLayoutAnimator.isViewAnimatingDeletion(viewManager.getChildAt(viewToManage, index))) {
addViewIndex++;
}
}
}

viewManager.addView(viewToManage, viewToAdd, addViewIndex);
}
}

Expand All @@ -399,6 +413,7 @@ public void manageChildren(
mLayoutAnimator.deleteView(viewToDestroy, new LayoutAnimationListener() {
@Override
public void onAnimationEnd() {
mLayoutAnimator.removeViewAnimatingDeletion(viewToDestroy);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with this

viewManager.removeView(viewToManage, viewToDestroy);
dropView(viewToDestroy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

package com.facebook.react.uimanager.layoutanimation;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

Expand Down Expand Up @@ -29,6 +32,8 @@ public class LayoutAnimationController {
private final AbstractLayoutAnimation mLayoutDeleteAnimation = new LayoutDeleteAnimation();
private boolean mShouldAnimateLayout;

private List<View> mDeleteAnimatedViews = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

May as well use a bitset and index by tag, right?


public void initializeFromConfig(final @Nullable ReadableMap config) {
if (!ENABLED) {
return;
Expand Down Expand Up @@ -138,6 +143,41 @@ public void onAnimationEnd(Animation anim) {
}
}

/**
* Add a view to list of views that are being deleted with an animation.
*
* @param view View to add
*/
public void addViewAnimatingDeletion(View view) {
mDeleteAnimatedViews.add(view);
}

/**
* Remove a view to list of views that are being deleted with an animation.
*
* @param view View to remove
*/
public void removeViewAnimatingDeletion(View view) {
mDeleteAnimatedViews.remove(view);
}

/**
* Returns if the view is being deleted with an animation.
*
* @param view View to check
* @return If it is being animated
*/
public boolean isViewAnimatingDeletion(View view) {
return mDeleteAnimatedViews.contains(view);
}

/**
* Returns if there are any view being deleted with an animation.
*/
public boolean isAnimatingViewDeletion() {
return mDeleteAnimatedViews.size() > 0;
}

/**
* Disables user interactions for a view and all it's subviews.
*/
Expand Down