VectorizedAnimationSpec
interface VectorizedAnimationSpec<V : AnimationVector>
androidx.compose.animation.core.VectorizedAnimationSpec |
VectorizedAnimationSpecs are stateless vector based animation specifications. They do not assume any starting/ending conditions. Nor do they manage a lifecycle. All it stores is the configuration that is particular to the type of the animation. easing and duration for VectorizedTweenSpecs, or spring constants for VectorizedSpringSpecs. Its stateless nature allows the same VectorizedAnimationSpec to be reused by a few different running animations with different starting and ending values. More importantly, it allows the system to reuse the same animation spec when the animation target changes in-flight.
Since VectorizedAnimationSpecs are stateless, it requires starting value/velocity and ending value to be passed in, along with playtime, to calculate the value or velocity at that time. Play time here is the progress of the animation in terms of milliseconds, where 0 means the start of the animation and getDurationMillis returns the play time for the end of the animation.
Note: For use cases where the starting values/velocity and ending values aren't expected to change, it is recommended to use Animation that caches these static values and hence does not require them to be supplied in the value/velocity calculation.
Summary
Public methods | |
---|---|
abstract Long |
getDurationMillis(start: V, end: V, startVelocity: V) Calculates the duration of an animation. |
open V |
getEndVelocity(start: V, end: V, startVelocity: V) Calculates the end velocity of the animation with the provided start/end values, and start velocity. |
abstract V |
Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity. |
abstract V |
getVelocity(playTime: Long, start: V, end: V, startVelocity: V) Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity. |
Public methods
getDurationMillis
abstract fun getDurationMillis(
start: V,
end: V,
startVelocity: V
): 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.
Parameters | |
---|---|
start: V | start value of the animation |
end: V | end value of the animation |
startVelocity: V | start velocity of the animation |
getEndVelocity
open fun getEndVelocity(
start: V,
end: V,
startVelocity: V
): V
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 physics-based animations, end velocity is an AnimationVector of 0s.
Parameters | |
---|---|
start: V | start value of the animation |
end: V | end value of the animation |
startVelocity: V | start velocity of the animation |
getValue
abstract fun getValue(
playTime: Long,
start: V,
end: V,
startVelocity: V
): V
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: V | start value of the animation |
end: V | end value of the animation |
startVelocity: V | start velocity of the animation |
getVelocity
abstract fun getVelocity(
playTime: Long,
start: V,
end: V,
startVelocity: V
): V
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: V | start value of the animation |
end: V | end value of the animation |
startVelocity: V | start velocity of the animation |