Package-level declarations

Types

Link copied to clipboard

Scope used for suspending anchored drag blocks. Allows to set UnstyledAnchoredDraggableState.offset to a new value.

Link copied to clipboard

DraggableAnchorsConfig stores a mutable configuration anchors, comprised of values of T and corresponding Float positions. This DraggableAnchorsConfig is used to construct an immutable UnstyledDraggableAnchors instance later on.

Link copied to clipboard
interface DraggableState

State of draggable. Allows for a granular control of how deltas are consumed by the user as well as to write custom drag methods using drag suspend function.

Link copied to clipboard
interface DragScope

Scope used for suspending drag blocks

Link copied to clipboard
class UnstyledAnchoredDraggableState<T>(initialValue: T, positionalThreshold: (totalDistance: Float) -> Float, velocityThreshold: () -> Float, val snapAnimationSpec: AnimationSpec<Float>, val decayAnimationSpec: DecayAnimationSpec<Float>, confirmValueChange: (newValue: T) -> Boolean = { true })

State of the unstyledAnchoredDraggable modifier. Use the constructor overload with anchors if the anchors are defined in composition, or update the anchors using updateAnchors.

Link copied to clipboard

Structure that represents the anchors of a UnstyledAnchoredDraggableState.

Functions

Link copied to clipboard
suspend fun <T> UnstyledAnchoredDraggableState<T>.animateTo(targetValue: T)

Animate to a targetValue. If the targetValue is not in the set of anchors, the UnstyledAnchoredDraggableState.currentValue will be updated to the targetValue without updating the offset.

Link copied to clipboard
suspend fun <T> UnstyledAnchoredDraggableState<T>.animateToWithDecay(targetValue: T, velocity: Float): 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 UnstyledAnchoredDraggableState.decayAnimationSpec to get to that offset and return the consumed velocity. If the velocity is not high enough, we'll use UnstyledAnchoredDraggableState.snapAnimationSpec to reach the target offset.

Link copied to clipboard

Reads pointer input events until a drag is detected or all pointers are up. When the final pointer is raised, the up event is returned. When a drag event is detected, the drag change will be returned. Note that if pointerId has been raised, another pointer that is down will be used, if available, so the returned PointerInputChange.id may differ from pointerId. If the position change in the any direction has been consumed by the PointerEventPass.Main pass, then the drag is considered canceled and null is returned. If pointerId is not down when awaitDragOrCancellation is called, then null is returned.

Link copied to clipboard

Reads pointer input events until a horizontal drag is detected or all pointers are up. When the final pointer is raised, the up event is returned. When a drag event is detected, the drag change will be returned. Note that if pointerId has been raised, another pointer that is down will be used, if available, so the returned PointerInputChange.id may differ from pointerId. If the position change has been consumed by the PointerEventPass.Main pass, then the drag is considered canceled and null is returned. If pointerId is not down when awaitHorizontalDragOrCancellation is called, then null is returned.

Link copied to clipboard
suspend fun AwaitPointerEventScope.awaitHorizontalTouchSlopOrCancellation(pointerId: PointerId, onTouchSlopReached: (change: PointerInputChange, overSlop: Float) -> Unit): PointerInputChange?

Waits for horizontal drag motion to pass touch slop, using pointerId as the pointer to examine. If pointerId is raised, another pointer from those that are down will be chosen to lead the gesture, and if none are down, null is returned.

Link copied to clipboard

Waits for a long press by examining pointerId.

Link copied to clipboard
suspend fun AwaitPointerEventScope.awaitTouchSlopOrCancellation(pointerId: PointerId, onTouchSlopReached: (change: PointerInputChange, overSlop: Offset) -> Unit): PointerInputChange?

Waits for drag motion to pass touch slop, using pointerId as the pointer to examine. If pointerId is raised, another pointer from those that are down will be chosen to lead the gesture, and if none are down, null is returned. If pointerId is not down when awaitTouchSlopOrCancellation is called, then null is returned.

Link copied to clipboard

Reads pointer input events until a vertical drag is detected or all pointers are up. When the final pointer is raised, the up event is returned. When a drag event is detected, the drag change will be returned. Note that if pointerId has been raised, another pointer that is down will be used, if available, so the returned PointerInputChange.id may differ from pointerId. If the position change has been consumed by the PointerEventPass.Main pass, then the drag is considered canceled and null is returned. If pointerId is not down when awaitVerticalDragOrCancellation is called, then null is returned.

Link copied to clipboard
suspend fun AwaitPointerEventScope.awaitVerticalTouchSlopOrCancellation(pointerId: PointerId, onTouchSlopReached: (change: PointerInputChange, overSlop: Float) -> Unit): PointerInputChange?

Waits for vertical drag motion to pass touch slop, using pointerId as the pointer to examine. If pointerId is raised, another pointer from those that are down will be chosen to lead the gesture, and if none are down, null is returned. If pointerId is not down when awaitVerticalTouchSlopOrCancellation is called, then null is returned.

Link copied to clipboard
suspend fun PointerInputScope.detectDragGestures(onDragStart: (Offset) -> Unit = { }, onDragEnd: () -> Unit = { }, onDragCancel: () -> Unit = { }, onDrag: (change: PointerInputChange, dragAmount: Offset) -> Unit)

Gesture detector that waits for pointer down and touch slop in any direction and then calls onDrag for each drag event. It follows the touch slop detection of awaitTouchSlopOrCancellation but will consume the position change automatically once the touch slop has been crossed.

Link copied to clipboard
suspend fun PointerInputScope.detectDragGesturesAfterLongPress(onDragStart: (Offset) -> Unit = { }, onDragEnd: () -> Unit = { }, onDragCancel: () -> Unit = { }, onDrag: (change: PointerInputChange, dragAmount: Offset) -> Unit)

Gesture detector that waits for pointer down and long press, after which it calls onDrag for each drag event.

Link copied to clipboard
suspend fun PointerInputScope.detectHorizontalDragGestures(onDragStart: (Offset) -> Unit = { }, onDragEnd: () -> Unit = { }, onDragCancel: () -> Unit = { }, onHorizontalDrag: (change: PointerInputChange, dragAmount: Float) -> Unit)

Gesture detector that waits for pointer down and touch slop in the horizontal direction and then calls onHorizontalDrag for each horizontal drag event. It follows the touch slop detection of awaitHorizontalTouchSlopOrCancellation, but will consume the position change automatically once the touch slop has been crossed.

Link copied to clipboard
suspend fun PointerInputScope.detectVerticalDragGestures(onDragStart: (Offset) -> Unit = { }, onDragEnd: () -> Unit = { }, onDragCancel: () -> Unit = { }, onVerticalDrag: (change: PointerInputChange, dragAmount: Float) -> Unit)

Gesture detector that waits for pointer down and touch slop in the vertical direction and then calls onVerticalDrag for each vertical drag event. It follows the touch slop detection of awaitVerticalTouchSlopOrCancellation, but will consume the position change automatically once the touch slop has been crossed.

Link copied to clipboard
suspend fun AwaitPointerEventScope.drag(pointerId: PointerId, onDrag: (PointerInputChange) -> Unit): Boolean

Reads position change events for pointerId and calls onDrag for every change in position. If pointerId is raised, a new pointer is chosen from those that are down and if none exist, the method returns. This does not wait for touch slop.

Link copied to clipboard
fun Modifier.draggable(state: DraggableState, orientation: Orientation, enabled: Boolean = true, interactionSource: MutableInteractionSource? = null, startDragImmediately: Boolean = false, onDragStarted: suspend CoroutineScope.(startedPosition: Offset) -> Unit = NoOpOnDragStarted, onDragStopped: suspend CoroutineScope.(velocity: Float) -> Unit = NoOpOnDragStopped, reverseDirection: Boolean = false): Modifier

Configure touch dragging for the UI element in a single Orientation. The drag distance reported to DraggableState, allowing users to react on the drag delta and update their state.

Link copied to clipboard

Default implementation of DraggableState interface that allows to pass a simple action that will be invoked when the drag occurs.

Link copied to clipboard

Reads horizontal position change events for pointerId and calls onDrag for every change in position. If pointerId is raised, a new pointer is chosen from those that are down and if none exist, the method returns. This does not wait for touch slop.

Link copied to clipboard

Create and remember default implementation of DraggableState interface that allows to pass a simple action that will be invoked when the drag occurs.

Link copied to clipboard
suspend fun <T> UnstyledAnchoredDraggableState<T>.snapTo(targetValue: T)

Snap to a targetValue without any animation. If the targetValue is not in the set of anchors, the UnstyledAnchoredDraggableState.currentValue will be updated to the targetValue without updating the offset.

Link copied to clipboard
fun <T> Modifier.unstyledAnchoredDraggable(state: UnstyledAnchoredDraggableState<T>, reverseDirection: Boolean, orientation: Orientation, enabled: Boolean = true, interactionSource: MutableInteractionSource? = null, startDragImmediately: Boolean = state.isAnimationRunning): Modifier

Enable drag gestures between a set of predefined values.

Link copied to clipboard

Create a new UnstyledDraggableAnchors instance using a builder function.

Link copied to clipboard

Reads vertical position change events for pointerId and calls onDrag for every change in position. If pointerId is raised, a new pointer is chosen from those that are down and if none exist, the method returns. This does not wait for touch slop