---
title: "VectorizedAnimationSpec"
description: "[VectorizedAnimationSpec]s are stateless vector based animation specifications. They do not
assume any starting/ending conditions. Nor do they manage a lifecycle. All it stores is the
configuration that is particular to the type of the animation. easing and duration for
[VectorizedTweenSpec]s, or spring constants for [VectorizedSpringSpec]s. Its stateless nature
allows the same [VectorizedAnimationSpec] to be reused by a few different running animations with
different starting and ending values. More importantly, it allows the system to reuse the same
animation spec when the animation target changes in-flight.

Since [VectorizedAnimationSpec]s are stateless, it requires starting value/velocity and ending
value to be passed in, along with playtime, to calculate the value or velocity at that time. Play
time here is the progress of the animation in terms of milliseconds, where 0 means the start of
the animation and [getDurationNanos] returns the play time for the end of the animation.

__Note__: For use cases where the starting values/velocity and ending values aren't expected to
change, it is recommended to use [Animation] that caches these static values and hence does not
require them to be supplied in the value/velocity calculation."
type: "interface"
---

<div class='type'>Interface</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>



```kotlin
@JvmDefaultWithCompatibility
public interface VectorizedAnimationSpec<V : AnimationVector>
```


`VectorizedAnimationSpec`s are stateless vector based animation specifications. They do not
assume any starting/ending conditions. Nor do they manage a lifecycle. All it stores is the
configuration that is particular to the type of the animation. easing and duration for
`VectorizedTweenSpec`s, or spring constants for `VectorizedSpringSpec`s. Its stateless nature
allows the same `VectorizedAnimationSpec` to be reused by a few different running animations with
different starting and ending values. More importantly, it allows the system to reuse the same
animation spec when the animation target changes in-flight.

Since `VectorizedAnimationSpec`s are stateless, it requires starting value/velocity and ending
value to be passed in, along with playtime, to calculate the value or velocity at that time. Play
time here is the progress of the animation in terms of milliseconds, where 0 means the start of
the animation and `getDurationNanos` returns the play time for the end of the animation.

__Note__: For use cases where the starting values/velocity and ending values aren't expected to
change, it is recommended to use `Animation` that caches these static values and hence does not
require them to be supplied in the value/velocity calculation.


## Functions

```kotlin
public fun getValueFromNanos(
        playTimeNanos: Long,
        initialValue: V,
        targetValue: V,
        initialVelocity: V,
    ): V
```


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

#### Parameters

| | |
| --- | --- |
| playTimeNanos | time since the start of the animation |
| initialValue | start value of the animation |
| targetValue | end value of the animation |
| initialVelocity | start velocity of the animation |



```kotlin
public fun getVelocityFromNanos(
        playTimeNanos: Long,
        initialValue: V,
        targetValue: V,
        initialVelocity: V,
    ): V
```


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

#### Parameters

| | |
| --- | --- |
| playTimeNanos | time since the start of the animation |
| initialValue | start value of the animation |
| targetValue | end value of the animation |
| initialVelocity | start velocity of the animation |



```kotlin
public fun getDurationNanos(initialValue: V, targetValue: V, initialVelocity: V): Long
```


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

| | |
| --- | --- |
| initialValue | start value of the animation |
| targetValue | end value of the animation |
| initialVelocity | start velocity of the animation |



```kotlin
public fun getEndVelocity(initialValue: V, targetValue: V, initialVelocity: V): V
```


Calculates the end velocity of the animation with the provided start/end values, and start
velocity. For duration-based animations, end velocity will be the velocity of the animation
at the duration time. This is also the default assumption. However, for physics-based
animations, end velocity is an `AnimationVector` of 0s.

#### Parameters

| | |
| --- | --- |
| initialValue | start value of the animation |
| targetValue | end value of the animation |
| initialVelocity | start velocity of the animation |




