<h2 id="animaterectasstate-targetvalue-animationspec-label-finishedlistener">animateRectAsState</h2>

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

```kotlin
@Composable
public fun animateRectAsState(
    targetValue: Rect,
    animationSpec: AnimationSpec<Rect> = rectDefaultSpring,
    label: String = "RectAnimation",
    finishedListener: ((Rect) -> Unit)? = null,
): State<Rect>
```

Fire-and-forget animation function for [Rect](/jetpack-compose/androidx.compose.ui/ui-geometry/classes/Rect). 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.

[animateRectAsState](/jetpack-compose/androidx.compose.animation/animation-core/composable-functions/animateRectAsState) 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, [animateRectAsState](/jetpack-compose/androidx.compose.animation/animation-core/composable-functions/animateRectAsState) 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.

val bounds: Rect by animateRectAsState( if (enabled) Rect(0f, 0f, 100f, 100f) else Rect(8f, 8f,
80f, 80f))

#### Parameters

| | |
| --- | --- |
| targetValue | Target value of the animation |
| animationSpec | The animation that will be used to change the value through time. Physics animation will be used by default. |
| 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="animaterectasstate-targetvalue-animationspec-finishedlistener">animateRectAsState</h2>

```kotlin
@Composable
public fun animateRectAsState(
    targetValue: Rect,
    animationSpec: AnimationSpec<Rect> = rectDefaultSpring,
    finishedListener: ((Rect) -> Unit)? = null,
): State<Rect>
```