Skip to content

Commit

Permalink
Merge pull request #237 from rubensousa/viewholder_animations
Browse files Browse the repository at this point in the history
Cancel animations in onViewDetachedFromWindow since they prevent ViewHolders from being recycled
  • Loading branch information
rubensousa authored Jul 10, 2024
2 parents 2150cf5 + 33166f9 commit b630502
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class NestedComposeListAdapter(
holder.item?.let {
scrollState.save(holder.getRecyclerView(), it.diffId)
}
}

override fun onViewDetachedFromWindow(holder: NestedComposeListViewHolder) {
super.onViewDetachedFromWindow(holder)
holder.cancelAnimations()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ class HorizontalListAdapter(
holder.recycle()
}

override fun onViewDetachedFromWindow(holder: HorizontalListViewHolder) {
holder.cancelAnimations()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class HorizontalListViewHolder(
animator.startDeselectionAnimation()
}

fun cancelAnimations() {
animator.cancel()
}

override fun getSubPositionAlignments(): List<SubPositionAlignment> {
return alignments
}
Expand Down

0 comments on commit b630502

Please sign in to comment.