Looking closer at composable functions
The UI of a Compose app is built by writing and calling composable functions. We have already done both in the previous chapters, but my explanations regarding the structure of a composable, as well as its internals, have been quite basic—it’s time to fix that.
Building blocks of composable functions
A composable function is a Kotlin function that has been annotated with @Composable
. All composables must be marked this way because the annotation informs the Compose compiler that the function converts data into UI elements.
The signature of a Kotlin function consists of the following parts or building blocks:
- An optional visibility modifier (
private
,protected
,internal
, orpublic
) - The
fun
keyword - A name
- A list of parameters (can be empty) or, optionally, a default value
- An optional return type
- A block of code
Let’s explore these parts in greater detail.
The default visibility...