Class

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.

InterruptionAwareAnimationSpecSample

@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))
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: