Skip to content

Instantly share code, notes, and snippets.

@Farhandroid
Created August 31, 2023 04:42
Show Gist options
  • Save Farhandroid/e3c94d77917308f67bdd229f2f31255c to your computer and use it in GitHub Desktop.
Save Farhandroid/e3c94d77917308f67bdd229f2f31255c to your computer and use it in GitHub Desktop.
@Composable
fun AnimatedVisibilityExample() {
// State to control the visibility of the text
var isVisible by remember { mutableStateOf(true) }
// Box to layer the button and the text
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize()
) {
// Button to toggle the visibility
Button(onClick = { isVisible = !isVisible }) {
Text("Toggle Visibility")
}
// AnimatedVisibility to control the appearance of the text
AnimatedVisibility(
visible = isVisible,
enter = fadeIn(),
exit = fadeOut()
) {
// The text to show/hide
Text("Hello, World!", modifier = Modifier.padding(top = 80.dp))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment