Skip to content

Commit

Permalink
Prevent onStart from happening before onCancel in circular reveal ani…
Browse files Browse the repository at this point in the history
…mation. Fixes #7
  • Loading branch information
Bryanx committed Jul 2, 2020
1 parent de4e622 commit 0ea26e3
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class ThemedToggleButtonGroup : FlexboxLayout {

private var deselectAnimator: Animator? = AnimatorSet()

private lateinit var animatorSet: AnimatorSet

/**
* The amount of space between the [buttons] when they are positioned next to each other.
* Default is 10dp.
Expand Down Expand Up @@ -113,11 +115,13 @@ class ThemedToggleButtonGroup : FlexboxLayout {
}

private fun startAnimations() {
if (this::animatorSet.isInitialized && animatorSet.isRunning) animatorSet.cancel()
try {
val set = AnimatorSet()
if (deselectAnimator != null) set.playTogether(selectAnimator, deselectAnimator)
else set.play(selectAnimator)
set.start()
animatorSet = AnimatorSet()
animatorSet.startDelay = 5 //small start delay to make sure onStart always happens before onCancel
if (deselectAnimator != null) animatorSet.playTogether(selectAnimator, deselectAnimator)
else animatorSet.play(selectAnimator)
animatorSet.start()
} catch (e: Exception) { /* catch exceptions caused by unfinished animations */ }
}

Expand Down

0 comments on commit 0ea26e3

Please sign in to comment.