Thread
#compose
    Mayank Saini

    Mayank Saini

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

    jim

    1 year ago
    cc @George Mount
    George Mount

    George Mount

    1 year ago
    It looks like it comes from this line:
    looseConstraints.copy(
      maxWidth = layoutWidth - imageWidth / 2,
      maxHeight = layoutHeight - gridTopOffset
    )
    Your
    gridTopOffset
    is likely larger than your
    layoutHeight
    Mayank Saini

    Mayank Saini

    1 year ago
    @George Mount Exactly this is the line where it crashes, and it was working perfectly in
    alpha07
    . What can be the solution here?
    George Mount

    George Mount

    1 year ago
    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:
    looseConstraints.copy(
      maxWidth = (layoutWidth - imageWidth / 2).coerceAtLeast(looseConstraints.minWidth),
      maxHeight = (layoutHeight - gridTopOffset).coerceAtLeast(looseConstraints.minHeight)
    )