Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ open class StackAnimator @JvmOverloads constructor(
@VisibleForTesting
val runningSetRootAnimations: MutableMap<ViewController<*>, AnimatorSet> = HashMap()

fun cancelPushAnimations() = runningPushAnimations.values.forEach(Animator::cancel)
fun cancelPushAnimations() = runningPushAnimations.values.toList().forEach(Animator::cancel)

open fun isChildInTransition(child: ViewController<*>?): Boolean {
return runningPushAnimations.containsKey(child) ||
Expand All @@ -43,9 +43,13 @@ open class StackAnimator @JvmOverloads constructor(
}

fun cancelAllAnimations() {
val animations = runningPushAnimations.values +
runningPopAnimations.values +
runningSetRootAnimations.values
runningPushAnimations.clear()
runningPopAnimations.clear()
runningSetRootAnimations.clear()
animations.forEach(Animator::cancel)
}

fun setRoot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,32 @@ class StackAnimatorTest : BaseTest() {
assertThat(uut.isChildInTransition(child3)).isTrue()
}

@Test
fun cancelAllAnimations_cancelsRunningAnimatorsWithoutCompletingCommands() {
val onAnimationEnd = mock<Runnable>()
uut.push(child2, child1, Options.EMPTY, emptyList(), onAnimationEnd)

uut.cancelAllAnimations()

verify(commandAnimator).cancel()
verify(onAnimationEnd, never()).run()
assertThat(uut.isChildInTransition(child2)).isFalse()
}

@Test
fun cancelPushAnimations_cancelsEveryRunningAnimator() {
uut.push(child2, child1, Options.EMPTY, emptyList(), mock())
val firstAnimator = uut.runningPushAnimations[child2]!!
val child3 = SimpleViewController(activity, mock(), "child3", Options())
uut.push(child3, child2, Options.EMPTY, emptyList(), mock())
val secondAnimator = uut.runningPushAnimations[child3]!!

uut.cancelPushAnimations()

verify(firstAnimator).cancel()
verify(secondAnimator).cancel()
}

private fun mockViewController(): ViewController<*> {
val vc = mock<ViewController<*>>()
val view = FrameLayout(activity)
Expand Down Expand Up @@ -240,4 +266,4 @@ class StackAnimatorTest : BaseTest() {
vc.mergeOptions(this)
}
}
}
}