<div class='type'>Composable Function</div>


<a id='references'></a>



<h2 id="animatecolor-label-targetvaluebystate">animateColor</h2>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
public inline fun <S> Transition<S>.animateColor(
    noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<Color> = {
        spring()
    },
    label: String = "ColorAnimation",
    targetValueByState: @Composable() (state: S) -> Color,
): State<Color>
```


Creates a `Color` animation as a part of the given `Transition`. This means the lifecycle of this
animation will be managed by the `Transition`.

`targetValueByState` is used as a mapping from a target state to the target value of this
animation. `Transition` will be using this mapping to determine what value to target this
animation towards. __Note__ that `targetValueByState` is a composable function. This means the
mapping function could access states, CompositionLocals, themes, etc. If the target value changes
when the `Transition` already reached its `targetState`, the `Transition`
will run an animation to ensure the new target value is reached smoothly.

An optional `transitionSpec` can be provided to specify (potentially different) animations for
each pair of initialState and targetState. `FiniteAnimationSpec` can be used to describe such
animations, such as `tween`, `spring`, `keyframes` and even `repeatable`, but not
`infiniteRepeatable`. By default, `transitionSpec` uses a `spring` animation for all transition
destinations.

`label` is used to differentiate from other animations in the same transition in Android Studio.

#### Returns

| | |
| --- | --- |
|  | A `State` object, the value of which is updated by animation |






<hr class="docs-overload-divider">


<h2 id="animatecolor-initialvalue-targetvalue-animationspec-label">animateColor</h2>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
@Composable
public fun InfiniteTransition.animateColor(
    initialValue: Color,
    targetValue: Color,
    animationSpec: InfiniteRepeatableSpec<Color>,
    label: String = "ColorAnimation",
): State<Color>
```


Creates a Color animation that runs infinitely as a part of the given `InfiniteTransition`.

Once the animation is created, it will run from `initialValue` to `targetValue` and repeat.
Depending on the `RepeatMode` of the provided `animationSpec`, the animation could either restart
after each iteration (i.e. `RepeatMode.Restart`), or reverse after each iteration (i.e .
`RepeatMode.Reverse`).

If `initialValue` or `targetValue` is changed at any point during the animation, the animation
will be restarted with the new initial/targetValue. __Note__: this means animation continuity
will *not* be preserved when changing either `initialValue` or `targetValue`.

A `label` for differentiating this animation from others in android studio.



<div class='sourceset sourceset-common'>Common</div>


> **Deprecated** animateColor APIs now have a new label parameter added.



<hr class="docs-overload-divider">


<h2 id="animatecolor-initialvalue-targetvalue-animationspec">animateColor</h2>

```kotlin
@Composable
public fun InfiniteTransition.animateColor(
    initialValue: Color,
    targetValue: Color,
    animationSpec: InfiniteRepeatableSpec<Color>,
): State<Color>
```