How do I set height WRAP_CONTENT in compose?

Viewed 1854

So I know that when I don't use Modifier.height() is like "WRAP_CONTENT" is set, but what if I want to set the value in height as WRAP_CONTENT. Is there a way to do this?

Already tried InstrinsicSize.Min, InstrinsicSize.Max and 0.dp.

Looking for something like this: Modifier.height(WRAP_CONTENT)

This is just for specific knowledge as I can't find nothing in the documents.

1 Answers

You can use the wrapContentHeight modifier.

For example:

Box(
    Modifier.size(50.dp)
        .wrapContentHeight(Alignment.CenterVertically)
        .height(20.dp)
        .background(Color.Blue)
)

In this case the result will be a 50.dp x 20.dp blue box centered vertically in a 50.dp x 50.dp if wrapContentHeight did not exist, the blue rectangle would actually be 50.dp x 50.dp to satisfy the size set by the modifier.

Related