https://kotlinlang.org logo
o

orangy

01/08/2021, 6:20 PM
Is there a reason
Layout
composable function has
content
parameter first and not last, so it would allow for container-like invocation?
z

Zach Klippenstein (he/him) [MOD]

01/08/2021, 6:31 PM
You can specify the parameters in whatever order you want if you name them
j

Javier

01/08/2021, 6:35 PM
but that forces to specify all names except content one to get the container invocation
o

orangy

01/08/2021, 6:36 PM
I can’t invoke it like
Layout(measureBlocks) { … }
in named parameters form
Oh, I got it. Confused by a different overload.
MeasureBlock
is a lambda typealias
a

Adam Powell

01/08/2021, 10:38 PM
yes, the intended usage here is for implementing a custom layout composable, e.g.:
Copy code
@Composable fun MyLayout(
  modifier: Modifier = Modifier,
  content: @Composable () -> Unit
) = Layout(content, modifier) { measurables, constraints ->
  // measure logic here
  layout(myWidth, myHeight) {
    // placement logic here
  }
}
so the measure/layout DSL block gets the trailing lambda position