Nested Scroll Connections
Coordinate scrolling between containers.
Nested Scroll Connections is a free Jetpack Compose Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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. 🎉
Frequently asked questions
Is the “Nested Scroll Connections” lesson free?
Yes — the full text of “Nested Scroll Connections” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.
What will I learn in “Nested Scroll Connections”?
Coordinate scrolling between containers. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Jetpack Compose Academy?
No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Nested Scroll Connections” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Jetpack Compose Academy lesson?
Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- pointerInput & detectTapGestures
- Drag, Swipe & Fling
- Transform: Pan, Zoom & Rotate
- Nested Scroll Connections