I wonder why the `matchParentSize` modifier is ava...
# compose
v
I wonder why the
matchParentSize
modifier is available only in
BoxScope
? It could be useful in any layout scope I think, as well as
matchParentWidth
and
matchParentHeight
2
t
Maybe you want to use the fillMaxSize()/fillMaxHeight/Width() modifier?
v
Unfortunately it’s not the same. Here is an example
Copy code
Column {
    Text(...)
    Canvas(modifier = Modifier.fillMaxWidth().height(1.dp)) {
        drawLine(color, Offset(0f, 0f), Offset(size.width, 0f))
    }
    Text(...)
}
And I get
While I really don’t want to take
Canvas
into account while measuring, I just want to set it to be in size as the rest of the content dictates
t
And when you wrap the Canvas into a Box that have .matchParentSize modifier it works?
Oh sorry. No that will not work
Yea i think you are right. It would be nice to have this modifier in every layout.
r
Constraints like match parent available in all layouts unfortunately sometimes leads to ambiguous setups
An obvious example with the View system is a linear layout set to wrap content and all its children set to match parent
a
it's not available in every layout because it requires some special handling by the parent, and we don't require that every custom layout perform that special handling.
matchParentSize
in Box is an instruction to measure that element last, with whatever specific size the Box has already determined for itself, potentially from measuring its other child elements first.
you can get a similar effect along a single dimension by sizing the container using intrinsic measurements; see this example: https://developer.android.com/codelabs/jetpack-compose-layouts#9
👍 5
t
Thanks @Adam Powell Works:
Copy code
Column(Modifier.preferredWidth(IntrinsicSize.Min)) {
        Text(text = "4")
        Divider(modifier = Modifier.fillMaxWidth().preferredHeight(1.dp),color = Color.Black)
        Text(text = "2")
    }
👍 4
👍🏼 1