sindrenm
02/09/2023, 11:23 AMBox(propagateMinConstraints = true)
. I would expect the following to show a Surface
with no color at all, because I haven't set any size for the Spacer
inside it, but instead, the Spacer
fills the entire Surface
with its green color, as per the picture.
@Preview
@Composable
fun SurfaceBehaviour() {
Surface(Modifier.padding(16.dp).fillMaxWidth().aspectRatio(16f / 9f)) {
Spacer(Modifier.background(Color.Green))
}
}
This doesn't really seem documented, either, so I'm curious as to why Surface
would behave like this.@Preview(widthDp = 50)
also propagates that width to the root child, which is also something I wouldn't expect.
@Preview("500 dp width", widthDp = 500)
@Preview("400 dp width", widthDp = 400)
@Preview("350 dp width", widthDp = 350)
@Composable
private fun Preview2() {
Spacer(Modifier.height(50.dp).background(Color.Magenta))
}
Louis Pullen-Freilich [G]
02/09/2023, 2:27 PMsindrenm
02/09/2023, 2:31 PMLouis Pullen-Freilich [G]
02/09/2023, 2:33 PMsindrenm
02/09/2023, 2:36 PMModifier.surface
, for consistency? I'm mostly just asking because it made my own custom layout behave differently when it was wrapped in a Box vs. a Surface, which is something I wouldn't expect initially.Layout
in a Box
, but it felt a little weird.Louis Pullen-Freilich [G]
02/09/2023, 2:38 PMsindrenm
02/09/2023, 2:40 PM