Hi Folks, I have a ComposeView (with LazyRow content) embedded in a LinearLayout with a weight.
And I get this error
Horizontally scrollable component was measured with an infinity maximum width constraints, which is disallowed. One of the common reasons is nesting layouts like LazyRow and Row(Modifier.horizontalScroll()). If you want to add a header before the list of items please add a header as a separate item() before the main items() inside the LazyRow scope. There are could be other reasons for this to happen: your ComposeView was added into a LinearLayout with some weight, you applied Modifier.wrapContentSize(unbounded = true) or wrote a custom layout. Please try to remove the source of infinite constraints in the hierarchy above the scrolling container.
I'm surprised this is an invalid combination. 🤔
My understanding is there are two passes to weighted children of linearLayouts, the first one passes 0 and then the second passes the appropriate width by sharing the available space with the weighted children
However, on debugging (using BoxWithConstraints) it seems that on the initial pass the maxWidth passed to the ComposeView is Infinity. Which causes the error above.
Is there any recommended approach for having Scrollable content embedded in linearLayouts with width?
I have a hack which is using
Modifier.widthIn(0.dp, 0.dp)
Which works because it is a more restrictive constraint than the (0, Infinity) constraint passed on the first measure phase of the linearlayout
But seems weird that this is not supported by default.