CompositionLocal

In this chapter, you have seen a few examples where nesting one composable inside another causes the inner composable’s appearance to change. Using the MaterialTheme composable, for example, causes all components nested within it to be aware of your theme and use its colors.

When you added the Text to your TopAppBar, you might have noticed something interesting. Despite the fact that you did not specify any parameters besides the text itself, the Text was appropriately styled with the correct font size and color to appear in your app bar. How did this happen?

When you build a UI using Jetpack Compose, a composition hierarchy is created at runtime for all your composables – much like the view hierarchy for framework ...

Get Android Programming: The Big Nerd Ranch Guide, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.