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

Roberto Leinardi

05/13/2022, 1:49 PM
Is it possible to change the modifier of a composable as parameter (
Content: @Composable () -> Unit
)? Right now I'm wrapping it in a
Box
to be able to set my modifier but I was wondering if there is a better way:
Copy code
Box(modifier = modifier) {
      content()
}
s

ste

05/13/2022, 2:25 PM
You could pass a
Modifier
as the only parameter of
content
, but then the user would have to "remember" to use it
z

Zach Klippenstein (he/him) [MOD]

05/13/2022, 4:45 PM
This is probably mostly an API concern - forcing your callers to apply a modifier you give them is very error-prone (see how often people report
Scaffold
bugs). Wrapping in a box is cheap, Box is inline and designed for this sort of thing. One important note however is that you'll want to pass
propagateMinConstraints=true
when doing so, otherwise you'll eg break if someone passes you a
fillMaxSize
👍 2
2 Views