Marc-Antoine Sauvé
10/18/2023, 6:53 PMMarc-Antoine Sauvé
10/18/2023, 6:54 PMIntrinsicSize.Min for that with propagateMinConstraints = true which does the trick.
We have an Image inside that have an aspectRatio. For some reason, the aspect ratio is also applied to the outer Box and we do not know why.
We expect the Box to be the same height as the Image .
@Preview(showBackground = true, widthDp = 300)
@Composable
fun TestZStackCompose() {
// ZStack
Box(
modifier = Modifier
.width(intrinsicSize = IntrinsicSize.Min)
.height(intrinsicSize = IntrinsicSize.Min)
,
propagateMinConstraints = true,
) {
// Aligned layer
Box(contentAlignment = Alignment.Center, modifier = Modifier.background(Color.Red)) {
// Image content
Image(
painter = rememberVectorPainter(image = Icons.Filled.Close),
contentDescription = null,
modifier = Modifier
.background(Color.Blue)
.width(40.dp)
.aspectRatio(ratio = 1f)
)
}
}
}