In a row/column, is there any way to ensure that t...
# compose
s
In a row/column, is there any way to ensure that the first item does not take over the entire space over some second item when there is not enough space but without having to use
weight()
modifier on that first item? Currently, no matter what, in for example a row of 2 items, if those two items don't quite fit in the available space the first item always wins over and makes the other item disappear. Is there some way to have the second item be the one which always wins without adding a weight to the first one?
f
I wanted to say you could maybe have a custom arrangement, but that already works with `Placeable`s, so the measuring should already be done at that step. So I think you can't AFAIK, the Row/Column logic measures the children from first item to the last. The only exception is children with
weight
, which are measured last. So you'd have to create a custom layout for that if you have a use case for it and are not just asking out of curiosity.
You can check out the logic in
RowColumnMeasurementHelper::measureWithoutPlacing
thank you color 1
s
My use case is that i want to lay out a text field inside some sort of custom TextField in a way where if someone wants a suffix, the suffix is both never gobbled up by the text field taking all the width, while also not giving the text field a weight(1f) since then it stops trying to take up the minimum amount of width it takes by itself by measuring how much space it'd take to lay out "HHHHHHHHHH". Relevant question here https://kotlinlang.slack.com/archives/CJLTWPH7S/p1714995962002769 too. I think I am not leaning towards going with the weight, and then relying on callers to make sure to do a
fillMaxWidth
on the text field itself, otherwise it just takes up no width. That is if you are in a container which is horizontally scrollable already, so weight does not want to take up infinite width, and it takes nothing instead.
f
I think custom layout is your best bet for this. Especially when you have the behaviour contained in one component like this.
🌟 1
s
Yup, this one is getting quite complicated and I was trying to get away with having some parts be a custom layout, and some parts be a normal column/rows layout passed inside that custom layout as a big slot. I might have to split it up more than what I initially hoped I would 😅
🤞 1
z
Did you try passing the fill parameter to weight?
Not sure it would solve your problem
s
Yeah I did try that too, unfortunately it doesn't do it for me because this component may also be inside a horizontally scrollable container (so infinite width constraints), where a weight modifier makes the width actually just be 0.dp regardless of the fill parameter as far as I can tell.