<h2 id="animatefloatasstate-targetvalue-animationspec-visibilitythreshold-label-finishedlistener">animateFloatAsState</h2>

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

```kotlin
@Composable
public fun animateFloatAsState(
    targetValue: Float,
    animationSpec: AnimationSpec<Float> = defaultAnimation,
    visibilityThreshold: Float = DefaultFloatVisibilityThreshold,
    label: String = "FloatAnimation",
    finishedListener: ((Float) -> Unit)? = null,
): State<Float>
```

Fire-and-forget animation function for [Float]. This Composable function is overloaded for
different parameter types such as [Dp](/jetpack-compose/androidx.compose.ui/ui-unit/classes/Dp), [Color][androidx.compose.ui.graphics.Color], [Offset](/jetpack-compose/androidx.compose.ui/ui-geometry/classes/Offset),
etc. When the provided `targetValue` is changed, the animation will run automatically. If there
is already an animation in-flight when `targetValue` changes, the on-going animation will adjust
course to animate towards the new target value.

[animateFloatAsState](/jetpack-compose/androidx.compose.animation/animation-core/composable-functions/animateFloatAsState) returns a [State](/jetpack-compose/androidx.compose.runtime/runtime/interfaces/State) object. The value of the state object will continuously
be updated by the animation until the animation finishes.

Note, [animateFloatAsState](/jetpack-compose/androidx.compose.animation/animation-core/composable-functions/animateFloatAsState) cannot be canceled/stopped without removing this composable function
from the tree. See [Animatable](/jetpack-compose/androidx.compose.animation/animation-core/classes/Animatable) for cancelable animations.

[visibilityThreshold](/jetpack-compose/androidx.compose.animation/animation-core/properties/VisibilityThreshold) can be used to define when the animation value is considered close enough
to the `targetValue` to finish. By default, the [visibilityThreshold](/jetpack-compose/androidx.compose.animation/animation-core/properties/VisibilityThreshold) in the [animationSpec](/jetpack-compose/androidx.compose.animation/animation-core/interfaces/AnimationSpec) will
be respected. If a non-default [visibilityThreshold](/jetpack-compose/androidx.compose.animation/animation-core/properties/VisibilityThreshold) is provided, it will override the visibility
threshold in the [animationSpec](/jetpack-compose/androidx.compose.animation/animation-core/interfaces/AnimationSpec) if it's a [SpringSpec](/jetpack-compose/androidx.compose.animation/animation-core/classes/SpringSpec).

#### Parameters

| | |
| --- | --- |
| targetValue | Target value of the animation |
| animationSpec | The animation that will be used to change the value through time. [spring](/jetpack-compose/androidx.compose.animation/animation-core/functions/spring) will be used by default. |
| visibilityThreshold | An optional threshold for deciding when the animation value is considered close enough to the targetValue. |
| label | An optional label to differentiate from other animations in Android Studio. |
| finishedListener | An optional end listener to get notified when the animation is finished. |

#### Returns

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

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

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

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

<h2 id="animatefloatasstate-targetvalue-animationspec-visibilitythreshold-finishedlistener">animateFloatAsState</h2>

```kotlin
@Composable
public fun animateFloatAsState(
    targetValue: Float,
    animationSpec: AnimationSpec<Float> = defaultAnimation,
    visibilityThreshold: Float = 0.01f,
    finishedListener: ((Float) -> Unit)? = null,
): State<Float>
```