pointerInput und detectTapGestures
Erkennen Sie Taps, Doppeltaps und langes Drücken.
pointerInput und detectTapGestures ist eine kostenlose Jetpack Compose Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Jetpack Compose Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. 🎉
Häufig gestellte Fragen
Ist die Lektion „pointerInput und detectTapGestures“ kostenlos?
Ja — der vollständige Text von „pointerInput und detectTapGestures“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Jetpack Compose Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „pointerInput und detectTapGestures“?
Erkennen Sie Taps, Doppeltaps und langes Drücken. Du übst Jetpack Compose Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Jetpack Compose Academy zu starten?
Keine Vorkenntnisse erforderlich. Jetpack Compose Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „pointerInput und detectTapGestures“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Jetpack Compose Academy-Lektion Code schreiben und ausführen?
Ja. Jede Jetpack Compose Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- pointerInput und detectTapGestures
- Ziehen, Wischen und Schleudern
- Transform: Schwenken, Zoomen und Drehen
- Verschachtelte Scroll-Verbindungen