A practical walkthrough of using Kotlin coroutines to solve a complex Android UI sequencing problem in the Tivi app. The post demonstrates how wrapping callback-based APIs (RecyclerView scroll listeners, AdapterDataObserver, MotionLayout transitions) into suspending extension functions eliminates nested callback chains. Key functions covered include `awaitItemIdExists()`, `awaitScrollEnd()`, `awaitTransitionComplete()`, and `awaitAnimationFrame()`, showing how sequential coroutine code replaces tightly coupled, hard-to-maintain callback logic for coordinating data loading, scrolling, and animations.

10m read timeFrom chrisbanes.me
Post cover image
Table of contents
The problem #Ideal solution #Coroutines to the rescue 🦸 #MotionLayout.awaitTransitionComplete() #Adapter.awaitItemIdExists() #RecyclerView.awaitScrollEnd() #Final result #Break the callback-chains ⛓️ #