animateChange

Called by the RecyclerView when an adapter item is present both before and after the layout and RecyclerView has received a notifyItemChanged call for it. This method may also be called when notifyDataSetChanged is called and adapter has stable ids so that RecyclerView could still rebind views to the same ViewHolders. If viewType changes when notifyDataSetChanged is called, this method will not be called, instead, animateAppearance will be called for the new ViewHolder and the old one will be recycled.

If this method is called due to a notifyDataSetChanged call, there is a good possibility that item contents didn't really change but it is rebound from the adapter. DefaultItemAnimator will skip animating the View if its location on the screen didn't change and your animator should handle this case as well and avoid creating unnecessary animations.

When an item is updated, ItemAnimator has a chance to ask RecyclerView to keep the previous presentation of the item as-is and supply a new ViewHolder for the updated presentation (see: canReuseUpdatedViewHolder. This is useful if you don't know the contents of the Item and would like to cross-fade the old and the new one (DefaultItemAnimator uses this technique).

When you are writing a custom item animator for your layout, it might be more performant and elegant to re-use the same ViewHolder and animate the content changes manually.

When notifyItemChanged is called, the Item's view type may change. If the Item's view type has changed or ItemAnimator returned false for this ViewHolder when canReuseUpdatedViewHolder was called, the oldHolder and newHolder will be different ViewHolder instances which represent the same Item. In that case, only the new ViewHolder is visible to the LayoutManager but RecyclerView keeps old ViewHolder attached for animations.

ItemAnimator must call dispatchAnimationFinished for each distinct ViewHolder when their animation is complete (or instantly call dispatchAnimationFinished if it decides not to animate the view).

If oldHolder and newHolder are the same instance, you should call dispatchAnimationFinishedonly once.

Note that when a ViewHolder both changes and disappears in the same layout pass, the animation callback method which will be called by the RecyclerView depends on the ItemAnimator's decision whether to re-use the same ViewHolder or not, and also the LayoutManager's decision whether to layout the changed version of a disappearing ViewHolder or not. RecyclerView will call animateChange instead of animateDisappearance if and only if the ItemAnimator returns false from canReuseUpdatedViewHolder and the LayoutManager lays out a new disappearing view that holds the updated information. Built-in LayoutManagers try to avoid laying out updated versions of disappearing views.

Return

true if a later call to runPendingAnimations is requested, false otherwise.

Parameters

oldHolder

The ViewHolder before the layout is started, might be the same instance with newHolder.

newHolder

The ViewHolder after the layout is finished, might be the same instance with oldHolder.

preLayoutInfo

The information that was returned from recordPreLayoutInformation.

postLayoutInfo

The information that was returned from recordPreLayoutInformation.


abstract fun animateChange(oldHolder: RecyclerView.ViewHolder, newHolder: RecyclerView.ViewHolder, fromLeft: Int, fromTop: Int, toLeft: Int, toTop: Int): Boolean(source)

Called when an item is changed in the RecyclerView, as indicated by a call to notifyItemChanged or notifyItemRangeChanged.

Implementers can choose whether and how to animate changes, but must always call dispatchChangeFinished for each non-null distinct ViewHolder, either immediately (if no animation will occur) or after the animation actually finishes. If the oldHolder is the same ViewHolder as the newHolder, you must call dispatchChangeFinished once and only once. In that case, the second parameter of dispatchChangeFinished is ignored.

The return value indicates whether an animation has been set up and whether the ItemAnimator's runPendingAnimations method should be called at the next opportunity. This mechanism allows ItemAnimator to set up individual animations as separate calls to animateAdd(), animateMove(), animateRemove(), and animateChange come in one by one, then start the animations together in the later call to runPendingAnimations.

Return

true if a later call to runPendingAnimations is requested, false otherwise.

Parameters

oldHolder

The original item that changed.

newHolder

The new item that was created with the changed content. Might be null

fromLeft

Left of the old view holder

fromTop

Top of the old view holder

toLeft

Left of the new view holder

toTop

Top of the new view holder