0Pricing
Jetpack Compose Academy · Lekcja

Animacje sterowane gestami

Steruj ruchem za pomocą przeciągnięć i przesunięć

Animacje sterowane gestami to bezpłatna lekcja Jetpack Compose Academy na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Jetpack Compose Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Jetpack Compose Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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

Często zadawane pytania

Czy lekcja „Animacje sterowane gestami” jest bezpłatna?

Tak — pełny tekst „Animacje sterowane gestami” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Jetpack Compose Academy, przejdź na CoddyKit PRO. Kurs Jetpack Compose Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Animacje sterowane gestami”?

Steruj ruchem za pomocą przeciągnięć i przesunięć Ćwiczysz Jetpack Compose Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Jetpack Compose Academy?

Nie wymagamy żadnego doświadczenia. Jetpack Compose Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Animacje sterowane gestami”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Jetpack Compose Academy?

Tak. Każda lekcja Jetpack Compose Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. animate*AsState dla prostych interpolacji
  2. AnimatedVisibility i Crossfade
  3. updateTransition dla skoordynowanego ruchu
  4. Animacje sterowane gestami
← Powrót do Jetpack Compose Academy