Skip to content

Instantly share code, notes, and snippets.

@pranavjayaraj
Last active March 26, 2021 05:11
Show Gist options
  • Save pranavjayaraj/af0182873aaf734e013087aa32045ae4 to your computer and use it in GitHub Desktop.
Save pranavjayaraj/af0182873aaf734e013087aa32045ae4 to your computer and use it in GitHub Desktop.
@Composable
fun AnimationLayout() {
var state by remember { mutableStateOf(false) }
val startColor = Color.Blue
val endColor = Color.Green
val backgroundColor by animateColorAsState(
if (state) endColor else startColor
)
Column(
modifier = Modifier.fillMaxSize().background(backgroundColor),
verticalArrangement = Arrangement.Center
) {
AnimationButtons(onValueChanged = { currState ->
state = currState
}, state = state)
}
}
@Composable
fun AnimationButton(onValueChanged: (Boolean) -> Unit, state: Boolean) {
Button(
onClick = { onValueChanged(!state) },
modifier = Modifier.height(50.dp).width(100.dp).padding(top = 10.dp),
content = {
Text(text = "Animate", color = Color.White)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment