AnimatedVisibility وCrossfade
حرّك الظهور وتبديل المحتوى
AnimatedVisibility وCrossfade درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Animating What Appears
Sometimes you want content to slide or fade in rather than pop. AnimatedVisibility animates a Composable as it enters and exits the screen. ✨
Wrap What You Show
Give AnimatedVisibility a boolean and a content lambda. When the boolean flips, it animates that content in or out for you.
AnimatedVisibility(visible = show) {
Text("Hello!")
}Default Enter and Exit
Out of the box it uses a gentle fade plus expand and shrink. The element appears and disappears smoothly without any extra configuration.
Customize the Entrance
Set the enter parameter to choose how content arrives. Combine transitions like fadeIn and slideInVertically with the plus operator.
enter = fadeIn() + slideInVertically()Customize the Exit
The exit parameter controls how content leaves. You can mirror the entrance or pick a different effect like shrinkOut for variety.
exit = fadeOut() + shrinkVertically()Slide, Expand, Scale
Compose ships many transitions: slideIn, expandHorizontally, scaleIn, and their exit pairs. Mix them to design exactly the motion you want.
Swapping Content Smoothly
To replace one Composable with another, reach for Crossfade. It fades the old content out while the new content fades in. 🔀
Crossfade on a Key
Give Crossfade a targetState. Whenever that value changes, it animates between the content produced for the old and new states.
Crossfade(targetState = screen) { current ->
ScreenFor(current)
}Great for Tabs and Screens
Crossfade shines when switching between distinct views, like loading versus loaded states or two tabs, giving a polished blend instead of a jarring swap.
Tune the Crossfade Timing
Pass an animationSpec to Crossfade to slow down or speed up the blend. A longer tween makes the transition feel softer and more deliberate.
Crossfade(state, animationSpec = tween(700)) { ... }Pick the Right Tool
Use AnimatedVisibility to show or hide one thing, and Crossfade to swap between alternatives. Each solves a different appearance problem.
Quick Check
Which Composable smoothly swaps one piece of content for another?
Recap: Enter, Exit, Swap
You now animate appearance with AnimatedVisibility and blend between views with Crossfade, customizing enter, exit, and timing. 🎉
الأسئلة الشائعة
هل درس «AnimatedVisibility وCrossfade» مجاني؟
نعم — نص درس «AnimatedVisibility وCrossfade» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
ماذا ستتعلم في «AnimatedVisibility وCrossfade»؟
حرّك الظهور وتبديل المحتوى تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟
لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «AnimatedVisibility وCrossfade»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟
نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- animate*AsState للتدرجات البسيطة
- AnimatedVisibility وCrossfade
- updateTransition للحركة المنسقة
- الرسوم المتحركة المدفوعة بالإيماءات