Last active
August 31, 2023 06:34
-
-
Save Farhandroid/0d5e8d34ce205fdf1a2bf2b24062ef87 to your computer and use it in GitHub Desktop.
AnimateAsStateExample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun AnimateAsStateExample() { | |
// State to control the background color | |
var boxColor by remember { mutableStateOf(Color.Blue) } | |
// Animate the background color | |
val backgroundColor by animateColorAsState(targetValue = boxColor, label = "") | |
// Box with clickable modifier to change the color | |
Box( | |
modifier = Modifier | |
.size(200.dp) | |
.background(backgroundColor) | |
.clickable { | |
// Toggle color between Blue and Green when clicked | |
boxColor = if (boxColor == Color.Blue) Color.Green else Color.Blue | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment