0Pricing
Jetpack Compose Academy · درس

‏animate*AsState للتدرجات البسيطة

حرّك قيمة واحدة تلقائيًا

‏animate*AsState للتدرجات البسيطة درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Animation, the Easy Way

Compose can animate changes for you. The simplest tool is the animate*AsState family, which smoothly moves a value from old to new. ✨

What animateDpAsState Does

When your target value changes, animateDpAsState returns a State that glides toward it over a few frames instead of jumping.

val size by animateDpAsState(targetValue = if (big) 200.dp else 100.dp)

Read It Like Normal State

The animated value is just a State you read with by. Use it in a Modifier and the UI follows the animation every frame.

Box(Modifier.size(size).background(Color.Blue))

A Whole Family of Helpers

There is one per type: animateFloatAsState, animateColorAsState, animateDpAsState, and more. Pick the one matching the value you want to tween.

Animate a Color

Use animateColorAsState to fade between colors. Toggle a boolean and watch the background shift smoothly from one tint to another. 🎨

val color by animateColorAsState(if (on) Color.Green else Color.Gray)

Animate Transparency

For fade in and out, animate a float and feed it to alpha. A value of 0f is invisible, 1f is fully opaque.

val a by animateFloatAsState(if (visible) 1f else 0f)
Box(Modifier.alpha(a))

Choose the Pace

Pass an animationSpec to control timing. A tween lets you set the duration in milliseconds and an easing curve.

animateDpAsState(target, animationSpec = tween(durationMillis = 500))

Spring for Bounce

Swap in a spring spec for natural, physics-based motion. Tune dampingRatio and stiffness to add a little playful bounce.

animateDpAsState(target, animationSpec = spring(dampingRatio = 0.4f))

It Reacts to State

You never call start or stop. When the target value changes during recomposition, the animation restarts toward the new goal automatically.

Smooth, Not Linear

Default easing makes motion feel alive by speeding up then slowing down. Easing curves like FastOutSlowInEasing avoid robotic, constant-speed movement.

Listen When It Finishes

Need to react when motion ends? Pass a finishedListener lambda, which fires once with the final value after the animation settles.

animateDpAsState(target) { final -> /* done */ }

Quick Check

Which spec gives motion a natural, bouncy physics feel?

Recap: One Value at a Time

You learned animate*AsState: change a target, read the animated State, and pick tween or spring. It is the quickest way to add smooth single-value motion. 🎉

الأسئلة الشائعة

هل درس «‏animate*AsState للتدرجات البسيطة» مجاني؟

نعم — نص درس «‏animate*AsState للتدرجات البسيطة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.

ماذا ستتعلم في «‏animate*AsState للتدرجات البسيطة»؟

حرّك قيمة واحدة تلقائيًا تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟

لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «‏animate*AsState للتدرجات البسيطة»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟

نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. ‏animate*AsState للتدرجات البسيطة
  2. ‏AnimatedVisibility وCrossfade
  3. ‏updateTransition للحركة المنسقة
  4. الرسوم المتحركة المدفوعة بالإيماءات
← العودة إلى Jetpack Compose Academy