Object

AnchoredDraggableDefaults

Contains useful defaults for use with AnchoredDraggableState and Modifier.anchoredDraggable

RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free
Common
object AnchoredDraggableDefaults

Contains useful defaults for use with AnchoredDraggableState and Modifier.anchoredDraggable

Properties

Common
val SnapAnimationSpec: AnimationSpec<Float>

The default spec for snapping, a tween spec

Common
val PositionalThreshold: (Float) -> Float

The default positional threshold, 50% of the distance

Common
val DecayAnimationSpec: DecayAnimationSpec<Float>

The default spec for decaying, an exponential decay

Functions

flingBehavior

@Composable
    fun <T> 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 The state the fling will be performed on
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 The animation spec used to perform the settling