Created
May 26, 2022 18:46
-
-
Save maiatoday/49b95958cc4d95f86b8948ff146d789d to your computer and use it in GitHub Desktop.
rainbow
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
@Composable | |
fun rainbowState( | |
rainbow: List<Color> = SkittlesRainbow, | |
duration: Int = 3000 | |
): State<Color> { | |
val infiniteTransition = rememberInfiniteTransition() | |
val interval = duration / rainbow.size | |
return infiniteTransition.animateColor( | |
initialValue = rainbow[0], | |
targetValue = rainbow.last(), | |
animationSpec = infiniteRepeatable( | |
animation = keyframes { | |
durationMillis = duration | |
var i = 0 | |
for (color in rainbow) { | |
color at i | |
i += interval | |
} | |
}, | |
repeatMode = RepeatMode.Restart | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment