Skip to content

Commit

Permalink
Merge pull request #1707 from novasamatech/feature/portfolio-view-ani…
Browse files Browse the repository at this point in the history
…mation-fix

Protfolio view animations fix
  • Loading branch information
antonijzelinskij authored Nov 7, 2024
2 parents afd32c1 + 55910b7 commit 9b058f9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ abstract class ExpandableItemAnimator(
// Reset remove state helps clear alpha and scale when animation is being to be canceled
if (pendingRemoveAnimations.contains(holder)) {
holder.itemView.animate().cancel()
resetRemoveState(holder)
}

if (pendingMoveAnimations.contains(holder)) {
Expand Down Expand Up @@ -219,6 +218,7 @@ abstract class ExpandableItemAnimator(
.setDuration(settings.duration)
.setListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animator: Animator) {
resetRemoveState(holder)
removeFinished(holder)
animation.setListener(null)
}
Expand All @@ -242,13 +242,13 @@ abstract class ExpandableItemAnimator(
}

override fun endAnimations() {
pendingAddAnimations.forEach { it.itemView.animate().cancel() }
pendingAddAnimations.iterator().forEach { it.itemView.animate().cancel() }
pendingAddAnimations.clear()

pendingRemoveAnimations.forEach { it.itemView.animate().cancel() }
pendingRemoveAnimations.iterator().forEach { it.itemView.animate().cancel() }
pendingRemoveAnimations.clear()

pendingMoveAnimations.forEach { it.itemView.animate().cancel() }
pendingMoveAnimations.iterator().forEach { it.itemView.animate().cancel() }
pendingMoveAnimations.clear()

addAnimations.clear()
Expand Down Expand Up @@ -288,5 +288,12 @@ abstract class ExpandableItemAnimator(
if (holder in pendingMoveAnimations) return

dispatchAnimationFinished(holder)
dispatchFinishedWhenDone()
}

private fun dispatchFinishedWhenDone() {
if (!isRunning) {
dispatchAnimationsFinished()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ class AssetTokensDecoration(
children.forEach {
val childrenBottomClipInset = (it.itemView.bottom + it.itemView.translationY.roundToInt()) - childrenBlock.bottom
val childrenTopClipInset = childrenBlock.top - (it.itemView.top + it.itemView.translationY.roundToInt())
if (childrenBottomClipInset > 0) {
if (childrenTopClipInset > 0 || childrenBottomClipInset > 0) {
it.itemView.clipBounds = Rect(
0,
childrenTopClipInset.coerceAtLeast(0),
childrenTopClipInset,
it.itemView.width,
it.itemView.height - childrenBottomClipInset
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import io.novafoundation.nova.common.utils.recyclerView.expandable.ExpandableAni
import io.novafoundation.nova.common.utils.recyclerView.expandable.ExpandableItemAnimator
import io.novafoundation.nova.common.utils.recyclerView.expandable.animator.ExpandableAnimator

private const val REMOVE_SCALE = 0.9f

class AssetTokensItemAnimator(
settings: ExpandableAnimationSettings,
expandableAnimator: ExpandableAnimator
Expand All @@ -15,7 +17,9 @@ class AssetTokensItemAnimator(
) {

override fun preAddImpl(holder: RecyclerView.ViewHolder) {
resetRemoveState(holder)
holder.itemView.alpha = 0f
holder.itemView.scaleX = REMOVE_SCALE
holder.itemView.scaleY = REMOVE_SCALE
}

override fun getAddAnimator(holder: RecyclerView.ViewHolder): ViewPropertyAnimator {
Expand All @@ -32,8 +36,8 @@ class AssetTokensItemAnimator(
override fun getRemoveAnimator(holder: RecyclerView.ViewHolder): ViewPropertyAnimator {
return holder.itemView.animate()
.alpha(0f)
.scaleX(0.90f)
.scaleY(0.90f)
.scaleX(REMOVE_SCALE)
.scaleY(REMOVE_SCALE)
}

override fun preMoveImpl(holder: RecyclerView.ViewHolder, fromY: Int, toY: Int) {
Expand All @@ -50,7 +54,6 @@ class AssetTokensItemAnimator(
super.endAnimation(viewHolder)

viewHolder.itemView.translationY = 0f
viewHolder.itemView.alpha = 0f
viewHolder.itemView.alpha = 1f
viewHolder.itemView.scaleX = 1f
viewHolder.itemView.scaleY = 1f
Expand All @@ -63,9 +66,9 @@ class AssetTokensItemAnimator(
}

override fun resetRemoveState(holder: RecyclerView.ViewHolder) {
holder.itemView.alpha = 0f
holder.itemView.scaleX = 0.90f
holder.itemView.scaleY = 0.90f
holder.itemView.alpha = 1f
holder.itemView.scaleX = 1f
holder.itemView.scaleY = 1f
}

override fun resetMoveState(holder: RecyclerView.ViewHolder) {
Expand Down

0 comments on commit 9b058f9

Please sign in to comment.