Package 

Interface LottieAnimatable

  • All Implemented Interfaces:
    androidx.compose.runtime.State , com.airbnb.lottie.compose.LottieAnimationState

    @Stable() 
    public interface LottieAnimatable
     implements LottieAnimationState
                        

    LottieAnimatable is an extension of LottieAnimationState that contains imperative suspend functions to control animation playback.

    To create one, call:

    val animatable = rememberLottieAnimatable()

    This is the imperative version of animateLottieCompositionAsState.

    LottieAnimationState ensures mutual exclusiveness on its animations. To achieve this, when a new animation is started via animate or snapTo, any ongoing animation will be canceled via a CancellationException. Because of this, it is possible that your animation will not start synchronously. As a result, if you switch from animating one composition to another, it is not safe to render the second composition immediately after calling animate. Instead, you should always rely on LottieAnimationState.composition and LottieAnimationState.progress.

    This class is comparable to androidx.compose.animation.core.Animatable. It is a relatively low-level API that gives maximum control over animations. In most cases, you can use animateLottieCompositionAsState which provides declarative APIs to create, update, and animate a LottieComposition.

    • Method Detail

      • snapTo

         abstract Unit snapTo(LottieComposition composition, Float progress, Integer iteration, Boolean resetLastFrameNanos)

        Snap to a specific point in an animation. This can be used to update the progress or iteration count of an ongoing animation. It will cancel any ongoing animations on this state class. To update and then resume an animation, call animate again with continueFromPreviousAnimate set to true after calling snapTo.

        Parameters:
        composition - The LottieComposition that should be rendered.
        progress - The progress that should be set.
        iteration - Updates the current iteration count.
        resetLastFrameNanos - rememberLottieAnimatable keeps track of the frame time of the most recent animation.
      • animate

         abstract Unit animate(LottieComposition composition, Integer iteration, Integer iterations, Boolean reverseOnRepeat, Float speed, LottieClipSpec clipSpec, Float initialProgress, Boolean continueFromPreviousAnimate, LottieCancellationBehavior cancellationBehavior, Boolean ignoreSystemAnimationsDisabled, Boolean useCompositionFrameRate)

        Animate a LottieComposition.

        Parameters:
        composition - The LottieComposition that should be rendered.
        iteration - The iteration to start the animation at.
        iterations - The number of iterations to continue running for.
        speed - The speed at which the composition should be animated.
        clipSpec - An optional LottieClipSpec to trim the playback of the composition between two values.
        initialProgress - An optional progress value that the animation should start at.
        continueFromPreviousAnimate - When set to true, instead of starting at the minimum progress, the initial progress will be advanced in accordance to the amount of time that has passed since the last frame was rendered.
        cancellationBehavior - The behavior that this animation should have when cancelled.
        ignoreSystemAnimationsDisabled - When set to true, the animation will animate even if animations are disabled at the OS level.
        useCompositionFrameRate - Lottie files can specify a target frame rate.