Jetpack Compose

Oct 11 2022 Kotlin 1.7.10, Android 13, Android Studio Chipmunk

Part 3: Manage State with Compose

18. Apply the CompositionLocal Pattern to UI

Episode complete

Save for later
About this episode
See versions

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 17. Connect LiveData to Compose UI

The student materials have been reviewed and are updated as of September 2022.

Explore more Compose resources on our website, such as our Jetpack Compose by Tutorials book, the Jetpack Compose Tutorial For Android: Getting Started, Jetpack Compose Animations Tutorial: Getting Started, or our two live talks and podcast episodes - Building UIs In Android Using Jetpack Compose and Jetpack Compose With Denis Buketa.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a Professional subscription.


[Slide 1 - LocalProviders]


Open the ReadingListDetailsActivity. Add the following composition local to the top of the class:

private val LocalReadingList = compositionLocalOf<ReadingListsWithBooks?> { error("No reading lists!") }
CompositionLocalProvider(LocalReadingList provides readingListState) {
    topBar = { ReadingListDetailsTopBar() },
    floatingActionButton = { AddBookToReadingList(bottomDrawerState) }
  ) {
fun ReadingListDetailsTopBar() {
  val readingList = LocalReadingList.current
fun ReadingListDetailsModalDrawer(drawerState: BottomDrawerState) {
  val readingList = LocalReadingList.current