Fix child constraints in (Horizontal|Vertical)Grid am: 3d5bf056c3

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24006843

Change-Id: I3c28331fb3cdeefbe246b525e8755edab1fc885f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jordan Demeulenaere
2023-07-21 08:15:41 +00:00
committed by Automerger Merge Worker

View File

@@ -22,7 +22,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.constrainWidth
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.max import kotlin.math.max
@@ -126,18 +125,20 @@ private fun Grid(
((columns - 1) * horizontalSpacing.toPx()).roundToInt() ((columns - 1) * horizontalSpacing.toPx()).roundToInt()
val totalVerticalSpacingBetweenChildren = ((rows - 1) * verticalSpacing.toPx()).roundToInt() val totalVerticalSpacingBetweenChildren = ((rows - 1) * verticalSpacing.toPx()).roundToInt()
val childConstraints = val childConstraints =
Constraints().apply { Constraints(
maxWidth =
if (constraints.maxWidth != Constraints.Infinity) { if (constraints.maxWidth != Constraints.Infinity) {
constrainWidth(
(constraints.maxWidth - totalHorizontalSpacingBetweenChildren) / columns (constraints.maxWidth - totalHorizontalSpacingBetweenChildren) / columns
) } else {
} Constraints.Infinity
},
maxHeight =
if (constraints.maxHeight != Constraints.Infinity) { if (constraints.maxHeight != Constraints.Infinity) {
constrainWidth(
(constraints.maxHeight - totalVerticalSpacingBetweenChildren) / rows (constraints.maxHeight - totalVerticalSpacingBetweenChildren) / rows
} else {
Constraints.Infinity
}
) )
}
}
val placeables = buildList { val placeables = buildList {
for (cellIndex in measurables.indices) { for (cellIndex in measurables.indices) {