pointerInputとdetectTapGestures
タップ、ダブルタップ、長押しを検出します。
「pointerInputとdetectTapGestures」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。
「pointerInputとdetectTapGestures」で何を学びますか?
タップ、ダブルタップ、長押しを検出します。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Jetpack Compose Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「pointerInputとdetectTapGestures」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このJetpack Compose Academyレッスンでコードを書いて実行できますか?
はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- pointerInputとdetectTapGestures
- ドラッグ、スワイプ、フリング
- Transform:パン、ズーム、回転
- ネストされたスクロール接続