ursus
05/04/2026, 6:44 PMtransitions in compose?
val transition = updateTransition(
targetState = expanded,
label = "expandedTransition"
)
val width by transition.animateDp(label = "width") { expanded ->
if (expanded) 220.dp else 64.dp
}
val alpha by transition.animateFloat(label = "alpha") { expanded ->
if (expanded) 1f else 0f
}
how is this fundamentally different than 2 animateXAsState?Chrimaeon
05/04/2026, 6:57 PMursus
05/04/2026, 7:20 PMWinson Chiu
05/04/2026, 7:56 PMursus
05/04/2026, 8:05 PMWinson Chiu
05/04/2026, 8:07 PMursus
05/04/2026, 8:10 PMWinson Chiu
05/04/2026, 8:22 PManimateValueAsState, it uses launch with a Channel to schedule animation updates. There's no guarantee of promptness there, it's possible one launch occurs before the frame boundary and another after.
Whereas Transition calls derivedStateOf on its state value, meaning that when the value is invalidated, all of the dependent state values must be updated in the same snapshot for it to be considered successful and applied.ursus
05/04/2026, 8:25 PMWinson Chiu
05/04/2026, 8:27 PMursus
05/04/2026, 8:29 PMWinson Chiu
05/04/2026, 8:32 PMursus
05/04/2026, 8:34 PMWinson Chiu
05/04/2026, 8:34 PMursus
05/04/2026, 8:36 PMursus
05/04/2026, 8:37 PMursus
05/04/2026, 8:38 PMWinson Chiu
05/04/2026, 8:50 PM