إعادة التركيب: ما الذي يسبب إعادة الرسم
افهم متى يعيد Compose تشغيل التعليمات البرمجية
إعادة التركيب: ما الذي يسبب إعادة الرسم درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
What Is Recomposition?
Recomposition is Compose re-running your Composable functions to update the screen after some state they read has changed.
Triggered by State Reads
A redraw is triggered only when a piece of state a Composable read actually changes. No state change means no recomposition.
Only Readers Re-Run
Compose is smart: it re-runs only the Composables that read the changed state, not your whole screen. This keeps updates cheap.
Recomposition Can Skip
If a Composable's inputs did not change, Compose may skip re-running it entirely. Unchanged work is simply reused.
It Can Run Out of Order
Compose may recompose Composables in any order or even in parallel. Never assume one runs before another.
It Can Run Often
Recomposition can happen frequently, even every animation frame. Your Composable code should be fast and lightweight.
Keep Composables Pure
Treat Composables as side-effect free. Avoid writing files or starting work directly in the body, since it may re-run many times.
@Composable
fun Greeting(name: String) {
Text("Hi " + name)
}Watch a Counter Recompose
Each time count changes, the Text that reads it recomposes and shows the new number, while untouched siblings stay put.
var count by remember { mutableStateOf(0) }
Text("Value: " + count)Don't Do Heavy Work Inline
Running an expensive calculation in the body repeats it on every recomposition. Move it out or remember the result.
remember Caches Computations
Wrap a costly value in remember so Compose computes it once and reuses it across recompositions instead of redoing the work.
val sorted = remember(items) { items.sorted() }Mental Model
Think of the UI as a function of state. Change the state, Compose recomputes the affected parts, and the screen follows.
Quick Check
What actually triggers a recomposition?
Recap
You now know recomposition re-runs only the readers of changed state, can run often and out of order, so keep Composables fast and pure. 🎯
الأسئلة الشائعة
هل درس «إعادة التركيب: ما الذي يسبب إعادة الرسم» مجاني؟
نعم — نص درس «إعادة التركيب: ما الذي يسبب إعادة الرسم» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
ماذا ستتعلم في «إعادة التركيب: ما الذي يسبب إعادة الرسم»؟
افهم متى يعيد Compose تشغيل التعليمات البرمجية تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟
لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «إعادة التركيب: ما الذي يسبب إعادة الرسم»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟
نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- remember وmutableStateOf
- إعادة التركيب: ما الذي يسبب إعادة الرسم
- بناء عدّاد للنقرات
- rememberSaveable عبر التدوير