Vsevolod Ganin

    Vsevolod Ganin

    1 year ago
    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
    Timo Drick

    Timo Drick

    1 year ago
    Maybe you want to use the fillMaxSize()/fillMaxHeight/Width() modifier?
    Vsevolod Ganin

    Vsevolod Ganin

    1 year ago
    Unfortunately it’s not the same. Here is an example
    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
    Timo Drick

    Timo Drick

    1 year ago
    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

    romainguy

    1 year ago
    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
    Adam Powell

    Adam Powell

    1 year ago
    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
    Timo Drick

    Timo Drick

    1 year ago
    Thanks @Adam Powell Works:
    Column(Modifier.preferredWidth(IntrinsicSize.Min)) {
            Text(text = "4")
            Divider(modifier = Modifier.fillMaxWidth().preferredHeight(1.dp),color = Color.Black)
            Text(text = "2")
        }