https://kotlinlang.org logo
m

Mikael Alfredsson

06/09/2020, 2:52 PM
Is it possible to add a modifier or wrap all child composeables in for example a Column. What I want to achieve right now is to be able to add padding around each component but the question is a bit broader.
z

Zach Klippenstein (he/him) [MOD]

06/09/2020, 3:30 PM
You can pass a custom Arrangement to Column to implement padding between its children.
💡 2
m

Mikael Alfredsson

06/10/2020, 8:18 AM
but wrapping, as like decorating them is not possible? this does not seems to work;
Copy code
Column {
    listOf(
            Text("Line1"),
            Text("Line2")
    ).map { Box(modifier = Modifier.padding(12.dp)) { it } }
}
z

Zach Klippenstein (he/him) [MOD]

06/10/2020, 2:46 PM
That exact example does not work, because most UI widget composables, like
Text
, do not return anything. However, some other options are: - You could make your list contain composable functions (eg
{ Text() }
, and then call those functions from your wrapper. - You can write a custom
Layout
that modifies the measurement/placement of all its children. This is a more general version of the
Column
-specific arrangement one.
m

Mikael Alfredsson

06/10/2020, 2:48 PM
I need to get my head around exactly how it composes things 🙂 Thanks for the hints
z

Zach Klippenstein (he/him) [MOD]

06/10/2020, 2:49 PM
Leland has given a few talks and written a few articles on this that are really helpful.
m

Mikael Alfredsson

06/10/2020, 2:49 PM
youtube / medium or other places?
z

Zach Klippenstein (he/him) [MOD]

06/10/2020, 3:24 PM
Google "leland richardson compose", there's a bunch
3 Views