> Documentation index: https://developer.android.com/reference/llms.txt

# InterruptionAwareAnimationSpec

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

  ```
  class InterruptionAwareAnimationSpec<T : Any?> : FiniteAnimationSpec<T>
  ```

*** ** * ** ***

A `FiniteAnimationSpec` that uses `animationSpec` for uninterrupted animations and switches to `interruptionSpec` when a `Transition`, `animateValueAsState`, or `Animatable.animateTo` animation is interrupted mid-flight.

When a `Transition` is interrupted mid-flight, most `FiniteAnimationSpec` implementations (such as `TweenSpec` or `KeyframesSpec`, which ignore initial velocity) fall back to a default `SpringSpec` to avoid abrupt velocity discontinuities. Wrapping a spec in `InterruptionAwareAnimationSpec` overrides this fallback so `Transition` instead uses `interruptionSpec` (which defaults to `animationSpec`) and passes the current in-flight value and velocity to it. Similarly, when used with `Animatable.animateTo` or `animate*AsState` APIs (such as `animateFloatAsState` or `animateValueAsState`), `animationSpec` is used when starting from rest and `interruptionSpec` is used when the target value changes while an animation is already in-flight.

```kotlin
import androidx.compose.animation.core.InterruptionAwareAnimationSpec
import androidx.compose.animation.core.animateDp
import androidx.compose.animation.core.tween
import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.State
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

// Use a 300ms tween for regular transitions, and a shorter 100ms tween when the transition
// is interrupted mid-flight instead of falling back to a default spring.
val transition = updateTransition(targetState = expanded, label = "BoxExpansion")
val size by
    transition.animateDp(
        transitionSpec = {
            InterruptionAwareAnimationSpec(
                animationSpec = tween(durationMillis = 300),
                interruptionSpec = tween(durationMillis = 100),
            )
        },
        label = "Size",
    ) { isExpanded ->
        if (isExpanded) 120.dp else 48.dp
    }
Box(Modifier.size(size).background(Color.Blue))
```

| See also |
|---|---|
| `SpringSpec` |   |
| `FiniteAnimationSpec` |   |
| `Transition` |   |
| `animateValueAsState` |   |
| `animateTo` |   |

## Summary

| ### Public constructors |
|---|---|
| `<T : Any?> InterruptionAwareAnimationSpec( animationSpec: FiniteAnimationSpec<T>, interruptionSpec: FiniteAnimationSpec<T> )` | Cmn |

| ### Public functions |
|---|---|---|
| `open operator Boolean` | `equals(other: Any?)` | Cmn |
| `open Int` | `hashCode()` | Cmn |
| `open VectorizedFiniteAnimationSpec<V>` | `<V : AnimationVector> vectorize(converter: TwoWayConverter<T, V>)` Creates a `VectorizedAnimationSpec` with the given `TwoWayConverter`. | Cmn |

| ### Public properties |
|---|---|---|
| `FiniteAnimationSpec<T>` | `animationSpec` the `FiniteAnimationSpec` used when starting an animation from rest. | Cmn |
| `FiniteAnimationSpec<T>` | `interruptionSpec` the `FiniteAnimationSpec` used when an animation is interrupted mid-flight. | Cmn |

## Public constructors

### InterruptionAwareAnimationSpec

Cmn

```
<T : Any?> InterruptionAwareAnimationSpec(
    animationSpec: FiniteAnimationSpec<T>,
    interruptionSpec: FiniteAnimationSpec<T> = animationSpec
)
```

## Public functions

### equals

Cmn

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

Cmn

```
open fun hashCode(): Int
```

### vectorize

Cmn

```
open fun <V : AnimationVector> vectorize(converter: TwoWayConverter<T, V>): VectorizedFiniteAnimationSpec<V>
```

Creates a `VectorizedAnimationSpec` with the given `TwoWayConverter`.

The underlying animation system operates on `AnimationVector`s. `T` will be converted to `AnimationVector` to animate. `VectorizedAnimationSpec` describes how the converted `AnimationVector` should be animated. E.g. The animation could simply interpolate between the start and end values (i.e.`TweenSpec`), or apply spring physics to produce the motion (i.e. `SpringSpec`), etc)

| Parameters |
|---|---|
| `converter: TwoWayConverter<T, V>` | converts the type `T` from and to `AnimationVector` type |

## Public properties

### animationSpec

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

```
val animationSpec: FiniteAnimationSpec<T>
```

the `FiniteAnimationSpec` used when starting an animation from rest.

### interruptionSpec

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

```
val interruptionSpec: FiniteAnimationSpec<T>
```

the `FiniteAnimationSpec` used when an animation is interrupted mid-flight. Defaults to `animationSpec`.