Carl Benson
09/25/2023, 4:23 PMCarl Benson
09/25/2023, 4:28 PM@Composable
fun Screen(value: Int) {
val transition = updateTransition(targetState = value)
val color by transition.animateColor {
// animate from Color.Red to Color.Blue to Color.Red
}
}
Carl Benson
09/25/2023, 4:34 PManimationSpec = keyframes {
durationMillis = 500
Color.Red at 0
Color.Blue at 250
Color.Red at 500
}
and then ignore the targetValueByState
method which requires me to surpress a warning with
@SuppressLint("UnusedTransitionTargetStateParameter")
but it feels hackishTimo Drick
09/25/2023, 5:20 PMLaunchedEffect(Key) {
targetColor = Color.Red
delay(500)
targetColor = Color.Blue
....
}
Carl Benson
09/26/2023, 12:28 PMCarl Benson
09/26/2023, 12:29 PMTimo Drick
09/26/2023, 12:29 PMTimo Drick
09/26/2023, 12:41 PM// Start out gray and animate to green/red based on `ok`
val color = remember { Animatable(Color.Gray) }
LaunchedEffect(ok) {
color.animateTo(if (ok) Color.Green else Color.Red)
}
Box(Modifier.fillMaxSize().background(color.value))
Carl Benson
09/26/2023, 12:51 PM