# FloatSpringSpec

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/FloatAnimationSpec.kt+class:androidx.compose.animation.core.FloatSpringSpec) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0) Common/All
- Cmn

  ```
  class FloatSpringSpec : FloatAnimationSpec
  ```

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec` animation uses a spring animation to animate a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` value. Its configuration can be tuned via adjusting the spring parameters, namely damping ratio and stiffness.

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec#FloatSpringSpec(kotlin.Float,kotlin.Float,kotlin.Float)( dampingRatio: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, stiffness: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, visibilityThreshold: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` | Cmn |

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec#getDurationNanos(kotlin.Float,kotlin.Float,kotlin.Float)( initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Calculates the duration of an animation. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec#getEndVelocity(kotlin.Float,kotlin.Float,kotlin.Float)( initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Calculates the end velocity of the animation with the provided start/end values, and start velocity. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec#getValueFromNanos(kotlin.Long,kotlin.Float,kotlin.Float,kotlin.Float)( playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec#getVelocityFromNanos(kotlin.Long,kotlin.Float,kotlin.Float,kotlin.Float)( playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec#dampingRatio()` damping ratio of the spring. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec#stiffness()` Stiffness of the spring. | Cmn |

| ### Inherited functions |
|---|
| From [androidx.compose.animation.core.FloatAnimationSpec](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec) |---|---|---| | `open https://developer.android.com/reference/kotlin/androidx/compose/animation/core/VectorizedFloatAnimationSpec<V>` | `<V : https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector> https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#vectorize(androidx.compose.animation.core.TwoWayConverter)(converter: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TwoWayConverter<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, V>)` Create an `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/VectorizedAnimationSpec` that animates `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector` from a `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec`. | Cmn | |

## Public constructors

### FloatSpringSpec

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

```
FloatSpringSpec(
    dampingRatio: Float = Spring.DampingRatioNoBouncy,
    stiffness: Float = Spring.StiffnessMedium,
    visibilityThreshold: Float = Spring.DefaultDisplacementThreshold
)
```

| Parameters |
|---|---|
| `dampingRatio: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = Spring.DampingRatioNoBouncy` | damping ratio of the spring. Defaults to `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Spring#DampingRatioNoBouncy()` |
| `stiffness: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = Spring.StiffnessMedium` | Stiffness of the spring. Defaults to `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Spring#StiffnessMedium()` |
| `visibilityThreshold: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = Spring.DefaultDisplacementThreshold` | The value threshold such that the animation is no longer significant. e.g. 1px for translation animations. Defaults to `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Spring#DefaultDisplacementThreshold()` |

## Public functions

### getDurationNanos

Cmn

```
open fun getDurationNanos(
    initialValue: Float,
    targetValue: Float,
    initialVelocity: Float
): Long
```

Calculates the duration of an animation. For duration-based animations, this will return the pre-defined duration. For physics-based animations, the duration will be estimated based on the physics configuration (such as spring stiffness, damping ratio, visibility threshold) as well as the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#getDurationNanos(kotlin.Float,kotlin.Float,kotlin.Float)`, `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#getDurationNanos(kotlin.Float,kotlin.Float,kotlin.Float)` values, and `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#getDurationNanos(kotlin.Float,kotlin.Float,kotlin.Float)`.

**Note**: this may be a computation that is expensive - especially with spring based animations

| Parameters |
|---|---|
| `initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start value of the animation |
| `targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | end value of the animation |
| `initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start velocity of the animation |

### getEndVelocity

Cmn

```
open fun getEndVelocity(
    initialValue: Float,
    targetValue: Float,
    initialVelocity: Float
): Float
```

Calculates the end velocity of the animation with the provided start/end values, and start velocity. For duration-based animations, end velocity will be the velocity of the animation at the duration time. This is also the default assumption. However, for spring animations, the transient trailing velocity will be snapped to zero.

| Parameters |
|---|---|
| `initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start value of the animation |
| `targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | end value of the animation |
| `initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start velocity of the animation |

### getValueFromNanos

Cmn

```
open fun getValueFromNanos(
    playTimeNanos: Long,
    initialValue: Float,
    targetValue: Float,
    initialVelocity: Float
): Float
```

Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.

| Parameters |
|---|---|
| `playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | time since the start of the animation |
| `initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start value of the animation |
| `targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | end value of the animation |
| `initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start velocity of the animation |

### getVelocityFromNanos

Cmn

```
open fun getVelocityFromNanos(
    playTimeNanos: Long,
    initialValue: Float,
    targetValue: Float,
    initialVelocity: Float
): Float
```

Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.

| Parameters |
|---|---|
| `playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | time since the start of the animation |
| `initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start value of the animation |
| `targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | end value of the animation |
| `initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start velocity of the animation |

## Public properties

### dampingRatio

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

```
val dampingRatio: Float
```

damping ratio of the spring. Defaults to `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Spring#DampingRatioNoBouncy()`

### stiffness

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

```
val stiffness: Float
```

Stiffness of the spring. Defaults to `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Spring#StiffnessMedium()`