Created
October 3, 2022 13:49
-
-
Save StephenVinouze/029fe4901835b2227c4a530b3d74479b to your computer and use it in GitHub Desktop.
This file contains 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
@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