# Animation

Artifact: [androidx.compose.animation:animation-core](https://developer.android.com/jetpack/androidx/releases/compose-animation) [View Source](https://cs.android.com/search?q=file:androidx/compose/animation/core/Animation.kt+class:androidx.compose.animation.core.Animation) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0) Common/All
- Cmn

  ```
  interface Animation<T : Any?, V : AnimationVector>
  ```
Known direct subclasses [DecayAnimation](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DecayAnimation), [TargetBasedAnimation](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TargetBasedAnimation)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DecayAnimation` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DecayAnimation` is an animation that slows down from `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DecayAnimation#(androidx.compose.animation.core.VectorizedDecayAnimationSpec,androidx.compose.animation.core.TwoWayConverter,kotlin.Any,androidx.compose.animation.core.AnimationVector)` as time goes on. |
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TargetBasedAnimation` | This is a convenient animation wrapper class that works for all target based animations, i.e. animations that has a pre-defined end value, unlike decay. |

*** ** * ** ***

This interface provides a convenient way to query from an `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/VectorizedAnimationSpec` or `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatDecayAnimationSpec`: It spares the need to pass the starting conditions and in some cases ending condition for each value or velocity query, and instead only requires the play time to be passed for such queries.

The implementation of this interface should cache the starting conditions and ending conditions of animations as needed.

**Note** : `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation` does not track the lifecycle of an animation. It merely reacts to play time change and returns the new value/velocity as a result. It can be used as a building block for more lifecycle aware animations. In contrast, `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animatable` and `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Transition` are stateful and manage their own lifecycles.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animatable` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/rememberTransition.composable#rememberTransition(androidx.compose.animation.core.TransitionState,kotlin.String)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/updateTransition.composable#updateTransition(kotlin.Any,kotlin.String)` |   |

## Summary

| ### Public functions |
|---|---|---|
| `T` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation#getValueFromNanos(kotlin.Long)(playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Returns the value of the animation at the given play time. | Cmn |
| `V` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation#getVelocityVectorFromNanos(kotlin.Long)(playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Returns the velocity (in `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector` form) of the animation at the given play time. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation#isFinishedFromNanos(kotlin.Long)(playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Returns whether the animation is finished at the given play time. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation#durationNanos()` This amount of time in nanoseconds that the animation will run before it finishes | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation#isInfinite()` Whether or not the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation` represents an infinite animation. | Cmn |
| `T` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation#targetValue()` This is the value that the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation` will reach when it finishes uninterrupted. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TwoWayConverter<T, V>` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation#typeConverter()` The `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TwoWayConverter` that will be used to convert value/velocity from any arbitrary data type to `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector`. | Cmn |

| ### Extension functions |
|---|---|---|
| `T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, V : https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector> https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation<T, V>.https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation#(androidx.compose.animation.core.Animation).getVelocityFromNanos(kotlin.Long)( playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` Returns the velocity of the animation at the given play time. | Cmn |

## Public functions

### getValueFromNanos

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
fun getValueFromNanos(playTimeNanos: Long): T
```

Returns the value of the animation at the given play time.

| Parameters |
|---|---|
| `playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | the play time that is used to determine the value of the animation. |

### getVelocityVectorFromNanos

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
fun getVelocityVectorFromNanos(playTimeNanos: Long): V
```

Returns the velocity (in `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector` form) of the animation at the given play time.

| Parameters |
|---|---|
| `playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | the play time that is used to calculate the velocity of the animation. |

### isFinishedFromNanos

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
open fun isFinishedFromNanos(playTimeNanos: Long): Boolean
```

Returns whether the animation is finished at the given play time.

| Parameters |
|---|---|
| `playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | the play time used to determine whether the animation is finished. |

## Public properties

### durationNanos

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
val durationNanos: Long
```

This amount of time in nanoseconds that the animation will run before it finishes

### isInfinite

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
val isInfinite: Boolean
```

Whether or not the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation` represents an infinite animation. That is, one that will not finish by itself, one that needs an external action to stop. For examples, an indeterminate progress bar, which will only stop when it is removed from the composition.

### targetValue

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
val targetValue: T
```

This is the value that the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animation` will reach when it finishes uninterrupted.

### typeConverter

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
val typeConverter: TwoWayConverter<T, V>
```

The `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TwoWayConverter` that will be used to convert value/velocity from any arbitrary data type to `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector`. This makes it possible to animate different dimensions of the data object independently (e.g. x/y dimensions of the position data).

## Extension functions

### Animation.getVelocityFromNanos

Cmn Artifact: [androidx.compose.animation:animation-core](https://developer.android.com/jetpack/androidx/releases/compose-animation) [View Source](https://cs.android.com/search?q=file:androidx/compose/animation/core/Animation.kt+function:getVelocityFromNanos)

```
fun <T : Any?, V : AnimationVector> Animation<T, V>.getVelocityFromNanos(
    playTimeNanos: Long
): T
```

Returns the velocity of the animation at the given play time.

| Parameters |
|---|---|
| `playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | the play time that is used to calculate the velocity of the animation. |