Thread
#compose
    Boris Kachscovsky

    Boris Kachscovsky

    1 year ago
    Is there any way to define the width of an element after it had been measured in a custom layout?
    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?
     }
    }
    Albert Chang

    Albert Chang

    1 year ago
    Use
    SubcomposeLayout
    .
    Adam Powell

    Adam Powell

    1 year ago
    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.
    Boris Kachscovsky

    Boris Kachscovsky

    1 year ago
    Makes sense 👍 I think what i went with is messing with the constraints of the third composable. Something like:
    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!