Skip to content

Commit b04ea9c

Browse files
committed
Fix swapped spacing bug in BoxGrid
The horizontalSpacing and verticalSpacing was swapped when calculating the size of the spanned cell in BoxGrid. This fix corrects the calculation.
1 parent 38d51b7 commit b04ea9c

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

grid/src/commonMain/kotlin/com/cheonjaeung/compose/grid/BoxGridMeasurePolicy.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ private class BoxGridMeasureHelper(
144144
}
145145

146146
val cellWidthConstraints = cellWidthConstraintList[columnPosition] * columnSpan +
147-
verticalSpacingPx * (columnSpan - 1)
147+
horizontalSpacingPx * (columnSpan - 1)
148148
val cellHeightConstraints = cellHeightConstraintList[rowPosition] * rowSpan +
149-
horizontalSpacingPx * (rowSpan - 1)
149+
verticalSpacingPx * (rowSpan - 1)
150150

151151
val placeableConstraints = Constraints(
152152
minWidth = if (fillCellWidth) cellWidthConstraints else 0,

grid/src/test/java/com/cheonjaeung/compose/grid/BoxGridSpanTest.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,43 @@ class BoxGridSpanTest {
216216
}
217217
}
218218
}
219+
220+
@Test
221+
fun testSpanWithSpacing() {
222+
paparazzi.snapshot {
223+
BoxGrid(
224+
modifier = Modifier
225+
.fillMaxSize()
226+
.background(Color.LightGray),
227+
rows = SimpleGridCells.Fixed(4),
228+
columns = SimpleGridCells.Fixed(4),
229+
horizontalSpacing = 32.dp,
230+
verticalSpacing = 8.dp,
231+
) {
232+
Box(
233+
modifier = Modifier
234+
.position(row = 0, column = 0)
235+
.span { BoxGridItemSpan(row = 2) }
236+
.background(Color.Blue)
237+
)
238+
Box(
239+
modifier = Modifier
240+
.position(row = 1, column = 1)
241+
.span { BoxGridItemSpan(row = 2) }
242+
.background(Color.Green)
243+
)
244+
Box(
245+
modifier = Modifier
246+
.position(row = 2, column = 2)
247+
.span { BoxGridItemSpan(row = 2, column = 2) }
248+
.background(Color.Yellow)
249+
)
250+
Box(
251+
modifier = Modifier
252+
.position(row = 0, column = 1)
253+
.background(Color.Red)
254+
)
255+
}
256+
}
257+
}
219258
}
5.84 KB
Loading

0 commit comments

Comments
 (0)