0Pricing
Jetpack Compose Academy · Урок

pointerInput и detectTapGestures

Распознавайте нажатие, двойное нажатие и длительное нажатие.

«pointerInput и detectTapGestures» — бесплатный урок Jetpack Compose Academy на CoddyKit. Это урок 1 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 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» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Jetpack Compose Academy, подпишись на CoddyKit PRO. Курс Jetpack Compose Academy содержит 4 уроков всего.

Чему я научусь в уроке «pointerInput и detectTapGestures»?

Распознавайте нажатие, двойное нажатие и длительное нажатие. Ты практикуешь Jetpack Compose Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 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