الرسوم المتحركة المدفوعة بالإيماءات
حرّك العناصر استنادًا إلى السحب والتمرير
الرسوم المتحركة المدفوعة بالإيماءات درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
ماذا ستتعلم في «الرسوم المتحركة المدفوعة بالإيماءات»؟
حرّك العناصر استنادًا إلى السحب والتمرير تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟
لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «الرسوم المتحركة المدفوعة بالإيماءات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟
نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- animate*AsState للتدرجات البسيطة
- AnimatedVisibility وCrossfade
- updateTransition للحركة المنسقة
- الرسوم المتحركة المدفوعة بالإيماءات