Recomposition

Compared to your work in the framework UI toolkit to keep your app state and UI state in sync, Compose’s automatic UI updates could seem a bit magical. Allow us to dispel some of the magic.

To see how Compose updates your UI firsthand, add a log statement to your ToppingCell composable to print a message each time the function is invoked.

Listing 27.7  Pulling back the curtain (ToppingCell.kt)

...
@Composable
fun ToppingCell(
    topping: Topping,
    placement: ToppingPlacement?,
    onClickTopping: () -> Unit,
    modifier: Modifier = Modifier
) {
    Log.d("ToppingCell", "Called ToppingCell for $topping")
    Row(
        ...
    ) {
        ...
    }
}

Run Coda Pizza and open Logcat. Right after Coda Pizza starts, you will see that your new log message ...

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.