Compose Modifier

draggable2D

Configure touch dragging for the UI element in both orientations.

draggable2D

Common
fun Modifier.draggable2D(
    state: Draggable2DState,
    enabled: Boolean = true,
    interactionSource: MutableInteractionSource? = null,
    startDragImmediately: Boolean = false,
    onDragStarted: (startedPosition: Offset) -> Unit = NoOpOnDragStart,
    onDragStopped: (velocity: Velocity) -> Unit = NoOpOnDragStop,
    reverseDirection: Boolean = false,
): Modifier

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.

Parameters

state Draggable2DState state of the draggable2D. Defines how drag events will be interpreted by the user land logic.
enabled whether or not drag is enabled
interactionSource MutableInteractionSource that will be used to emit DragInteraction.Start when this draggable is being dragged.
startDragImmediately when 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.
onDragStarted callback that will be invoked when drag is about to start at the starting position, allowing user to perform preparation for drag.
onDragStopped callback that will be invoked when drag is finished, allowing the user to react on velocity and process it.
reverseDirection reverse the direction of the dragging, so top to bottom dragging will behave like bottom to top and left to right will behave like right to left.