{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

VectorizedRepeatableSpec

public final class VectorizedRepeatableSpec<V extends AnimationVector> implements VectorizedFiniteAnimationSpec


This animation takes another VectorizedDurationBasedAnimationSpec and plays it iterations times. For infinitely repeating animation spec, VectorizedInfiniteRepeatableSpec is recommended.

Note: When repeating in the RepeatMode.Reverse mode, it's highly recommended to have an odd number of iterations. Otherwise, the animation may jump to the end value when it finishes the last iteration.

initialStartOffset can be used to either delay the start of the animation or to fast forward the animation to a given play time. This start offset will not be repeated, whereas the delay in the animation (if any) will be repeated. By default, the amount of offset is 0.

Summary

Public constructors

<V extends AnimationVector> VectorizedRepeatableSpec(
    int iterations,
    @NonNull VectorizedDurationBasedAnimationSpec<@NonNull V> animation,
    @NonNull RepeatMode repeatMode,
    @NonNull StartOffset initialStartOffset
)

Public methods

long
getDurationNanos(
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

Calculates the duration of an animation.

@NonNull V
getValueFromNanos(
    long playTimeNanos,
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.

@NonNull V
getVelocityFromNanos(
    long playTimeNanos,
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.

Inherited methods

From androidx.compose.animation.core.VectorizedAnimationSpec
@NonNull V
getEndVelocity(
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

Calculates the end velocity of the animation with the provided start/end values, and start velocity.

From androidx.compose.animation.core.VectorizedFiniteAnimationSpec
boolean

Whether or not the VectorizedAnimationSpec specifies an infinite animation.

Public constructors

VectorizedRepeatableSpec

public <V extends AnimationVector> VectorizedRepeatableSpec(
    int iterations,
    @NonNull VectorizedDurationBasedAnimationSpec<@NonNull V> animation,
    @NonNull RepeatMode repeatMode,
    @NonNull StartOffset initialStartOffset
)
Parameters
int iterations

the count of iterations. Should be at least 1.

@NonNull VectorizedDurationBasedAnimationSpec<@NonNull V> animation

the VectorizedAnimationSpec describing each repetition iteration.

@NonNull RepeatMode repeatMode

whether animation should repeat by starting from the beginning (i.e. RepeatMode.Restart) or from the end (i.e. RepeatMode.Reverse)

@NonNull StartOffset initialStartOffset

offsets the start of the animation

Public methods

getDurationNanos

public long getDurationNanos(
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

Calculates the duration of an animation. For duration-based animations, this will return the pre-defined duration. For physics-based animations, the duration will be estimated based on the physics configuration (such as spring stiffness, damping ratio, visibility threshold) as well as the initialValue, targetValue values, and initialVelocity.

Parameters
@NonNull V initialValue

start value of the animation

@NonNull V targetValue

end value of the animation

@NonNull V initialVelocity

start velocity of the animation

getValueFromNanos

public @NonNullgetValueFromNanos(
    long playTimeNanos,
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.

Parameters
long playTimeNanos

time since the start of the animation

@NonNull V initialValue

start value of the animation

@NonNull V targetValue

end value of the animation

@NonNull V initialVelocity

start velocity of the animation

getVelocityFromNanos

public @NonNullgetVelocityFromNanos(
    long playTimeNanos,
    @NonNull V initialValue,
    @NonNull V targetValue,
    @NonNull V initialVelocity
)

Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.

Parameters
long playTimeNanos

time since the start of the animation

@NonNull V initialValue

start value of the animation

@NonNull V targetValue

end value of the animation

@NonNull V initialVelocity

start velocity of the animation