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

Kazemihabib1996

05/12/2020, 3:26 PM
In dev10 there is a problem with Box background color and
size
modifiers: backgroundColor not works in below code:
Copy code
Box(backgroundColor = Color.Blue, modifier = Modifier.width(200.dp).height(100.dp))
works in below one:
Copy code
Box(backgroundColor = Color.Blue, modifier = Modifier.size(200.dp))
m

Mihai Popa

05/12/2020, 3:41 PM
It is a known issue,
width
and
height
have been buggy in dev09 and dev10. Please use
preferredWidth
or
preferredHeight
instead, and switch back to them in dev11 where the bug should be fixed
k

Kazemihabib1996

05/12/2020, 3:47 PM
@Mihai Popa Thank you, can you please explain the difference of width and preferredWidth, the docs of them is not very clear to me.
m

Mihai Popa

05/12/2020, 3:55 PM
width
will be respected even when it does not respect the incoming constraints, while
preferredWidth
will be coerced inside the incoming constraints
👍 2
if
width
is not respecting the incoming constraints, the layout will be centered horizontally in the available space
👍 1
5 Views