# Detecting Touch Input in Compose: Tap, Drag, and Transform Gestures

> Compose ships one detect*Gestures function per touch shape, tap, drag, and transform. A map of what each one hands you and when to reach for it.

**Date:** 2026-10-26T00:00:00.000Z
**Tags:** Gesture

## The intuition

Every touch gesture in Compose starts the same way: a `Modifier.pointerInput`
block and a suspend function you hand it. What changes is which function,
because each one is a purpose-built loop over the same raw pointer event
stream, shaped for one kind of gesture.

Pick the wrong one and you either fight the API (parsing raw offsets
yourself to detect a tap) or get handed data you didn't ask for (rotation
values for a gesture that's only a drag).

* `detectTapGestures` for a single point that doesn't move: tap,
  double-tap, long-press.
* `detectDragGestures` (and its horizontal/vertical siblings) for a single
  point that does move, one direction at a time.
* `detectTransformGestures` for two or more fingers at once: pinch, pan,
  rotate.

## Tap, double-tap, long-press: `detectTapGestures`

```kotlin
Modifier.pointerInput(Unit) {
    detectTapGestures(
        onTap = { /* single tap */ },
        onDoubleTap = { /* second tap within the double-tap window */ },
        onLongPress = { /* held past the long-press threshold */ },
        onPress = { /* fires on every press down, before Compose knows
                       which gesture this will resolve to */ }
    )
}
```

`onPress` is a `PressGestureScope` lambda, so it gets `awaitRelease()` and
`tryAwaitRelease()`, release detection without blocking the other
callbacks, useful for press-and-hold-style feedback.

Only the callbacks you pass get wired up. Passing just `onTap` means
Compose never bothers waiting out the double-tap window, so a lone tap
resolves immediately instead of waiting to see if a second tap follows.

Reach for this over `Modifier.clickable` when you need something it
doesn't expose: double-tap-to-like, a long-press context menu, a
press-state scale or color change you control yourself.

> **Don't stack this on clickable**
>
> Adding `detectTapGestures` to a node that already has
> `Modifier.clickable`/`combinedClickable` installs two competing gesture
> detectors on the same pointer stream, and you lose the ripple and
> accessibility semantics `clickable` gives you for free. Pick one.

## Single-axis drag: `detectDragGestures` and its horizontal/vertical pair

```kotlin
Modifier.pointerInput(Unit) {
    detectDragGestures(
        onDragStart = { offset -> /* finger moved past touch slop */ },
        onDrag = { change, dragAmount -> change.consume() /* dragAmount: Offset, both axes */ },
        onDragEnd = { /* finger lifted */ },
        onDragCancel = { /* gesture interrupted, e.g. another pointer took over */ }
    )
}
```

`onDrag` hands you a `PointerInputChange` plus a `dragAmount: Offset`, the
delta since the last event, not the total drag distance. You call
`change.consume()` yourself; `detectDragGestures` won't claim the gesture
for you.

> **An unconsumed drag leaks to the parent**
>
> Skipping `change.consume()` doesn't just make the gesture feel laggy. A
> parent `scrollable`/`verticalScroll` further up the tree never learns the
> pointer was already claimed, and scrolls at the same time your drag does.

`detectHorizontalDragGestures` and `detectVerticalDragGestures` are the
same shape, minus a dimension: `onHorizontalDrag`/`onVerticalDrag` hand
you a `Float` delta instead of an `Offset`, and only that axis's{" "}
slop (A small movement threshold a touch must cross before a gesture detector commits to it, so a shaky tap or a trembling finger doesn't get misread as a drag.){" "}
has to clear to start the gesture. Reach for these over the two-axis
version whenever the gesture is genuinely one-directional (a swipeable
row, a vertical slider), so a diagonal finger movement doesn't win the
gesture on the wrong axis, and so a vertical list above it still gets to
scroll normally.

## Pinch, pan, rotate: `detectTransformGestures`

```kotlin
Modifier.pointerInput(Unit) {
    detectTransformGestures(
        panZoomLock = false
    ) { centroid, pan, zoom, rotation ->
        /* centroid: Offset, midpoint between the active pointers
           pan: Offset, translation since the last event
           zoom: Float, scale factor since the last event (1f = unchanged)
           rotation: Float, degrees since the last event */
    }
}
```

Centroid (The midpoint of all active pointers in a multi-touch gesture, recomputed every event as fingers move.){" "}
is why `detectTransformGestures` takes one callback instead of four: pan,
zoom, and rotation aren't separate gestures, they're three numbers Compose
derives from the same multi-pointer event every frame, so there's nothing
to resolve between the way there is between a tap and a long-press.

`panZoomLock = true` does the opposite of what the name suggests: it
locks *rotation* out, not pan or zoom. Whichever threshold the gesture
crosses first decides its shape for the rest of the gesture, pan/zoom
first means rotation stays at `0f` from then on. Useful for a
pinch-to-zoom image viewer or map, where you want pan and zoom but don't
want two fingers pinching to also read as an accidental rotate. A crop
tool that combines all three in one gesture is the case for leaving it
`false`.

> **zoom and rotation are deltas, not totals**
>
> `zoom` and `rotation` are the change since the last event, not the
> gesture's running total. Multiply into your own accumulator
> (`scale *= zoom`), don't assign (`scale = zoom`), or your transform
> resets every frame instead of accumulating.

## Picking between them

| Function | Pointers | Callbacks | Delta shape |
|---|---|---|---|
| `detectTapGestures` | 1, stays put | `onTap`, `onDoubleTap`, `onLongPress`, `onPress` | none, position only |
| `detectDragGestures` | 1, moves | `onDragStart`, `onDrag`, `onDragEnd`, `onDragCancel` | `Offset` per event |
| `detectHorizontalDragGestures` / `detectVerticalDragGestures` | 1, moves on one axis | same shape, `onHorizontalDrag`/`onVerticalDrag` | `Float` per event |
| `detectTransformGestures` | 2+ | one `onGesture` callback | `centroid`, `pan`: `Offset`; `zoom`, `rotation`: `Float` |

## Combining detectors, and the primitive underneath

A single `Modifier.pointerInput` block can only run one `detect*Gestures`
call, because each one is an infinite loop (built on `awaitEachGesture`)
that never returns while the block is alive. Writing
`detectTapGestures(...)` followed by `detectDragGestures(...)` in the
same block doesn't race them, the second call is simply unreachable code.
Needing a tap *and* a drag on the same node means giving each its own
`pointerInput` modifier instead, Compose runs both in parallel, each
watching the same raw stream independently.

Which pointer stays available to the second detector comes down to touch
slop and which `PointerInputChange` gets consumed first, mechanics this
blog covers on their own.

Every one of these functions is a loop written in terms of
`awaitPointerEventScope`/`awaitEachGesture`, the lower-level primitive
`PointerInputScope` actually exposes. You drop to it directly only when
none of the four above fit, a custom multi-stage gesture, for instance,
that needs to switch what it's listening for mid-stream.

> **Key pointerInput on what the lambda actually reads**
>
> All four are installed through `Modifier.pointerInput(key)`. Key it on
> `Unit` while the lambda closes over state that changes, and the block
> never reinstalls, so it keeps reading whatever that state was on first
> composition. Key it on the state the callback reads, or read that state
> through `rememberUpdatedState` instead.


---

Canonical page: https://recomposed.blog/detecting-touch-input-tap-drag-transform