Jetpack Compose: Getting Started

Aug 1 2023 · Kotlin 1.8.10, Android 13, Android Studio Flamingo

Part 3: Jetpack Controls

18. Understanding Recomposition

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 17. State Management in Jetpack Compose Next episode: Part 3 Quiz: Jetpack Controls

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.

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

With the Imperative UI model, in order to change a piece of the UI, you usually call a setter method on the UI element. For example, if you want to change the text of a TextView, you would call the setText() method on the TextView and pass in the new text that you want to display.

@Composable
fun Sample(){
    HomePage()
    NotificationsPage()
    ProfilePage()
}

Parallel Compositions

Do this:

@Composable
fun TestPage(){
    var clicks by remember { mutableStateOf(0) }
    Column(){
        Button(onClick = { clicks++ }) {
            Text(text = "Click Me")
        }
        Text(text = "Clicked $clicks times")
    }
}
@Composable
fun TestPage(){
    var clicks by remember { mutableStateOf(0) }
    Column(){
        Button(onClick = { }) {
            Text(text = "Click Me")
            clicks++
        }
        Text(text = "Clicked $clicks times")
    }
}

Recomposition Skips

Once a portion of your UI is declared invalid by a state change, Jetpack Compose will recompose that portion of the UI. However, Jetpack Compose will not always recompose the UI. Jetpack Compose will skip recomposition if the UI is already up to date.