FloatSpringSpec
class FloatSpringSpec : FloatAnimationSpec
kotlin.Any | |
↳ | androidx.compose.animation.core.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 | |
---|---|
<init>(dampingRatio: Float = Spring.DampingRatioNoBouncy, stiffness: Float = Spring.StiffnessMedium, visibilityThreshold: Float = Spring.DefaultDisplacementThreshold) FloatSpringSpec animation uses a spring animation to animate a Float value. |
Public methods | |
---|---|
Long |
getDurationMillis(start: Float, end: Float, startVelocity: Float) Calculates the duration of an animation. |
Float |
getEndVelocity(start: Float, end: Float, startVelocity: Float) Calculates the end velocity of the animation with the provided start/end values, and start velocity. |
Float |
Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity. |
Float |
getVelocity(playTime: Long, start: Float, end: Float, startVelocity: Float) Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity. |
Inherited functions | |
---|---|
Properties | |
---|---|
Float |
damping ratio of the spring. |
Float |
Stiffness of the spring. |
Public constructors
<init>
FloatSpringSpec(
dampingRatio: Float = Spring.DampingRatioNoBouncy,
stiffness: Float = Spring.StiffnessMedium,
visibilityThreshold: Float = Spring.DefaultDisplacementThreshold)
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.
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 methods
getDurationMillis
fun getDurationMillis(
start: Float,
end: Float,
startVelocity: 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 start, end values, and startVelocity.
Note: this may be a computation that is expensive - especially with spring based animations
Parameters | |
---|---|
start: Float | start value of the animation |
end: Float | end value of the animation |
startVelocity: Float | start velocity of the animation |
getEndVelocity
fun getEndVelocity(
start: Float,
end: Float,
startVelocity: 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 | |
---|---|
start: Float | start value of the animation |
end: Float | end value of the animation |
startVelocity: Float | start velocity of the animation |
getValue
fun getValue(
playTime: Long,
start: Float,
end: Float,
startVelocity: Float
): Float
Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.
Parameters | |
---|---|
playTime: Long | time since the start of the animation |
start: Float | start value of the animation |
end: Float | end value of the animation |
startVelocity: Float | start velocity of the animation |
getVelocity
fun getVelocity(
playTime: Long,
start: Float,
end: Float,
startVelocity: Float
): Float
Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.
Parameters | |
---|---|
playTime: Long | time since the start of the animation |
start: Float | start value of the animation |
end: Float | end value of the animation |
startVelocity: Float | start velocity of the animation |
Properties
dampingRatio
val dampingRatio: Float
damping ratio of the spring. Defaults to Spring.DampingRatioNoBouncy