اتصالات التمرير المتداخل
نسّق التمرير بين الحاويات
اتصالات التمرير المتداخل درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Scrolls Inside Scrolls
Sometimes a scrollable sits inside another scrollable, like a list under a collapsing header. Nested scroll lets them cooperate instead of fighting. 📜
The Coordination Problem
Without help, the inner list eats every swipe and the outer container never moves. NestedScrollConnection shares the scroll between them.
Meet nestedScroll
Attach the nestedScroll modifier and pass a connection. That connection intercepts scroll deltas as they travel up the tree.
Modifier.nestedScroll(connection)Pre-Scroll: First Dibs
The parent gets a chance before the child via onPreScroll. Return how much of the delta you consumed; the rest flows to the child.
override fun onPreScroll(available: Offset, source): OffsetPost-Scroll: Leftovers
After the child scrolls, onPostScroll offers any unused delta back to the parent. Use it to move a header once the list hits its edge.
override fun onPostScroll(consumed, available, source): OffsetConsume What You Need
In each callback you return an Offset of how much you used. Return Offset.Zero to pass everything through to the next participant.
return Offset(0f, consumedY)Fling Phases Too
There are matching onPreFling and onPostFling callbacks for momentum. They are suspend functions so you can animate as the fling resolves.
override suspend fun onPreFling(available: Velocity): VelocityRemember the Connection
Wrap your connection in remember so it survives recomposition. Capture any state it reads, like a header offset, inside it.
val connection = remember { object : NestedScrollConnection {...} }Collapsing Toolbar Classic
The flagship use is a collapsing toolbar: shrink the top bar with pre-scroll while the list scrolls, then expand it on the way back.
It Just Works Often
Many built-ins like Scaffold with scroll behaviors already wire nested scroll for you. Reach for a custom connection only when you need fine control.
Mind the Source
Each callback gets a source telling you if the scroll came from a drag or a fling. Use it to react differently to touch versus momentum.
if (source == NestedScrollSource.Drag) { /* ... */ }Quick Check
Which callback lets a parent consume scroll before its child does?
Recap: Scrolls in Harmony
You learned NestedScrollConnection with pre and post scroll and fling, the key to collapsing toolbars and cooperating lists. 🎉
تعلم Kotlin مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 30
- الدروس
- 120
الأسئلة الشائعة
هل درس «اتصالات التمرير المتداخل» مجاني؟
نعم — نص درس «اتصالات التمرير المتداخل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- pointerInput وdetectTapGestures
- السحب والتمرير والدفع
- Transform: التحريك والتكبير والتدوير
- اتصالات التمرير المتداخل