Skip to content

Instantly share code, notes, and snippets.

@StephenVinouze
Created October 3, 2022 13:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StephenVinouze/029fe4901835b2227c4a530b3d74479b to your computer and use it in GitHub Desktop.
Save StephenVinouze/029fe4901835b2227c4a530b3d74479b to your computer and use it in GitHub Desktop.
@OptIn(ExperimentalAnimationApi::class)
@Composable
fun CountDown(
count: Int?,
modifier: Modifier = Modifier,
) {
val transitionDuration = 500
val enterTransition = scaleIn(initialScale = 1.5f, animationSpec = tween(transitionDuration))
val exitTransition = scaleOut(targetScale = 4f, animationSpec = tween(transitionDuration)) + fadeOut(animationSpec = tween(transitionDuration))
AnimatedVisibility(
modifier = modifier,
visible = count != null,
enter = enterTransition,
exit = exitTransition
) {
val countDown = when (count) {
0, null -> "Go"
else -> "$count"
}
AnimatedContent(
targetState = count,
transitionSpec = { enterTransition with fadeOut(animationSpec = tween(0)) },
contentAlignment = Alignment.Center,
) {
Text(
modifier = Modifier.padding(100.dp),
text = countDown.uppercase(),
color = Color.White,
textAlign = TextAlign.Center,
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment