Rick Regan
03/18/2021, 7:54 PMCrossfade (see thread), when I click "Reset", the Button labelled "Button" fades and goes back to full color. I don't know what that animation is, or why it's animating anything at all.Rick Regan
03/18/2021, 7:55 PMclass AnimationState(val i: Int = 0)
var animationState by mutableStateOf(AnimationState())
@Composable
fun CrossfadeButton() {
Column {
Button(onClick = { animationState = AnimationState() },
) {
Text(text = "Reset")
}
Crossfade(targetState = animationState, animationSpec = tween(2000)) { currentAnimationState ->
Button(onClick = { },
) {
Text(text = "Button")
}
}
}
}Doris Liu
03/18/2021, 10:45 PMRick Regan
03/19/2021, 12:13 AMRick Regan
03/19/2021, 4:37 PM// Based on Crossfade example at <https://developer.android.com/jetpack/compose/animation>
@Composable
fun CrossfadeButton() {
var currentPage by remember { mutableStateOf("A") }
Column {
Button(onClick = { currentPage = if (currentPage == "A") "B" else "A" },
) {
Text(text = "Swap")
}
Crossfade(targetState = currentPage, animationSpec = tween(2000)) { screen ->
when (screen) {
"A" -> Button(onClick = { }) {
Text(text = "Button A",
color = Color.Green)
}
"B" -> Button(onClick = { }) {
Text(text = "Button B",
color = Color.Red)
}
}
}
}
}Rick Regan
03/19/2021, 4:46 PMDoris Liu
03/19/2021, 4:55 PMRick Regan
03/19/2021, 5:00 PMButton is special then because Text does not get an alpha (if you remove Button from my first example and just leave the Text it looks like the "NOOP" I expect).Rick Regan
03/19/2021, 5:11 PMText is special. Box and Surface work like Button I see.Doris Liu
03/19/2021, 5:12 PMRick Regan
03/19/2021, 5:23 PMText is (I tried Color.Magenta and a few others).Doris Liu
03/19/2021, 5:29 PM