FloatSpringSpec


FloatSpringSpec animation uses a spring animation to animate a Float value. Its configuration can be tuned via adjusting the spring parameters, namely damping ratio and stiffness.

Summary

Public constructors

FloatSpringSpec(
    dampingRatio: Float,
    stiffness: Float,
    visibilityThreshold: Float
)
Cmn

Public functions

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

Calculates the duration of an animation.

Cmn
open Float
getEndVelocity(
    initialValue: Float,
    targetValue: Float,
    initialVelocity: Float
)

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

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

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

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

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

Cmn

Public properties

Float

damping ratio of the spring.

Cmn
Float

Stiffness of the spring.

Cmn

Public constructors

FloatSpringSpec

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

damping ratio of the spring. Defaults to Spring.DampingRatioNoBouncy

stiffness: Float = Spring.StiffnessMedium

Stiffness of the spring. Defaults to Spring.StiffnessMedium

visibilityThreshold: Float = Spring.DefaultDisplacementThreshold

The value threshold such that the animation is no longer significant. e.g. 1px for translation animations. Defaults to Spring.DefaultDisplacementThreshold

Public functions

getDurationNanos

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 initialValue, targetValue values, and initialVelocity.

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

Parameters
initialValue: Float

start value of the animation

targetValue: Float

end value of the animation

initialVelocity: Float

start velocity of the animation

getEndVelocity

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: Float

start value of the animation

targetValue: Float

end value of the animation

initialVelocity: Float

start velocity of the animation

getValueFromNanos

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: Long

time since the start of the animation

initialValue: Float

start value of the animation

targetValue: Float

end value of the animation

initialVelocity: Float

start velocity of the animation

getVelocityFromNanos

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: Long

time since the start of the animation

initialValue: Float

start value of the animation

targetValue: Float

end value of the animation

initialVelocity: Float

start velocity of the animation

Public properties

dampingRatio

val dampingRatioFloat

damping ratio of the spring. Defaults to Spring.DampingRatioNoBouncy

stiffness

val stiffnessFloat

Stiffness of the spring. Defaults to Spring.StiffnessMedium