Skip to content

Commit 006294b

Browse files
authored
Merge pull request #66 from cheonjaeung/span-overriding
Fix span overriding bug
2 parents 8406dec + 10ddae1 commit 006294b

8 files changed

+66
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ internal class BoxGridSpanNode(
3939
) : Modifier.Node(), ParentDataModifierNode {
4040
override fun Density.modifyParentData(parentData: Any?): Any {
4141
val p = parentData as? BoxGridParentData ?: BoxGridParentData()
42-
span?.let {
43-
p.span = it
42+
if (p.span == null) {
43+
p.span = span
4444
}
4545
return p
4646
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ internal class HorizontalVerticalGridSpanNode(
3939
) : Modifier.Node(), ParentDataModifierNode {
4040
override fun Density.modifyParentData(parentData: Any?): Any {
4141
val p = parentData as? HorizontalVerticalGridParentData ?: HorizontalVerticalGridParentData()
42-
p.span = span
42+
if (p.span == HorizontalVerticalGridParentData.DefaultSpan) {
43+
p.span = span
44+
}
4345
return p
4446
}
4547
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,25 @@ class BoxGridSpanTest {
255255
}
256256
}
257257
}
258+
259+
@Test
260+
fun testOverrideSpan() {
261+
paparazzi.snapshot {
262+
BoxGrid(
263+
modifier = Modifier
264+
.fillMaxSize()
265+
.background(Color.LightGray),
266+
rows = SimpleGridCells.Fixed(4),
267+
columns = SimpleGridCells.Fixed(4)
268+
) {
269+
Box(
270+
modifier = Modifier
271+
.size(100.dp)
272+
.background(Color.Blue)
273+
.span { BoxGridItemSpan(row = 1, column = 1) }
274+
.span { BoxGridItemSpan(row = 2, column = 2) }
275+
)
276+
}
277+
}
278+
}
258279
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,24 @@ class HorizontalGridSpanTest {
200200
}
201201
}
202202
}
203+
204+
@Test
205+
fun testOverrideSpan() {
206+
paparazzi.snapshot {
207+
HorizontalGrid(
208+
modifier = Modifier
209+
.fillMaxSize()
210+
.background(Color.LightGray),
211+
rows = SimpleGridCells.Fixed(3)
212+
) {
213+
Box(
214+
modifier = Modifier
215+
.size(100.dp)
216+
.background(Color.Blue)
217+
.span { 1 }
218+
.span { 2 }
219+
)
220+
}
221+
}
222+
}
203223
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,24 @@ class VerticalGridSpanTest {
200200
}
201201
}
202202
}
203+
204+
@Test
205+
fun testOverrideSpan() {
206+
paparazzi.snapshot {
207+
VerticalGrid(
208+
modifier = Modifier
209+
.fillMaxSize()
210+
.background(Color.LightGray),
211+
columns = SimpleGridCells.Fixed(3)
212+
) {
213+
Box(
214+
modifier = Modifier
215+
.size(100.dp)
216+
.background(Color.Blue)
217+
.span { 1 }
218+
.span { 2 }
219+
)
220+
}
221+
}
222+
}
203223
}
3.65 KB
Loading
3.88 KB
Loading
3.17 KB
Loading

0 commit comments

Comments
 (0)