Created
March 25, 2022 09:48
-
-
Save abhishekBansal/af2f7cd0e6cc373e7770159f687ae2f3 to your computer and use it in GitHub Desktop.
Compose Infinite Moving gradient
This file contains hidden or 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
| val infiniteTransition = rememberInfiniteTransition() | |
| val animationDuration = 5000 | |
| val color1 by infiniteTransition.animateColor( | |
| initialValue = Color.Green, | |
| targetValue = Color.Cyan, | |
| animationSpec = infiniteRepeatable( | |
| animation = tween(animationDuration, easing = FastOutSlowInEasing), | |
| repeatMode = RepeatMode.Reverse | |
| ) | |
| ) | |
| val color2 by infiniteTransition.animateColor( | |
| initialValue = Color.Cyan, | |
| targetValue = Color.Green, | |
| animationSpec = infiniteRepeatable( | |
| animation = tween(animationDuration, easing = LinearOutSlowInEasing), | |
| repeatMode = RepeatMode.Reverse | |
| ) | |
| ) | |
| val radial = Brush.linearGradient(listOf(color1, color2)) | |
| Box( | |
| modifier = Modifier | |
| .background(radial) | |
| .fillMaxHeight() | |
| .fillMaxWidth() | |
| .padding(24.dp), | |
| contentAlignment = Alignment.Center | |
| ) { | |
| val text= Text( | |
| text = fact.fact, | |
| textAlign = TextAlign.Center, | |
| fontSize = 22.sp, | |
| fontWeight = FontWeight.SemiBold, | |
| modifier = Modifier.background(Color.Transparent) | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment