Is there a guarantee that when working with `Layou...
# compose
e
Is there a guarantee that when working with
Layout
the order of
Measurables
in the
MeasurePolicy
will be in the same order that the content composables are emitted?
👌 2
s
However, it might be easier on your eyes and your brain to do what TextField for example does by tagging each item with a layoutId and reference that later to measure it and whatnot. See here in line 530 and then in line 650 for example. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]Main/kotlin/androidx/compose/material3/TextField.kt;l=530-650
e
Good to know, thanks (I was using parent data for that in some cases). I'm asking for a case where there will be a dynamic amount of children of the same type
e
you do have to be somewhat careful because
Copy code
@Composable fun Foo() {
    Bar()
    Baz()
}

Layout(
    content = {
        Foo()
    },
    measurePolicy = { measurables, constraints ->
can result in your measurePolicy receiving
measurables.size != 1
the <https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/package-summary#Layout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MeasurePolicy)%7C@Composable fun Layout(contents: List<@Composable () -> Unit>, modifier: Modifier = Modifier, measurePolicy: MultiContentMeasurePolicy ): Unit> overload doesn't have that issue because each item of the list is put into its own group so there's a 1:1 correspondance