0Pricing
Jetpack Compose Academy · レッスン

ジェスチャー駆動アニメーション

ドラッグやスワイプで動きを制御します。

「ジェスチャー駆動アニメーション」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはJetpack Compose Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Jetpack Compose Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Motion You Control by Touch

State-driven animations run on their own, but some motion should follow your finger. Gesture-driven animations let drags and swipes steer the movement. ✨

Track the Offset

Hold the current position in state. The most direct tool is the Animatable, which stores a value and can both jump and animate to it.

val offsetX = remember { Animatable(0f) }

Read Drag Events

Use pointerInput with detectDragGestures to receive each drag delta as the user moves their finger across the element.

Modifier.pointerInput(Unit) { detectDragGestures { _, drag -> } }

Follow the Finger

During a drag, call snapTo to move instantly to the new position. Snapping keeps the element glued to the finger with no lag.

scope.launch { offsetX.snapTo(offsetX.value + drag.x) }

Apply the Offset

Feed the value into an offset modifier so the Composable physically moves. The view tracks every pixel of the drag in real time.

Modifier.offset { IntOffset(offsetX.value.roundToInt(), 0) }

Animate on Release

When the finger lifts, switch from snap to animateTo so the element glides back home or to the nearest anchor smoothly.

scope.launch { offsetX.animateTo(0f) }

Carry the Momentum

Capture fling velocity from onDragEnd and pass it to animateDecay. The element keeps coasting after release, just like real flicks. 🌀

offsetX.animateDecay(velocity, exponentialDecay())

Swipe Between Anchors

For swipe-to-dismiss or sliders, snap to fixed stops. anchoredDraggable ties gestures to defined anchor points and settles between them.

Coroutines Drive It

Animatable updates are suspend functions, so launch them in a coroutine scope. Grab one with rememberCoroutineScope inside your Composable.

val scope = rememberCoroutineScope()

Interruptible by Design

Because gestures and animations share the same Animatable, a new touch interrupts any running animation, handing control straight back to the user.

The Feel of Native Apps

Combining snap during drag with decay and spring on release is the secret to fluid, natural gestures that feel responsive and alive.

Quick Check

While the finger is dragging, which Animatable call keeps the element glued to the touch?

Recap: Touch Meets Motion

You combined pointerInput with Animatable: snapTo while dragging, then animateTo or animateDecay on release for fluid, gesture-driven motion. 🎉

よくある質問

「ジェスチャー駆動アニメーション」レッスンは無料ですか?

はい。「ジェスチャー駆動アニメーション」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。

「ジェスチャー駆動アニメーション」で何を学びますか?

ドラッグやスワイプで動きを制御します。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Jetpack Compose Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「ジェスチャー駆動アニメーション」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このJetpack Compose Academyレッスンでコードを書いて実行できますか?

はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 単純な補間にanimate*AsStateを使う
  2. AnimatedVisibilityとCrossfade
  3. 連動した動きにupdateTransitionを使う
  4. ジェスチャー駆動アニメーション
← Jetpack Compose Academyに戻る