@@ -11,6 +11,7 @@ import android.util.Log
1111import android.view.View
1212import androidx.annotation.ColorInt
1313import androidx.annotation.FloatRange
14+ import androidx.core.animation.addListener
1415import androidx.core.view.ViewCompat
1516import androidx.core.view.isGone
1617import androidx.core.view.isInvisible
@@ -106,15 +107,10 @@ fun View.animateBackgroundColor(duration: Long, @ColorInt colorStart: Int, @Colo
106107 viewPropertyAnimator.addUpdateListener { animation: ValueAnimator ->
107108 backgroundTintListCompat = ColorStateList (empty, intArrayOf(animation.animatedValue as Int ))
108109 }
109- viewPropertyAnimator.addListener(object : AnimatorListenerAdapter () {
110- override fun onAnimationEnd (animation : Animator ) {
111- backgroundTintListCompat = ColorStateList (empty, intArrayOf(colorEnd))
112- }
113-
114- override fun onAnimationCancel (animation : Animator ) {
115- onAnimationEnd(animation)
116- }
117- })
110+ viewPropertyAnimator.addListener(
111+ onCancel = { backgroundTintListCompat = ColorStateList (empty, intArrayOf(colorEnd)) },
112+ onEnd = { backgroundTintListCompat = ColorStateList (empty, intArrayOf(colorEnd)) }
113+ )
118114 viewPropertyAnimator.start()
119115}
120116
@@ -134,17 +130,16 @@ fun View.animateHeight(duration: Long, targetHeight: Int): ValueAnimator {
134130 layoutParams.height = value.toInt()
135131 requestLayout()
136132 }
137- animator.addListener(object : AnimatorListenerAdapter () {
138- override fun onAnimationEnd ( animation : Animator ) {
133+ animator.addListener(
134+ onCancel = {
139135 layoutParams.height = targetHeight
140136 requestLayout()
141- }
142-
143- override fun onAnimationCancel (animation : Animator ) {
137+ },
138+ onEnd = {
144139 layoutParams.height = targetHeight
145140 requestLayout()
146141 }
147- } )
142+ )
148143 animator.start()
149144 return animator
150145}
0 commit comments