0Pricing
Jetpack Compose Academy · Pelajaran

Koneksi Gulir Bersarang

Koordinasikan pengguliran antarkontainer.

Koneksi Gulir Bersarang adalah pelajaran Jetpack Compose Academy gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Jetpack Compose Academy, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Jetpack Compose Academy mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

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): Offset

Post-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): Offset

Consume 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): Velocity

Remember 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. 🎉

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Koneksi Gulir Bersarang” gratis?

Ya — teks lengkap “Koneksi Gulir Bersarang” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Jetpack Compose Academy, upgrade ke CoddyKit PRO. Kursus Jetpack Compose Academy mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Koneksi Gulir Bersarang”?

Koordinasikan pengguliran antarkontainer. Kamu berlatih Jetpack Compose Academy dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Jetpack Compose Academy?

Tidak diperlukan pengalaman sebelumnya. Jetpack Compose Academy di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.

Berapa lama pelajaran “Koneksi Gulir Bersarang” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Jetpack Compose Academy ini?

Ya. Setiap pelajaran Jetpack Compose Academy menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. pointerInput & detectTapGestures
  2. Seret, Usap & Lontar
  3. Transformasi: Geser, Perbesar & Putar
  4. Koneksi Gulir Bersarang
← Kembali ke Jetpack Compose Academy