I have recently upgraded to compose `alpha08` I ha...
# compose
m
I have recently upgraded to compose
alpha08
I have encountered this error in
layout
while measuring height.
java.lang.IllegalArgumentException: maxHeight(-35) must be >= minHeight(0)
This is the code snippet.
Copy code
SubcomposeLayout(modifier = modifier) { constraints ->
        val layoutWidth = constraints.maxWidth
        val layoutHeight = constraints.maxHeight
        val gridTopOffset = 10.dp.toPx().toInt()
        val looseConstraints = constraints.copy(minWidth = 0, minHeight = 0)
        layout(width = layoutWidth, height = layoutHeight) {
            val imagePlaceables = subcompose(GamesCompositionContent.Image, image).fastMap {
                it.measure(looseConstraints.copy(minHeight = layoutHeight))
            }
            val imageWidth = imagePlaceables.fastMaxBy { it.width }?.width ?: 0

            val gridPlaceables = subcompose(GamesCompositionContent.GamesGrid) {
                val innerPadding = PaddingValues(
                    start = if (imageWidth != 0) (imageWidth / 2).toDp() else 0.dp
                )
                grid(innerPadding)
            }.fastMap {
                it.measure(
                    looseConstraints.copy(
                        maxWidth = layoutWidth - imageWidth / 2,
                        maxHeight = layoutHeight - gridTopOffset
                    )
                )
            }
The code was working perfectly and no crashes on
alpha07
.
j
cc @George Mount
g
It looks like it comes from this line:
Copy code
looseConstraints.copy(
  maxWidth = layoutWidth - imageWidth / 2,
  maxHeight = layoutHeight - gridTopOffset
)
Your
gridTopOffset
is likely larger than your
layoutHeight
m
@George Mount Exactly this is the line where it crashes, and it was working perfectly in
alpha07
. What can be the solution here?
g
The check isn't new, so I'm guessing that you're being measured with a
0
height for some reason. The solution is to ensure your maxes are within range:
Copy code
looseConstraints.copy(
  maxWidth = (layoutWidth - imageWidth / 2).coerceAtLeast(looseConstraints.minWidth),
  maxHeight = (layoutHeight - gridTopOffset).coerceAtLeast(looseConstraints.minHeight)
)