When will Subcompose Layout support Intrinsic layout, if ever?

Viewed 1635

I see this function in the source code of androidx.compose.ui.layout.SubcomposeLayout.kt in androidx.compose.ui:ui:1.0.0-beta02.

    private fun createMeasurePolicy(
        block: SubcomposeMeasureScope.(Constraints) -> MeasureResult
    ): MeasurePolicy = object : LayoutNode.NoIntrinsicsMeasurePolicy(
        error = "Intrinsic measurements are not currently supported by SubcomposeLayout"
    ) {
        ...
    }

It looks like I can't use intrinsic measurement when the composable will be rendered within a subcomposable.

For reference, I'm trying to use a view like this inside a ModalBottomSheet. The intention is to have a scrollable view within the sheet, with a sticky view always at the bottom (like a button). I'd like the scrollable content to only take up as much space as it needs, and not always be full screen when in the sheets expanded state, which weight(1f) does.

Column(
        modifier = Modifier
                .height(IntrinsicSize.Min)
                .wrapContentHeight(Alignment.Bottom),
        verticalArrangement = Arrangement.Bottom
) {
  Column(
          content = sheetContent,
          modifier = Modifier
                  .weight(1f)
                  .wrapContentHeight(Alignment.Bottom)
  )
  Box {
    bottomStickyContent?.let { it() }
  }
}
1 Answers

Sounds like the answer is no, SubcomposeLayout will not get Intrinsic support anytime soon, if ever.

I solved this problem by updating by code to use constraint layout.

ConstraintLayout {
  val (sticky, column) = createRefs()
  Column(
          content = sheetContent,
          modifier = Modifier
                  .constrainAs(column) {
                    top.linkTo(parent.top)
                    bottom.linkTo(sticky.top)
                    height = Dimension.preferredWrapContent
                  }
                  .wrapContentHeight(Alignment.Bottom)
  )
  Box(
          modifier = Modifier
                  .constrainAs(sticky) {
                    bottom.linkTo(parent.bottom)
                  }
  ) {
    bottomStickyContent?.let { it() }
  }
}
Related