This episode builds the conceptual foundation of Compose: composable functions as UI, the recomposition mechanism, the composition tree and the slot API, the rendering pipeline, and integration with existing Android views.

Episode 1 explained why Compose was born. Now you need to understand how it works: what a composable function is, how recomposition runs, how the composition tree is structured, and how the final pixels appear on screen.
The concepts in this episode are the shared language used throughout the entire series. If this episode feels heavy, that's normal — but hang in there, because the coming material will keep referring to terms like composition, state, and slots.
Episode 2 lays the foundation: composable functions, recomposition, the composition tree and slots, the rendering pipeline, and Compose's position within the Android framework.
The foundation of Compose is the composable function — a Kotlin function annotated with @Composable. This function produces UI based on its parameters and can only be called within a composition context. Compose assembles these functions into a UI tree that describes the screen.
@Composable
fun KartuPengguna(nama: String, aktif: Boolean) {
Card {
Row {
Text(nama)
if (aktif) {
Text("online")
}
}
}
}if (aktif) inside a composable is valid control flow — Compose processes the branch only when needed. Because the UI is simply a function of its inputs, the result is always predictable. To make sure your project compiles correctly after writing a composable, run ./gradlew :app:compileDebugKotlin in the terminal.
Compose remembers the result of each composable based on its parameters and its position in the tree. This mechanism is called positional memoization: as long as the inputs don't change, Compose skips that function during recomposition. This is why the call order of composables must not change between invocations.
Compose works on a state-driven model. When state changes, Compose re-runs the composables that read that state. This process is called recomposition, and Compose uses smart skipping — only the functions that actually read the changed state are recomputed.
@Composable
fun Penghitung() {
var jumlah by remember { mutableStateOf(0) }
Button(onClick = { jumlah++ }) {
Text("Ditekan $jumlah kali")
}
}remember { mutableStateOf(0) } stores a value that survives across recompositions. onClick = { jumlah++ } changes the state, and Compose automatically updates the text. The details of the state mechanism are dissected thoroughly in episode 5.
Every composable call produces an entry in the composition tree. This structure is what Compose uses to compare old and new UI during recomposition. As long as the order and types of composables are the same, unnecessary work is skipped.
The slots concept allows a composable to accept a region of UI as a parameter, not just data. This is the pattern Material Components use to inject free-form content:
@Composable
fun HalamanDasar(content: @Composable () -> Unit) {
Scaffold(topBar = { TopAppBar(title = { Text("Beranda") }) }) {
content()
}
}content: @Composable () -> Unit is a slot: the caller is free to fill in the page content. This slot pattern is what keeps components like Scaffold, ModalBottomSheet, and SnackbarHost flexible.
After composition, Compose runs three sequential phases:
Modifiers that affect position work in the layout phase, while effects like background and shadow work in the drawing phase. These phases become relevant again when we discuss custom layouts in episode 18.
Compose doesn't replace Android; it runs on the same framework. Integration with legacy views is therefore always possible: AndroidView embeds a traditional view into a composable, and ComposeView embeds Compose into an XML layout. These interop mechanisms are covered in episode 16.
Episode 2 built the conceptual foundation of Compose: composable functions as the representation of UI, state-driven recomposition, the composition tree with positional memoization, the slot API for flexible composition, the three-phase pipeline, and Compose's position of sitting on top of the Android framework.
Key takeaways:
@Composable.In episode 3 we will discuss project setup and your first composable — creating a new Compose project in Android Studio, understanding the structure of build.gradle.kts, writing your first composable complete with a preview, and running it on the emulator. You'll put the episode 2 concepts into practice right here.