https://kotlinlang.org logo
#compose
Title
# compose
m

Mehdi Haghgoo

08/06/2020, 5:05 AM
I have noticed some composables have a content field, and they also have a body for content. Should the children composables go in their content field or written in their body? For example surface:
Copy code
@Composable
fun Surface(
    modifier: Modifier = Modifier,
    shape: Shape = RectangleShape,
    color: Color = MaterialTheme.colors.surface,
    contentColor: Color = contentColorFor(color),
    border: Border? = null,
    elevation: Dp = 0.dp,
    content: @Composable () -> Unit
)
a

allan.conda

08/06/2020, 5:24 AM
and they also have a body for content
What do you mean?
r

romainguy

08/06/2020, 6:03 AM
When a lambda (content here) is the last parameter you can use a special Kotlin syntax so you can write
Surface { content() }
instead
❤️ 1
K 2
(trailing lambda)
a

allan.conda

08/06/2020, 6:10 AM
ah so that’s what he meant, 😄
😄 2
m

Mehdi Haghgoo

08/06/2020, 8:20 AM
@romainguy so all composables we write inside the body of other composables are made possible thanks to trailing lambdas?
m

matvei

08/06/2020, 9:13 AM
Yes, the "body" of the composable is possible and equal to the last parameter of this composable is a lambda https://kotlinlang.org/docs/reference/lambdas.html#passing-a-lambda-to-the-last-parameter
❤️ 1
c

caelum19

08/08/2020, 2:31 PM
2 Views