Created
February 14, 2022 19:35
-
-
Save theapache64/1c9b84ad0dabbf6e60f05237121f65c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Column { | |
var flag by remember { mutableStateOf(false) } | |
val transition = updateTransition(targetState = flag, label = "My Animation") | |
// Method #1 | |
LaunchedEffect(transition.currentState == transition.targetState) { | |
if (transition.currentState == transition.targetState) { | |
println("Animation finished (1)") | |
} | |
} | |
// Method #2 | |
LaunchedEffect(Unit){ | |
snapshotFlow { transition.currentState == transition.targetState } | |
.filter { it } | |
.collect { | |
println("Animation finished: (2)") | |
} | |
} | |
transition.AnimatedVisibility( | |
visible = { it }, | |
enter = fadeIn(animationSpec = tween(3000)), | |
exit = fadeOut(animationSpec = tween(3000)), | |
) { | |
Box( | |
modifier = Modifier | |
.size(100.dp) | |
.background(Color.Red), | |
contentAlignment = Alignment.Center | |
) { | |
Text(text = "I am content") | |
} | |
} | |
Button(onClick = { flag = !flag }) { | |
Text(text = "Toggle") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment