by @alexstyl
✉️ Leave your feedback

← Back to Foundation

draggable2D

Modifier
in
Foundation
. Since 1.6.0-beta01

Overview

Examples

Community Notes

Configure touch dragging for the UI element in both orientations. The drag distance reported to Draggable2DState, allowing users to react to the drag delta and update their state.

The common common usecase for this component is when you need to be able to drag something inside the component on the screen and represent this state via one float value

If you are implementing dragging in a single orientation, consider using draggable.

Overloads

draggable2D

@Suppress("PrimitiveInLambda")
@ExperimentalFoundationApi
fun Modifier.draggable2D(
    state: Draggable2DState,
    enabled: Boolean = true,
    interactionSource: MutableInteractionSource? = null,
    startDragImmediately: Boolean = false,
    onDragStarted: suspend CoroutineScope.(startedPosition: Offset) -> Unit = {},
    onDragStopped: suspend CoroutineScope.(velocity: Velocity) -> Unit = {},
    reverseDirection: Boolean = false
)

Parameters

NameDescription
stateDraggable2DState state of the draggable2D. Defines how drag events will be interpreted by the user land logic.
enabledwhether or not drag is enabled
interactionSourceMutableInteractionSource that will be used to emit DragInteraction.Start when this draggable is being dragged.
startDragImmediatelywhen set to true, draggable2D will start dragging immediately and prevent other gesture detectors from reacting to "down" events (in order to block composed press-based gestures). This is intended to allow end users to "catch" an animating widget by pressing on it. It's useful to set it when value you're dragging is settling / animating.
onDragStartedcallback that will be invoked when drag is about to start at the starting position, allowing user to suspend and perform preparation for drag, if desired.This suspend function is invoked with the draggable2D scope, allowing for async processing, if desired. Note that the scope used here is the onw provided by the draggable2D node, for long running work that needs to outlast the modifier being in the composition you should use a scope that fits the lifecycle needed.
onDragStoppedcallback that will be invoked when drag is finished, allowing the user to react on velocity and process it. This suspend function is invoked with the draggable2D scope, allowing for async processing, if desired. Note that the scope used here is the onw provided by the draggable2D scope, for long running work that needs to outlast the modifier being in the composition you should use a scope that fits the lifecycle needed.
reverseDirectionreverse the direction of the scroll, so top to bottom scroll will behave like bottom to top and left to right will behave like right to left
Next ComponentBaseTextField