Skip to main content

Jetpack Compose

Examples

To add a Composable, use the compose method.

compose("Text") {
Text(text = "Hello, World")
}

You can use state in the compose.

compose("MyComponent") {
var boolean by remember {
mutableStateOf(true)
}
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = if (boolean) "Hello" else "World"
)
Button(
onClick = { boolean = !boolean }
) {
Text(text = "Toggle")
}
}
}

Parameters

namedescription
nameThe UI Component name.
definitionComposable function.