pointerInput & detectTapGestures
Deteksi ketukan, ketukan ganda, dan tekan lama.
pointerInput & detectTapGestures adalah pelajaran Jetpack Compose Academy gratis di CoddyKit. Ini adalah pelajaran 1 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Jetpack Compose Academy, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Jetpack Compose Academy mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
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. 🎉
Pertanyaan yang Sering Diajukan
Apakah pelajaran “pointerInput & detectTapGestures” gratis?
Ya — teks lengkap “pointerInput & detectTapGestures” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Jetpack Compose Academy, upgrade ke CoddyKit PRO. Kursus Jetpack Compose Academy mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “pointerInput & detectTapGestures”?
Deteksi ketukan, ketukan ganda, dan tekan lama. Kamu berlatih Jetpack Compose Academy dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Jetpack Compose Academy?
Tidak diperlukan pengalaman sebelumnya. Jetpack Compose Academy di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 1 dari 4.
Berapa lama pelajaran “pointerInput & detectTapGestures” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Jetpack Compose Academy ini?
Ya. Setiap pelajaran Jetpack Compose Academy menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- pointerInput & detectTapGestures
- Seret, Usap & Lontar
- Transformasi: Geser, Perbesar & Putar
- Koneksi Gulir Bersarang