Is there any way to define the width of an element...
# compose
b
Is there any way to define the width of an element after it had been measured in a custom layout?
Copy code
Layout(content = {
   Composable1()
   Composable2()
   ComposableWhoseSizeDependsOnOtherComposables()
} { measurables, constraints ->
 // I measure all the elements and get the width i'd like the last element to be
 layout(width, height) {
   // I place placables for composable 1 and 2
   //
   // How can i make composable 3's width depend on the measurements I had made on 1 and 2?
 }
}
a
Use
SubcomposeLayout
.
a
Not necessarily, this is a case where I would use a parent data modifier to tag composable 3 for different treatment, and handle it as part of the custom layout above. SubcomposeLayout would be overkill here since the only dependent element is width, not composed structure.
👍 1
b
Makes sense 👍 I think what i went with is messing with the constraints of the third composable. Something like:
Copy code
val linePlaceable = measurables.last().measure(
                constraints.copy(
                    minWidth = someMeasuredWidth,
                    maxWidth = someMeasuredWidth
                )
            )
Measuring it against those constraints is a nice way to change the size without requiring subcompose layout!