Google is committed to advancing racial equity for Black communities. See how.

DragObserver

interface DragObserver
androidx.compose.ui.gesture.DragObserver

Defines the callbacks associated with dragging.

Summary

Public methods
open Unit

Override to be notified when the drag has been cancelled.

open Offset
onDrag(dragDistance: Offset)

Override to be notified when a distance has been dragged.

open Unit
onStart(downPosition: Offset)

Override to be notified when a drag has started.

open Unit
onStop(velocity: Offset)

Override to be notified when a drag has stopped.

Public methods

onCancel

open fun onCancel(): Unit

Override to be notified when the drag has been cancelled.

This is called in response to a cancellation event such as the associated PointerInputFilter having been removed from the hierarchy.

Only called if the last called if the most recent call among onStart, onStop, and onCancel was onStart.

onDrag

open fun onDrag(dragDistance: Offset): Offset

Override to be notified when a distance has been dragged.

When overridden, return the amount of the dragDistance that has been consumed.

Called immediately after onStart and for every subsequent pointer movement, as long as the movement was enough to constitute a drag (the average movement on the x or y axis is not equal to 0).

Note: This may be called multiple times in a single pass and the values should be accumulated for each call.

Parameters
dragDistance: Offset The distance that has been dragged. Reflects the average drag distance of all pointers.

onStart

open fun onStart(downPosition: Offset): Unit

Override to be notified when a drag has started.

This will be called as soon as the DragGestureDetector is allowed to start (canStartDragging is null or returns true) and the average distance the pointers have moved are not 0 on both the x and y axes.

Only called if the last called if the most recent call among onStart, onStop, and onCancel was onStop or onCancel.

Parameters
downPosition: Offset The average position of all pointer positions when they first touched down.

onStop

open fun onStop(velocity: Offset): Unit

Override to be notified when a drag has stopped.

This is called once all pointers have stopped interacting with this DragGestureDetector.

Only called if the last called if the most recent call among onStart, onStop, and onCancel was onStart.

Parameters
velocity: Offset The velocity of the drag in both orientations at the point in time when all pointers have released the relevant PointerInputFilter. In pixels per second.