mattinger
01/03/2022, 6:57 PMValueAnimator.ofArgb
function. I’m not finding an equivalent in compose (at least not easily)Bradleycorn
01/03/2022, 7:03 PMkeyframes
(says the guy who just learned animations last week and now considers himself an expert on the subject 😄 )mattinger
01/03/2022, 7:39 PMBradleycorn
01/03/2022, 7:39 PM@Composable
fun ColorAnimator() {
var someState by remember { mutableStateOf(true) }
val transition = updateTransition(targetState = someState)
val color by transition.animateColor(
transitionSpec = {
keyframes {
durationMillis = 4000
Color.Red at 1000
Color.Green at 2000
Color.Blue at 3000
}
},
label = "color change"
) { state ->
when {
state -> MaterialTheme.colors.primary
else -> MaterialTheme.colors.secondary
}
}
// Background ....
Surface(color = MaterialTheme.colors.background) {
// A spacer with it's color animated
Spacer(
modifier = Modifier
.size(200.dp)
.padding(24.dp)
.background(color)
.clickable { someState = !someState }
)
}
}
Bradleycorn
01/03/2022, 7:44 PMBradleycorn
01/03/2022, 7:45 PMmattinger
01/03/2022, 9:50 PMmattinger
01/03/2022, 9:50 PM