-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
/
LottieIdlingAnimationResource.kt
33 lines (25 loc) · 1.09 KB
/
LottieIdlingAnimationResource.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.airbnb.lottie.samples
import android.animation.Animator
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.IdlingResource
import com.airbnb.lottie.LottieAnimationView
class LottieIdlingAnimationResource(animationView: LottieAnimationView, private val name: String = "Lottie") : IdlingResource {
private var hasEnded = false
private var callback: IdlingResource.ResourceCallback? = null
init {
animationView.addAnimatorListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
hasEnded = true
callback?.onTransitionToIdle()
animationView.removeAllAnimatorListeners()
IdlingRegistry.getInstance().unregister(this@LottieIdlingAnimationResource)
}
})
}
override fun getName() = name
override fun isIdleNow() = hasEnded
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
this.callback = callback
if (isIdleNow) callback?.onTransitionToIdle()
}
}