summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jordan Demeulenaere <jdemeulenaere@google.com> 2023-07-10 15:41:25 +0200
committer Jordan Demeulenaere <jdemeulenaere@google.com> 2023-07-13 18:02:46 +0200
commit3d5bf056c331c5dce3926e1111ecff018e08d445 (patch)
tree7fa940b1040c0022c16ae2165c253aad1ce860c1
parentfc8905a72bcbd8f833f41627c7362c18fb6708f9 (diff)
Fix child constraints in (Horizontal|Vertical)Grid
Bug: 290184746 Test: Manual. Wrote a demo with multiple grids in http://aosp/2635217 Change-Id: I2d67f43a53e76a7053473fce327c5f82a14f2c75
-rw-r--r--packages/SystemUI/compose/core/src/com/android/compose/grid/Grids.kt23
1 files changed, 12 insertions, 11 deletions
diff --git a/packages/SystemUI/compose/core/src/com/android/compose/grid/Grids.kt b/packages/SystemUI/compose/core/src/com/android/compose/grid/Grids.kt
index 5224c51bb7c3..27f0948d5377 100644
--- a/packages/SystemUI/compose/core/src/com/android/compose/grid/Grids.kt
+++ b/packages/SystemUI/compose/core/src/com/android/compose/grid/Grids.kt
@@ -22,7 +22,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp
-import androidx.compose.ui.unit.constrainWidth
import androidx.compose.ui.unit.dp
import kotlin.math.ceil
import kotlin.math.max
@@ -126,18 +125,20 @@ private fun Grid(
((columns - 1) * horizontalSpacing.toPx()).roundToInt()
val totalVerticalSpacingBetweenChildren = ((rows - 1) * verticalSpacing.toPx()).roundToInt()
val childConstraints =
- Constraints().apply {
- if (constraints.maxWidth != Constraints.Infinity) {
- constrainWidth(
+ Constraints(
+ maxWidth =
+ if (constraints.maxWidth != Constraints.Infinity) {
(constraints.maxWidth - totalHorizontalSpacingBetweenChildren) / columns
- )
- }
- if (constraints.maxHeight != Constraints.Infinity) {
- constrainWidth(
+ } else {
+ Constraints.Infinity
+ },
+ maxHeight =
+ if (constraints.maxHeight != Constraints.Infinity) {
(constraints.maxHeight - totalVerticalSpacingBetweenChildren) / rows
- )
- }
- }
+ } else {
+ Constraints.Infinity
+ }
+ )
val placeables = buildList {
for (cellIndex in measurables.indices) {