Edit
To be clear, what I want is the following algorithm:
height = if (contentHeight > minHeight) {
contentHeight } else {
minHeight }
Modifier.height(contentHeight.coerceAtLeast(minHeight))
is the shortened algorithm.
When a Layout measures and places children it checks constraints. You can find detail answered here about how it works.
For instance column has minHegith = 100.dp, while maxHeight is your composable height in dp. If it's root it's height of screen in dp
Column(modifier=Modifier.heightIn(min=100.dp)) {
Box(modifier=Modifier.fillMaxSize().background(Color.Yellow))
}
For instance this Box covers whole space because it's min and max constraint is Column's maxHeight
. In this case using Modifier.heightIn()
won't limit, so you need Modifier.height()
such as in my original answer with a fixed value or use custom layout to check and assign .
layout(width, height){}
inside Layout
.
But there is something to note with Surface that it forces minimum constraints to direct descendant, you can check my answer about Surface here.
Surface(modifier = Modifier.heightIn(min = 100.dp)) {
Box(
modifier = Modifier
.size(300.dp)
.background(Color.Yellow)
)
}
This Box in example will cover all of the height because of being Surface's direct descendant.
Surface(modifier = Modifier.heightIn(min = 100.dp)) {
Column() {
Box(
modifier = Modifier
.size(300.dp)
.background(Color.Yellow)
)
}
}
This one will have 300.dp size while Column
covers all available space of Surface