AnchoredDraggableDefaults


Contains useful defaults for use with AnchoredDraggableState and Modifier.anchoredDraggable

Summary

Public functions

TargetedFlingBehavior
@Composable
<T : Any?> flingBehavior(
    state: AnchoredDraggableState<T>,
    positionalThreshold: (totalDistance: Float) -> Float,
    animationSpec: AnimationSpec<Float>
)

Create and remember a TargetedFlingBehavior for use with Modifier.anchoredDraggable that will find the target based on the velocity and positionalThreshold when performing a fling, and settle to that target.

Cmn

Public properties

DecayAnimationSpec<Float>

The default spec for decaying, an exponential decay

Cmn
(Float) -> Float

The default positional threshold, 50% of the distance

Cmn
AnimationSpec<Float>

The default spec for snapping, a tween spec

Cmn

Public functions

flingBehavior

@Composable
fun <T : Any?> flingBehavior(
    state: AnchoredDraggableState<T>,
    positionalThreshold: (totalDistance: Float) -> Float = PositionalThreshold,
    animationSpec: AnimationSpec<Float> = SnapAnimationSpec
): TargetedFlingBehavior

Create and remember a TargetedFlingBehavior for use with Modifier.anchoredDraggable that will find the target based on the velocity and positionalThreshold when performing a fling, and settle to that target.

There are two paths: a) If the velocity is bigger than AnchoredDraggableMinFlingVelocity (125 dp/s), the fling behavior will move to the next closest anchor in the fling direction, determined by the sign of the fling velocity. b) If the velocity is smaller than AnchoredDraggableMinFlingVelocity (125 dp/s), the fling behavior will consider the positional thresholds, by default AnchoredDraggableDefaults.PositionalThreshold. If the offset has crossed the threshold when performing the fling, the fling behavior will move to the next anchor in the fling direction. Otherwise, it will move back to the previous anchor.

Parameters
state: AnchoredDraggableState<T>

The state the fling will be performed on

positionalThreshold: (totalDistance: Float) -> Float = PositionalThreshold

The positional threshold, in px, to be used when calculating the target state while a drag is in progress and when settling after the drag ends. This is the distance from the start of a transition. It will be, depending on the direction of the interaction, added or subtracted from/to the origin offset. It should always be a positive value.

animationSpec: AnimationSpec<Float> = SnapAnimationSpec

The animation spec used to perform the settling

Public properties

DecayAnimationSpec

val DecayAnimationSpecDecayAnimationSpec<Float>

The default spec for decaying, an exponential decay

PositionalThreshold

val PositionalThreshold: (Float) -> Float

The default positional threshold, 50% of the distance

SnapAnimationSpec

val SnapAnimationSpecAnimationSpec<Float>

The default spec for snapping, a tween spec