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

About this episode

Leave a rating/review

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

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 18. Apply the CompositionLocal Pattern to 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’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Intro

[Slide 1 - LocalProviders]

Demo

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) {
  Scaffold(
    topBar = { ReadingListDetailsTopBar() },
    floatingActionButton = { AddBookToReadingList(bottomDrawerState) }
  ) {
    ReadingListDetailsModalDrawer(bottomDrawerState)
  }
}
fun ReadingListDetailsTopBar() {
  val readingList = LocalReadingList.current
}
    
fun ReadingListDetailsModalDrawer(drawerState: BottomDrawerState) {
  val readingList = LocalReadingList.current
}