Composing `Wrap` and `Container` result in a 0 siz...
# compose
k
Composing
Wrap
and
Container
result in a 0 sized child. is this the expected behavior?
both of the following code paints the entire wide area with Cyan
Copy code
Container {
    Draw { canvas: Canvas, parentSize: PxSize ->
        canvas.drawRect(parentSize.toRect(), Paint().apply { color = Color.Cyan })
}}
Copy code
Wrap {
    Draw { canvas: Canvas, parentSize: PxSize ->
        canvas.drawRect(parentSize.toRect(), Paint().apply { color = Color.Cyan })
}}
but here the
parentSize
is (0, 0, 0, 0):
Copy code
Wrap {
    Container {
        Draw { canvas: Canvas, parentSize: PxSize ->
            canvas.drawRect(parentSize.toRect(), Paint().apply { color = Color.Cyan })
}}}
expanded argument sets the layout back to normal 🤔
Copy code
Wrap {
    Container(expanded = true) {
    // …
    }
}
couldn’t figure out yet the wrap behavior
f
wrap means that the child will take the minimum amount of space possible. Container matches the minimum size of its child, and since it has none, that size is 0. Therefore, you will get a 0 sized child.
👍 1
k
What you say makes sense, they take the minimum amount of size. Actually that is what expected. But the Comtainer has the draw child which takes the size of the parent thats why the drawing not visible. But using them separately both of them expand, composed they take minimum? That feels inconsistent behaviour for me
this is how I can formulate it:
Copy code
wrap + draw = expanded // shouldn't be compressed?
container + draw = expanded
wrap + container + draw = compressed
👍🏼 1
f
Draw
is not a child in the composition phase. It's merely a callback for when the drawing happens, which is after the composition phase.
In other words,
Draw
is "nothing"
If you want to draw something, you need to order space for it in the composition phase, by using something like
Card
k
yeah, I feel we are misunderstanding each other. I see how Draw is “nothing” the problem I have is the two component behavior. wrap + nothing should be collapsed to minimum (0 sized), basically nothing because of the minimum size of nothing is well nothing. but instead of collapsing the space wrap actually expands it.
Container(expanded = false) + Nothing
also expands the entire free space which also questionable
f
How do you know it expands the entire free space?
I think I see what you mean
Copy code
Wrap {
    Draw { canvas: Canvas, parentSize: PxSize ->
        canvas.drawRect(parentSize.toRect(), Paint().apply { color = Color.Cyan })
}}
Here
Draw
should not be expanded, unless I'm missing something
👍 1
Someone from google can comment
m
In general, both Wrap and Container(expanded = false) will match the size of their layout child
If they have no child, they will be (0, 0) or actually the minimum size the constraints received from their parent allow
However, the root of the layout hierarchy will always need to fill the screen, due to the constraints it is measured with. So if Wrap or Container are the root of the hierarchy, they will have to fill the screen
👍 1
Hence their Draw children can draw in the whole screen space
Indeed only Layout elements can occupy layout space - this space can be then be used for Drawing. But layouts do not care about draws