# InterruptionAwareAnimationSpec

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

## API Reference

> Source set: Common

```kotlin
public class InterruptionAwareAnimationSpec<T>(
    public val animationSpec: FiniteAnimationSpec<T>,
    public val interruptionSpec: FiniteAnimationSpec<T> = animationSpec,
) : FiniteAnimationSpec<T>
```

A [FiniteAnimationSpec](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/interfaces/FiniteAnimationSpec/api.md) that uses `animationSpec` for uninterrupted animations and switches to
`interruptionSpec` when a [Transition](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/classes/Transition/api.md), [animateValueAsState](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/composable-functions/animateValueAsState/api.md), or `Animatable.animateTo`
animation is interrupted mid-flight.

When a [Transition](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/classes/Transition/api.md) is interrupted mid-flight, most [FiniteAnimationSpec](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/interfaces/FiniteAnimationSpec/api.md) implementations (such
as [TweenSpec](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/classes/TweenSpec/api.md) or [KeyframesSpec](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/classes/KeyframesSpec/api.md), which ignore initial velocity) fall back to a default
[SpringSpec](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/classes/SpringSpec/api.md) to avoid abrupt velocity discontinuities. Wrapping a spec in
[InterruptionAwareAnimationSpec](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/classes/InterruptionAwareAnimationSpec/api.md) overrides this fallback so [Transition](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/classes/Transition/api.md) 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](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/composable-functions/animateFloatAsState/api.md) or [animateValueAsState](https://composables.com/jetpack-compose/androidx.compose.animation/animation-core/composable-functions/animateValueAsState/api.md)), `animationSpec` is used when starting from
rest and `interruptionSpec` is used when the target value changes while an animation is already
in-flight.

## Functions

### vectorize

> Source set: Common

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

### equals

> Source set: Common

```kotlin
override fun equals(other: Any?): Boolean
```

### hashCode

> Source set: Common

```kotlin
override fun hashCode(): Int
```

## Code Examples

### InterruptionAwareAnimationSpecSample

```kotlin
@Sampled
@Composable
fun InterruptionAwareAnimationSpecSample(expanded: Boolean) {
    // 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))
}
```
