# AnimationResult

Artifact: [androidx.compose.animation:animation-core](https://developer.android.com/jetpack/androidx/releases/compose-animation) [View Source](https://cs.android.com/search?q=file:androidx/compose/animation/core/Animatable.kt+class:androidx.compose.animation.core.AnimationResult) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0) Common/All
- Cmn

  ```
  class AnimationResult<T : Any?, V : AnimationVector>
  ```

*** ** * ** ***

AnimationResult contains information about an animation at the end of the animation. `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationResult#endState()` captures the value/velocity/frame time, etc of the animation at its last frame. It can be useful for starting another animation to continue the velocity from the previously interrupted animation. `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationResult#endReason()` describes why the animation ended, it could be either of the following:

- `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationEndReason#Finished`, when the animation finishes successfully without any interruption

- `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationEndReason#BoundReached` If the animation reaches the either `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animatable#lowerBound()` or `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animatable#upperBound()` in any dimension, the animation will end with `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationEndReason#BoundReached` being the end reason.

```kotlin
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationEndReason
import androidx.compose.animation.core.exponentialDecay
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size

suspend fun CoroutineScope.animateBouncingOffBounds(
    animatable: Animatable<Offset, *>,
    flingVelocity: Offset,
    parentSize: Size,
) {
    launch {
        var startVelocity = flingVelocity
        // Set bounds for the animation, so that when it reaches bounds it will stop
        // immediately. We can then inspect the returned `AnimationResult` and decide whether
        // we should start another animation.
        animatable.updateBounds(Offset(0f, 0f), Offset(parentSize.width, parentSize.height))
        do {
            val result = animatable.animateDecay(startVelocity, exponentialDecay())
            // Copy out the end velocity of the previous animation.
            startVelocity = result.endState.velocity

            // Negate the velocity for the dimension that hits the bounds, to create a
            // bouncing off the bounds effect.
            with(animatable) {
                if (value.x == upperBound?.x || value.x == lowerBound?.x) {
                    // x dimension hits bounds
                    startVelocity = startVelocity.copy(x = -startVelocity.x)
                }
                if (value.y == upperBound?.y || value.y == lowerBound?.y) {
                    // y dimension hits bounds
                    startVelocity = startVelocity.copy(y = -startVelocity.y)
                }
            }
            // Repeat the animation until the animation ends for reasons other than hitting
            // bounds, e.g. if `stop()` is called, or preempted by another animation.
        } while (result.endReason == AnimationEndReason.BoundReached)
    }
}
```

## Summary

| ### Public constructors |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, V : https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector> https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationResult#AnimationResult(androidx.compose.animation.core.AnimationState,androidx.compose.animation.core.AnimationEndReason)( endState: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationState<T, V>, endReason: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationEndReason )` | Cmn |

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationResult#toString()()` | Cmn |

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationEndReason` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationResult#endReason()` The reason why the animation has ended. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationState<T, V>` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationResult#endState()` The state of the animation in its last frame before it's canceled or reset. | Cmn |

## Public constructors

### AnimationResult

Cmn

```
<T : Any?, V : AnimationVector> AnimationResult(
    endState: AnimationState<T, V>,
    endReason: AnimationEndReason
)
```

## Public functions

### toString

Cmn

```
open fun toString(): String
```

## Public properties

### endReason

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
val endReason: AnimationEndReason
```

The reason why the animation has ended. Could be either of the following:

- `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationEndReason#Finished`, when the animation finishes successfully without any interruption

- `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationEndReason#BoundReached` If the animation reaches the either `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animatable#lowerBound()` or `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animatable#upperBound()` in any dimension, the animation will end with `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationEndReason#BoundReached` being the end reason.

### endState

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
val endState: AnimationState<T, V>
```

The state of the animation in its last frame before it's canceled or reset. This captures the animation value/velocity/frame time, etc at the point of interruption, or before the velocity is reset when the animation finishes successfully.