6

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() } } } 
0

2 Answers 2

5

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() } } } 
Sign up to request clarification or add additional context in comments.

Comments

1

To me, it doesn't make sense to have the support of Intrinsic in Subcompose layout.

If you think, in a normal container(non-Subcompose) layout, what Intrisic does that pre-measure(pre-measuring is cheap as compared to actual measure and follow some heuretics) all the items and finds max or min size a child can take and then the container enforces that size to each child

In the case of Subcompose layout measurements of some components are done upfront but not of all(to prevent measurement of potentially very large sets). It is not able to know what should be the maximum or minimum size among all the children.

Even the latest compose gives the following error

java.lang.IllegalStateException: Asking for intrinsic measurements of SubcomposeLayout layouts is not supported. This includes components that are built on top of SubcomposeLayout, such as lazy lists, BoxWithConstraints, TabRow, etc. To mitigate this: 
- if intrinsic measurements are used to achieve 'match parent' sizing,, consider replacing the parent of the component with a custom layout which controls the order in which children are measured, making intrinsic measurement not needed 
- adding a size modifier to the component, in order to fast return the queried intrinsic measurement 

I have deduced this from the MAD compose series video

2 Comments

What about using a FlowRow inside a FlowRow?
Yes you are right.. same should apply

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.