0Pricing
Jetpack Compose Academy · Lesson

pointerInput & detectTapGestures

Detect tap, double-tap, and long press.

pointerInput & detectTapGestures is a free Jetpack Compose Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Gateway to Touch

To handle raw touch in Compose you reach for the pointerInput modifier. It gives any element a place to read finger events directly. 👆

Add It to Any Composable

Attach pointerInput in a Modifier chain. Inside its lambda you get a gesture scope where you can listen for taps, drags, and more.

Box(Modifier.pointerInput(Unit) {
  // gesture detectors go here
})

Detect Simple Taps

The friendliest helper is detectTapGestures. It bundles tap, double tap, long press, and press into one tidy call for you.

detectTapGestures(onTap = { /* tapped */ })

A Single Quick Tap

The onTap lambda fires when a finger presses and lifts without moving much. It receives the Offset where the tap landed.

detectTapGestures(onTap = { offset -> println(offset) })

Catch a Double Tap

Pass onDoubleTap to react to two quick taps in a row. It is perfect for a like or zoom shortcut on an image. 💙

detectTapGestures(onDoubleTap = { /* zoom in */ })

Hold for Long Press

The onLongPress lambda fires after the finger stays down past a threshold. Use it to open context menus or selection mode.

detectTapGestures(onLongPress = { /* show menu */ })

Track the Press Itself

Use onPress to know the moment a finger touches down. Its lambda is suspendable, so you can await release or cancellation.

detectTapGestures(onPress = { awaitRelease() })

Every Tap Carries Position

Each tap callback hands you an Offset in pixels, measured from the top-left of the composable. Read it to know exactly where the user touched.

The Key Argument Matters

The first argument to pointerInput is a key. When it changes the gesture block restarts, so pass any state your handlers depend on.

Modifier.pointerInput(enabled) { /* restarts if enabled flips */ }

Gestures Run in Coroutines

The pointerInput block is a suspend scope. That is why detectors can await events frame by frame without blocking the UI thread.

Combine Several Callbacks

One detectTapGestures call can take tap, double tap, and long press together. Compose figures out which one the user meant.

detectTapGestures(onTap = {...}, onLongPress = {...})

Quick Check

Which helper bundles tap, double tap, and long press into one call?

Recap: Raw Taps Made Easy

You met pointerInput and detectTapGestures for tap, double tap, and long press. They are your foundation for custom touch handling. 🎉

Frequently asked questions

Is the “pointerInput & detectTapGestures” lesson free?

Yes — the full text of “pointerInput & detectTapGestures” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.

What will I learn in “pointerInput & detectTapGestures”?

Detect tap, double-tap, and long press. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Jetpack Compose Academy?

No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “pointerInput & detectTapGestures” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Jetpack Compose Academy lesson?

Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. pointerInput & detectTapGestures
  2. Drag, Swipe & Fling
  3. Transform: Pan, Zoom & Rotate
  4. Nested Scroll Connections
← Back to Jetpack Compose Academy