Skip to content

Instantly share code, notes, and snippets.

@maiatoday
Created May 26, 2022 18:46
Show Gist options
  • Save maiatoday/49b95958cc4d95f86b8948ff146d789d to your computer and use it in GitHub Desktop.
Save maiatoday/49b95958cc4d95f86b8948ff146d789d to your computer and use it in GitHub Desktop.
rainbow
@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