Skip to content

Instantly share code, notes, and snippets.

@sabiou
Forked from nikhilpanju/getValueAnimator.kt
Created December 16, 2019 23:46
Show Gist options
  • Save sabiou/d3f40661b3c89a1c4635ef46e478aad8 to your computer and use it in GitHub Desktop.
Save sabiou/d3f40661b3c89a1c4635ef46e478aad8 to your computer and use it in GitHub Desktop.
inline fun getValueAnimator(forward: Boolean = true, duration: Long, interpolator: TimeInterpolator,
crossinline updateListener: (progress: Float) -> Unit
): ValueAnimator {
val a =
if (forward) ValueAnimator.ofFloat(0f, 1f)
else ValueAnimator.ofFloat(1f, 0f)
a.addUpdateListener { updateListener(it.animatedValue as Float) }
a.duration = duration
a.interpolator = interpolator
return a
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment