From the course: Android Compose with Kotlin

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Understand composable functions

Understand composable functions - Kotlin Tutorial

From the course: Android Compose with Kotlin

Understand composable functions

- [Instructor] This is a composable function. It generates the following user interface through a three step process. The first is composition. This is when compose creates a representation of your UI hierarchy based on composable functions. Next is layout. The UI elements are measured and placed on a 2D plane. Finally, we have drawing, each of the UI elements is drawn on the device screen. Let's spend some time taking a closer look at what happens during composition. But first, what makes a function composable? Well, it has to adhere to a few rules. It must have the @composable annotation. This annotation informs the composed compiler that this function is intended to convert data into UI. How does it do that? When new or change data comes into a composable function, it uses that data to modify our UI hierarchy. Therefore, composable functions don't return anything. Instead, their execution is referred to as emitting UI. I'm going to put on my English professor hat to explain the…

Contents