Skip to content

Instantly share code, notes, and snippets.

@Skyyo
Last active June 19, 2022 17:55
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 Skyyo/31966488e2b31b446c7489f9b47fa7a5 to your computer and use it in GitHub Desktop.
Save Skyyo/31966488e2b31b446c7489f9b47fa7a5 to your computer and use it in GitHub Desktop.
@Composable
fun ExpandableContent(
visible: Boolean = true,
initialVisibility: Boolean = false
) {
val enterTransition = remember {
expandVertically(
expandFrom = Alignment.Top,
animationSpec = tween(EXPANSTION_TRANSITION_DURATION)
) + fadeIn(
initialAlpha = 0.3f,
animationSpec = tween(EXPANSTION_TRANSITION_DURATION)
)
}
val exitTransition = remember {
shrinkVertically(
// Expand from the top.
shrinkTowards = Alignment.Top,
animationSpec = tween(EXPANSTION_TRANSITION_DURATION)
) + fadeOut(
// Fade in with the initial alpha of 0.3f.
animationSpec = tween(EXPANSTION_TRANSITION_DURATION)
)
}
AnimatedVisibility(
visible = visible,
initiallyVisible = initialVisibility,
enter = enterTransition,
exit = exitTransition
) {
Column(modifier = Modifier.padding(8.dp)) {
Spacer(modifier = Modifier.heightIn(100.dp))
Text(
text = "Expandable content here",
textAlign = TextAlign.Center
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment