what is the best animation API to use if I want to...
# compose
n
what is the best animation API to use if I want to make an IconButton scale from 1f to 3f and back to 1f on click? 🤔
f
animatable
Copy code
@Preview(widthDp = 360, heightDp = 360)
@Composable
fun IconScale() {
    val animatable = remember {
        Animatable(1f)
    }
    val scope = rememberCoroutineScope()
    PlaygroundTheme {
        Surface(
            color = MaterialTheme.colorScheme.background
        ) {
            Column(
                modifier = Modifier.fillMaxWidth(),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.SpaceAround,
            ) {
                Icon(
                    imageVector = Icons.Default.Favorite,
                    modifier = Modifier.graphicsLayer {
                        scaleX = animatable.value
                        scaleY = animatable.value
                    },
                    contentDescription = null,
                )
                Button(
                    onClick = {
                        scope.launch {
                            animatable.animateTo(
                                targetValue = 3f,
                                animationSpec = tween(durationMillis = 500)
                            )
                            animatable.animateTo(
                                targetValue = 1f,
                                animationSpec = tween(durationMillis = 500)
                            )
                        }

                    }
                ) {
                    Text(
                        text = "Animate"
                    )
                }
            }
        }
    }
}
❤️ 2
n
@Francesc thank you so much !!
👍 1