Vaibhav Jaiswal
05/16/2024, 11:58 AMRow
with 2 columns in it, and I want the smaller height column to match the height of the other column
I achieved it by applying height(IntrinsizSize.Min)
to Row and fillMaxHeight()
to the smaller column
This works fine, but it breaks when I have a composable which uses heightIn(max = ...)
It works fine when i use a fixed height height(...)
but breaks if I use maxHeight instead
More in thread 🧵Vaibhav Jaiswal
05/16/2024, 11:58 AMVaibhav Jaiswal
05/16/2024, 11:59 AMVaibhav Jaiswal
05/16/2024, 12:00 PMSurface(modifier = Modifier.fillMaxWidth(), border = BorderStroke(1.dp, Color.Black)) {
Row(
modifier = Modifier.fillMaxWidth()
.padding(16.dp)
.height(IntrinsicSize.Min)
) {
Column(modifier = Modifier.fillMaxHeight()){
Box(modifier = Modifier.size(40.dp).background(Color.Red))
Box(modifier = Modifier.width(40.dp).weight(1f).background(Color.Green))
Box(modifier = Modifier.size(40.dp).background(Color.Red))
}
Column(modifier = Modifier.weight(1f)){
Box(modifier = Modifier.fillMaxWidth().height(32.dp).background(Color.Blue))
Box(modifier = Modifier.fillMaxWidth().height(64.dp).background(Color.Yellow))
Box(modifier = Modifier.fillMaxWidth().heightIn(max = 240.dp).background(Color.DarkGray))
Box(modifier = Modifier.fillMaxWidth().height(44.dp).background(Color.Blue))
}
}
}
Vaibhav Jaiswal
05/16/2024, 1:03 PMAsync Image
Vaibhav Jaiswal
05/16/2024, 1:03 PMSean Proctor
05/16/2024, 9:08 PMAsyncImage
in a Box
with a constrained height, does it do something similar to what you want?Vaibhav Jaiswal
05/17/2024, 6:02 AM@Composable
private fun PostImage(
url: String,
modifier: Modifier = Modifier,
onImageClick: () -> Unit
) {
Surface(
onClick = onImageClick,
modifier = modifier,
) {
MedialImage(
url = url,
modifier = Modifier.fillMaxWidth(),
contentScale = ContentScale.Crop,
contentDescription = "Post Image",
)
}
}
And i call it like this inside the Column
PostImageItem(
image = media.data,
modifier = modifier.height(240.dp).clip(RoundedCornerShape(4.dp)),
onImageClick = { onAction(PostAction.ImageClick(post, it)) }
)
As soon as i change the height()
to heightIn(max = ...)
the ui becomes like the screenshot i shared above
With fixed height the image height is correct and the composable below it is also displayedSean Proctor
05/17/2024, 12:45 PMVaibhav Jaiswal
05/17/2024, 2:02 PM