```interface LayoutModifier : Modifier.Element { ...
# compose
k
Copy code
interface LayoutModifier : Modifier.Element {
    fun MeasureScope.measure(
        measurable: Measurable,
        constraints: Constraints,
        layoutDirection: LayoutDirection
    ): MeasureScope.MeasureResult
How exactly LayoutModifier works? instead of list of measurables for each child, there is only one measurable. and I've playing with it, when I tried
placeable.place(50.ipx, 50.ipx)
it applied for all children. I think there is some thing I misunderstood about it.
a
There is only one child of a modifier: the element it is applied to
k
Thanks @Adam Powell but sorry I can't understand your explanation Let me explain what I'm struggling with:
Copy code
@Composable
fun SimpleBox(modifier: Modifier = Modifier, children: @Composable() () -> Unit) {
    Layout(children = children, modifier = modifier) { measurables, constraints, layoutDirection ->

        val placeable = measurables[0].measure(constraints)
        val placeable2 = measurables[1].measure(constraints)
        layout(placeable.width, placeable.height) {
            placeable.place(0.ipx, 0.ipx)
            placeable2.place(0.ipx, 100.ipx)
        }
    }
}

private class SimpleLayoutModifier(): LayoutModifier {
    override fun MeasureScope.measure(
        measurable: Measurable,
        constraints: Constraints,
        layoutDirection: LayoutDirection
    ): MeasureScope.MeasureResult {
        val placeable = measurable.measure(constraints)

        return layout(placeable.width, placeable.height) {
            placeable.place(50.ipx, 50.ipx)
        }
    }
}
Copy code
with(DensityAmbient.current) {
SimpleBox(modifier =   Modifier.drawBackground(Color.Blue).size(400.ipx.toDp()) ) {
                    Text("First one")
                    Text("Second one")
                }
            }
If I add the SimpleLayoutModifier both
Text()
widgets will be effected.
Copy code
with(DensityAmbient.current) {
    SimpleBox(modifier = Modifier.drawBackground(Color.Blue).size(400.ipx.toDp()) + SimpleLayoutModifier()) {
        Text("First one")
        Text("Second one")
    }
}
a
Only the SimpleBox is affected by it. The modifier acts on the SimpleBox's layout node and is not aware of what the SimpleBox contains
👍 1
k
AH, that was my first guess but when I saw the blue color not moves and it just stays there, I thought it's wrong. Why the blue Box not moves?
Hmm, If I add the drawBackground after SimpleLayoutModifier The blue background also moves 🤔
SimpleLayoutModifier().drawBackground(Color.Blue)
a
Yes, each modifier is applied in order. A modifier applies to everything that comes after it in sequence
🙏 1