What are composables - devrath/ComposeAlchemy GitHub Wiki
About composables
Composable
is the fundamental building block for building any type of composable function.
- In the Flutter, we refer to any UI component as a
widget
, and here in jetpack compose
we refer as compose
- The UI is built with the composable and they have the annotation
@compose
- The annotation
@compose
will tell the compiler that the contents of the function are a piece of UI that needs to be displayed.
Naming conventions
@Composable
private fun HelloScreen(displayText: String) {
Text(text = displayText)
}
- The naming of composable stats with a capital letter, unlike the regular functions.
- Reason for this is because the composable are like widgets or components, Thus we give the Capital name.
Places to add the composables
- We can add the composable functions inside the class.
- We can add it outside the class and within the file.
- They are so much decoupled that, all the widgets in jetpack compose are functions.
- We can even define them in a separate class and use them in the current class.
- Due to this modularity the composable can be made to run on a desktop application as well that just has kotlin framework.