Nino
02/28/2025, 12:14 PMColumn
with height of at most 16.dp, but should the incoming size constraint give less space, this element should shrink. How to do it without relying to a custom Layout
? Even after 5 years of Compose, I still feel retarded using this framework. 😞
Code :
Column {
Card(modifier = Modifier.size(100.dp))
Spacer(modifier = Modifier.background(Color.Gray).size(16.dp))
Card(modifier = Modifier.size(50.dp))
}
@Composable
private fun Card(modifier: Modifier = Modifier) {
Column(modifier = modifier.background(Color.Yellow)) {
Text("Foo")
Box(
modifier = Modifier
.background(Color.Red)
.fillMaxWidth()
.weight(1F)
.heightIn(0.dp, 16.dp)
)
Text("Bar")
}
}
[1] is the actual result, [2] is the expected resultTgo1014
02/28/2025, 1:15 PMBox(
modifier = Modifier
.background(Color.Red)
.heightIn(max = 16.dp)
.fillMaxSize()
)
Tgo1014
02/28/2025, 1:16 PMNino
02/28/2025, 1:17 PMNino
02/28/2025, 1:18 PMTgo1014
02/28/2025, 1:21 PMBox(
modifier = Modifier
.background(Color.Red)
.heightIn(max = 16.dp)
.weight(1f, fill = false)
.fillMaxSize()
)
Nino
02/28/2025, 1:23 PMfill
param out of nowhere lol, thank youNino
02/28/2025, 1:24 PMSpacer(
modifier = Modifier
.height(16.dp)
.weight(1f, fill = false)
)
Tgo1014
02/28/2025, 1:25 PMNino
02/28/2025, 1:27 PMlayout_weight=1
& maxHeight=16dp
🤔Tgo1014
02/28/2025, 1:40 PMheightIn
has no effect over the weight
Zach Klippenstein (he/him) [MOD]
02/28/2025, 6:25 PM.weight(…).height(…)
, since weight
is effectively always at the top of the modifier chain anyway since it directly communicates to the parent layout. It doesn't change the behavior, but it makes the modifiers read more like how they actually work.Zach Klippenstein (he/him) [MOD]
02/28/2025, 6:26 PMweight
modifier is doing in this case is changing the measure "priority" of the modified node. From the perspective of "weight", that's kind of a side effect, so i do kind of wish there was a more explicit way to say "all i care about is measure priority, i don't actually care about weighting". But it's the best we've got right now ¯\_(ツ)_/¯