When trying to use a infiniteTransition + animate ...
# compose
s
When trying to use a infiniteTransition + animate color + keyframes seems like we got some redundant parameters in InfiniteTransition.animateColor. With the code
Copy code
val transition = rememberInfiniteTransition()
val color by transition.animateColor(
  initialValue = Color.Red,
  targetValue = Color.Red,
  animationSpec = infiniteRepeatable(
    animation = keyframes {
      durationMillis = 500
      Color.White atFraction 0f
      Color.Magenta atFraction 0.33f
      Color.White atFraction 0.66f
      Color.White atFraction 1f
    },
    repeatMode = RepeatMode.Restart,
  ),
  label = "color transition",
)
initialValue
and
targetValue
are simply ignored, Red is never shown since we are specifying the colors inside the keyFrames dsl instead for how the transition should look like. Is it because I am misusing the API in some way, is there something else I should be using here instead, or is it just a bit of a shortcoming in how this API has shaped itself while supporting all the different approaches, like tween, keyFrames etc.
c
I wouldn’t categorize it as misuse. You are just choosing to declare the initial and target value in key frames instead. That can happen due to how keyframes are designed, but doesn’t mean you shouldn’t use it with infiniteTransition, since you may want to alter the interpolation between the two. Also, in many cases you might only need to set initial and target for infinite transitions. Flexibility is there when you need it.
s
Ah perfect, thanks a lot for sharing your thoughts on this one. I simply was a bit confused but the way you put it does make it make sense ☺️