0Pricing
Jetpack Compose Academy · บทเรียน

pointerInput และ detectTapGestures

ตรวจจับการแตะ แตะสองครั้ง และกดค้าง

pointerInput และ detectTapGestures เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

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

คำถามที่พบบ่อย

บทเรียน “pointerInput และ detectTapGestures” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “pointerInput และ detectTapGestures” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “pointerInput และ detectTapGestures”

ตรวจจับการแตะ แตะสองครั้ง และกดค้าง คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “pointerInput และ detectTapGestures” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม

ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. pointerInput และ detectTapGestures
  2. ลาก ปัด และสะบัด
  3. การแปลง: เลื่อน ซูม และหมุน
  4. การเชื่อมต่อการเลื่อนซ้อนกัน
← กลับไปที่ Jetpack Compose Academy