Skip to main content

Module draggable

Module draggable 

Source
Expand description

General drag state, for controls that are dragged but do not scroll.

A scrollbar thumb, a bottom sheet, a resizable split, a swipe-away card and a knob all want the same thing from the framework: the drag discipline the scroll containers already have — touch slop before a drag starts, axis locking so a mostly-vertical drag does not steal a horizontal gesture, yielding to whoever already consumed the event, and an observable “is this being dragged right now” for the visuals to react to.

DraggableState carries that, and Modifier::draggable runs the same gesture pipeline the scroll modifiers run, so a dragged control and a scrolled list respond to a finger identically.

let offset = rememberMutableStateOf(|| 0.0_f32);
let drag = rememberDraggableState(move |delta| offset.set(offset.get() + delta));
Box(Modifier::empty().size_points(64.0, 64.0).draggable(Axis::Horizontal, drag.clone()), …);

Deltas arrive in the same logical pixels layout uses, positive along the axis (right for Axis::Horizontal, down for Axis::Vertical).

Structs§

DraggableState
Drag position and progress for one control.

Functions§

rememberDraggableState
Remembers a DraggableState for this composition, keeping its delta handler current across recompositions.

Type Aliases§

DragDeltaHandler
What a DraggableState hands each drag delta to.