0Pricing
Jetpack Compose Academy · Lezione

pointerInput e detectTapGestures

Rilevi tocchi, doppi tocchi e pressioni prolungate.

pointerInput e detectTapGestures è una lezione Jetpack Compose Academy gratuita su CoddyKit. Questa è la lezione 1 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Jetpack Compose Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Jetpack Compose Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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. 🎉

Domande Frequenti

La lezione «pointerInput e detectTapGestures» è gratuita?

Sì — il testo completo di «pointerInput e detectTapGestures» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Jetpack Compose Academy, passa a CoddyKit PRO. Il corso Jetpack Compose Academy include 4 lezioni in totale.

Cosa imparerò in «pointerInput e detectTapGestures»?

Rilevi tocchi, doppi tocchi e pressioni prolungate. Eserciti Jetpack Compose Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Jetpack Compose Academy?

Non è richiesta alcuna esperienza precedente. Jetpack Compose Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 1 di 4.

Quanto tempo richiede la lezione «pointerInput e detectTapGestures»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Jetpack Compose Academy?

Sì. Ogni lezione Jetpack Compose Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. pointerInput e detectTapGestures
  2. Trascinamento, swipe e fling
  3. Transform: pan, zoom e rotazione
  4. Connessioni di scorrimento annidate
← Torna a Jetpack Compose Academy