Fix child constraints in (Horizontal|Vertical)Grid
Bug: 290184746 Test: Manual. Wrote a demo with multiple grids in http://aosp/2635217 Change-Id: I2d67f43a53e76a7053473fce327c5f82a14f2c75
This commit is contained in:
@@ -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(
|
||||||
if (constraints.maxWidth != Constraints.Infinity) {
|
maxWidth =
|
||||||
constrainWidth(
|
if (constraints.maxWidth != Constraints.Infinity) {
|
||||||
(constraints.maxWidth - totalHorizontalSpacingBetweenChildren) / columns
|
(constraints.maxWidth - totalHorizontalSpacingBetweenChildren) / columns
|
||||||
)
|
} else {
|
||||||
}
|
Constraints.Infinity
|
||||||
if (constraints.maxHeight != Constraints.Infinity) {
|
},
|
||||||
constrainWidth(
|
maxHeight =
|
||||||
|
if (constraints.maxHeight != Constraints.Infinity) {
|
||||||
(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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user