animateToWithDecay

Function
Common
suspend fun <T> AnchoredDraggableState<T>.animateToWithDecay(
    targetValue: T,
    velocity: Float,
    snapAnimationSpec: AnimationSpec<Float> =
        if (usePreModifierChangeBehavior) {
            @Suppress("DEPRECATION") this.snapAnimationSpec
        } else AnchoredDraggableDefaults.SnapAnimationSpec,
    decayAnimationSpec: DecayAnimationSpec<Float> =
        if (usePreModifierChangeBehavior) {
            @Suppress("DEPRECATION") this.decayAnimationSpec
        } else AnchoredDraggableDefaults.DecayAnimationSpec,
): Float

Attempt to animate using decay Animation to a targetValue. If the velocity is high enough to get to the target offset, we'll use decayAnimationSpec to get to that offset and return the consumed velocity. If the velocity is not high enough, we'll use snapAnimationSpec to reach the target offset.

If the targetValue is not in the set of anchors, AnchoredDraggableState.currentValue will be updated ro the targetValue without updating the offset.

Parameters

targetValue The target value of the animation
velocity The velocity the animation should start with, in px/s
snapAnimationSpec The animation spec used if the velocity is not high enough to perform a decay to the targetValue using the decayAnimationSpec
decayAnimationSpec The animation spec used if the velocity is high enough to perform a decay to the targetValue

Returns

The velocity consumed in the animation