Skip to content

Instantly share code, notes, and snippets.

@theapache64
Created February 14, 2022 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theapache64/1c9b84ad0dabbf6e60f05237121f65c9 to your computer and use it in GitHub Desktop.
Save theapache64/1c9b84ad0dabbf6e60f05237121f65c9 to your computer and use it in GitHub Desktop.
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