Tom De Decker
07/13/2023, 2:11 PMwidthIn(max = ...)
should have been able to solve this issue but it does not seem to behave as I expected. Does anyone have any experience using this modifier? More information in the 🧵Tom De Decker
07/13/2023, 2:12 PM@Preview(name = "Phone", device = Devices.PHONE)
@Preview(name = "Tablet", device = Devices.TABLET)
@Composable
private fun WidthInTestPreview() {
MaterialTheme {
Surface(
color = Color.Black,
modifier = Modifier.fillMaxSize()
) {
Box(
modifier = Modifier
.widthIn(max = 100.dp)
.height(100.dp)
.background(Color.DarkGray)
)
}
}
}
This produces the following:Tom De Decker
07/13/2023, 2:14 PMStylianos Gakis
07/13/2023, 2:15 PMSurface
inside itself uses a Box
which has propagateMinConstraints
to true.
What this basically means, is that the child of Surface
will always override the constraints that it has to match the current size of the Surface itself.Stylianos Gakis
07/13/2023, 2:16 PMprivate fun WidthInTestPreview() {
MaterialTheme {
Surface(
color = Color.Black,
modifier = Modifier.fillMaxSize()
) {
Box {
Box(
modifier = Modifier
.widthIn(max = 100.dp)
.height(100.dp)
.background(Color.DarkGray)
)
}
}
}
}
Then it’d work actually. Since the outer box would be the one with the max size, and then the rest of the children can have a lower minimum size if they wantTom De Decker
07/13/2023, 2:17 PMStylianos Gakis
07/13/2023, 2:19 PMpropagateMinConstraints
. Go in the box implementation and read the docs about it. After you know about it all these odd behaviors explain themselves if you see this is set to true