Skip to content

Instantly share code, notes, and snippets.

@PhongHuynh93
Created July 2, 2021 15:23
Show Gist options
  • Save PhongHuynh93/3098f5a6e8cd7a23a67687be5803b361 to your computer and use it in GitHub Desktop.
Save PhongHuynh93/3098f5a6e8cd7a23a67687be5803b361 to your computer and use it in GitHub Desktop.
runAnimation
private fun runAnimation(isReverse: Boolean): AnimatorSet {
val values = if (isReverse) {
floatArrayOf(1f, 0f)
} else {
floatArrayOf(0f, 1f)
}
val animatorList = listOf(
ValueAnimator.ofFloat(*values).apply {
addUpdateListener {
colorBgFraction = it.animatedValue as Float
colorTextFraction = it.animatedValue as Float
invalidate()
}
},
ValueAnimator.ofFloat(*values).apply {
addUpdateListener {
scaleTextFraction = it.animatedValue as Float
morphFraction = it.animatedValue as Float
invalidate()
}
},
ValueAnimator.ofFloat(*values).apply {
addUpdateListener {
scaleIconFraction = it.animatedValue as Float
invalidate()
}
}
).let {
if (isReverse) {
it.reversed()
} else {
it
}
}
return AnimatorSet().apply {
playSequentially(
animatorList
)
interpolator = FastOutSlowInInterpolator()
doOnStart {
this@MorphButton.uiState = UIState.Animating
}
duration = 250L
start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment