LifecycleAwareAnimationController
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 if 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
Functions
Ends all ongoing animations. This will cancel the animation and invoke the AnimationListener.onAnimationEnd on the animationListener.
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.
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.