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))
}