<h2 id="animatevalue-initialvalue-targetvalue-typeconverter-animationspec-label">animateValue</h2>

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

```kotlin
@Composable
public fun <T, V : AnimationVector> InfiniteTransition.animateValue(
    initialValue: T,
    targetValue: T,
    typeConverter: TwoWayConverter<T, V>,
    animationSpec: InfiniteRepeatableSpec<T>,
    label: String = "ValueAnimation",
): State<T>
```

Creates an animation of type [T] that runs infinitely as a part of the given
[InfiniteTransition](/jetpack-compose/androidx.compose.animation/animation-core/classes/InfiniteTransition). Any data type can be animated so long as it can be converted from and to an
[AnimationVector](/jetpack-compose/androidx.compose.animation/animation-core/classes/AnimationVector). This conversion needs to be provided as a `typeConverter`. Some examples of
such [TwoWayConverter](/jetpack-compose/androidx.compose.animation/animation-core/interfaces/TwoWayConverter) are: [Int.VectorConverter][Int.Companion.VectorConverter],
[Dp.VectorConverter][Dp.Companion.VectorConverter],
[Size.VectorConverter][Size.Companion.VectorConverter], etc

Once the animation is created, it will run from `initialValue` to `targetValue` and repeat.
Depending on the [RepeatMode](/jetpack-compose/androidx.compose.animation/animation-core/classes/RepeatMode) of the provided [animationSpec](/jetpack-compose/androidx.compose.animation/animation-core/interfaces/AnimationSpec), the animation could either restart
after each iteration (i.e. [RepeatMode.Restart](/jetpack-compose/androidx.compose.animation/animation-core/classes/RepeatMode.Restart)), or reverse after each iteration (i.e .
[RepeatMode.Reverse](/jetpack-compose/androidx.compose.animation/animation-core/classes/RepeatMode.Reverse)).

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

A [label](/jetpack-compose/androidx.compose.material3/material3/components/Label) for differentiating this animation from others in android studio.

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

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

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

<h2 id="animatevalue-initialvalue-targetvalue-typeconverter-animationspec">animateValue</h2>

```kotlin
@Composable
public fun <T, V : AnimationVector> InfiniteTransition.animateValue(
    initialValue: T,
    targetValue: T,
    typeConverter: TwoWayConverter<T, V>,
    animationSpec: InfiniteRepeatableSpec<T>,
): State<T>
```

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

<h2 id="animatevalue-typeconverter-label-targetvaluebystate">animateValue</h2>

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

```kotlin
@Composable
public inline fun <S, T, V : AnimationVector> Transition<S>.animateValue(
    typeConverter: TwoWayConverter<T, V>,
    noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<T> = {
        spring()
    },
    label: String = "ValueAnimation",
    targetValueByState: @Composable (state: S) -> T,
): State<T>
```

Creates an animation of type [T] as a part of the given [Transition](/jetpack-compose/androidx.compose.animation/animation-core/classes/Transition). This means the states of
this animation will be managed by the [Transition](/jetpack-compose/androidx.compose.animation/animation-core/classes/Transition). `typeConverter` will be used to convert
between type [T] and [AnimationVector](/jetpack-compose/androidx.compose.animation/animation-core/classes/AnimationVector) so that the animation system knows how to animate it.

`targetValueByState` is used as a mapping from a target state to the target value of this
animation. [Transition](/jetpack-compose/androidx.compose.animation/animation-core/classes/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 targetValue changes
outside of a [Transition](/jetpack-compose/androidx.compose.animation/animation-core/classes/Transition) run (i.e. when the [Transition](/jetpack-compose/androidx.compose.animation/animation-core/classes/Transition) already reached its targetState), the
[Transition](/jetpack-compose/androidx.compose.animation/animation-core/classes/Transition) will start running again to ensure this animation reaches its new target smoothly.

An optional `transitionSpec` can be provided to specify (potentially different) animation for
each pair of initialState and targetState. [FiniteAnimationSpec](/jetpack-compose/androidx.compose.animation/animation-core/interfaces/FiniteAnimationSpec) includes any non-infinite
animation, such as [tween](/jetpack-compose/androidx.compose.animation/animation-core/functions/tween), [spring](/jetpack-compose/androidx.compose.animation/animation-core/functions/spring), [keyframes](/jetpack-compose/androidx.compose.animation/animation-core/functions/keyframes) and even [repeatable](/jetpack-compose/androidx.compose.animation/animation-core/functions/repeatable), but not
[infiniteRepeatable](/jetpack-compose/androidx.compose.animation/animation-core/functions/infiniteRepeatable). By default, `transitionSpec` uses a [spring](/jetpack-compose/androidx.compose.animation/animation-core/functions/spring) animation for all transition
destinations.

[label](/jetpack-compose/androidx.compose.material3/material3/components/Label) is used to differentiate from other animations in the same transition in Android Studio.

#### Returns

| | |
| --- | --- |
|  | A [State](/jetpack-compose/androidx.compose.runtime/runtime/interfaces/State) object, the value of which is updated by animation |