LifecycleAwareAnimationController

class LifecycleAwareAnimationController(lifecycleOwner: LifecycleOwner)

A utility for keeping animations within the scope of a given lifecycleOwner.

This is useful in cases where the animation is only valid while the animating view is shown, and the animation end action should be performed immediately is the animating view stops being shown. A concrete example of where this is important, is in a system UI that may play an exit animation for a fragment before actually removing the fragment from the stack. If the animation is interrupted by a call to the containing activity's onSaveInstanceState, the fragment cannot be safely removed anymore by the time that the animation finishes.

Constructors

Link copied to clipboard
fun LifecycleAwareAnimationController(lifecycleOwner: LifecycleOwner)

Functions

Link copied to clipboard
fun runAnimation(view: View, animation: Animation, animationListener: Animation.AnimationListener? = null)

Runs animation on view, but only if the controller's lifecycle is in a started state. If the lifecycle is stopped, the animation will not be started and the animation end listener is called immediately.

fun runAnimation(view: View, @AnimRes animationResource: Int, onAnimationEnd: AnimationEndListener? = null)

Runs an animation created through animationResource on view, but only if the controller's lifecycle is in a started state. If the lifecycle is stopped, the animation will not be started and onAnimationEnd is called immediately.