FloatSpringSpec
-
Cmn
class FloatSpringSpec : FloatAnimationSpec
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( |
Cmn
|
Public functions |
||
|---|---|---|
open Long |
getDurationNanos(Calculates the duration of an animation. |
Cmn
|
open Float |
getEndVelocity(Calculates the end velocity of the animation with the provided start/end values, and start velocity. |
Cmn
|
open Float |
getValueFromNanos(Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity. |
Cmn
|
open Float |
getVelocityFromNanos(Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity. |
Cmn
|
Inherited functions |
|||
|---|---|---|---|
|
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 |
stiffness: Float = Spring.StiffnessMedium |
Stiffness of the spring. Defaults to |
visibilityThreshold: Float = Spring.DefaultDisplacementThreshold |
The value threshold such that the animation is no longer significant. e.g. 1px for translation animations. Defaults to |
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
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.
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.
Public properties
dampingRatio
val dampingRatio: Float
damping ratio of the spring. Defaults to Spring.DampingRatioNoBouncy