Mayank Saini
12/10/2020, 9:46 AMalpha08
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
12/10/2020, 4:33 PMGeorge Mount
12/10/2020, 4:56 PMlooseConstraints.copy(
maxWidth = layoutWidth - imageWidth / 2,
maxHeight = layoutHeight - gridTopOffset
)
Your gridTopOffset
is likely larger than your layoutHeight
Mayank Saini
12/11/2020, 3:20 AMalpha07
. What can be the solution here?George Mount
12/11/2020, 4:42 PM0
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)
)