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've reached locked video content where the transcript will be shown as obfuscated text.


[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