Skip to content

Commit f2f6759

Browse files
authored
Merge pull request #108 from cheonjaeung/cheon/optimizing
Add skipping line calculation for sequaltial grid if all items can't be displayed
2 parents b90f3b4 + 449a6ee commit f2f6759

5 files changed

Lines changed: 73 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ private class SequentialGridMeasureHelper(
205205
measurableIndex++
206206
}
207207

208+
// Skip calculation because all items in the line have too much span (span > maxSpan).
209+
if (spanLine.isEmpty()) {
210+
continue
211+
}
212+
208213
val placeableLine = mutableListOf<PlaceableMeasureInfo>()
209214
val maxMainAxisIntrinsicSize = if (containsFillMaxMainAxisSize) {
210215
mainAxisMaxIntrinsicSizes.fastMaxOfOrNull { it ?: 0 }

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.cheonjaeung.compose.grid
22

33
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Arrangement
45
import androidx.compose.foundation.layout.Box
6+
import androidx.compose.foundation.layout.fillMaxHeight
57
import androidx.compose.foundation.layout.fillMaxSize
68
import androidx.compose.foundation.layout.size
79
import androidx.compose.foundation.layout.width
@@ -202,6 +204,38 @@ class HorizontalGridSpanTest {
202204
}
203205
}
204206

207+
@Test
208+
fun testAllOverSpanItemsAreNotPlaced() {
209+
paparazzi.snapshot {
210+
Box(
211+
modifier = Modifier
212+
.fillMaxSize()
213+
.background(Color.DarkGray)
214+
) {
215+
HorizontalGrid(
216+
modifier = Modifier
217+
.fillMaxHeight()
218+
.background(Color.LightGray),
219+
rows = SimpleGridCells.Fixed(3),
220+
horizontalArrangement = Arrangement.spacedBy(8.dp),
221+
) {
222+
Box(
223+
modifier = Modifier
224+
.size(100.dp)
225+
.background(Color.Blue)
226+
.span { maxLineSpan + 1 }
227+
)
228+
Box(
229+
modifier = Modifier
230+
.size(100.dp)
231+
.background(Color.Green)
232+
.span { maxLineSpan + 2 }
233+
)
234+
}
235+
}
236+
}
237+
}
238+
205239
@Test
206240
fun testOverrideSpan() {
207241
paparazzi.snapshot {

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.cheonjaeung.compose.grid
22

33
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Arrangement
45
import androidx.compose.foundation.layout.Box
56
import androidx.compose.foundation.layout.fillMaxSize
7+
import androidx.compose.foundation.layout.fillMaxWidth
68
import androidx.compose.foundation.layout.height
79
import androidx.compose.foundation.layout.size
810
import androidx.compose.ui.Modifier
@@ -202,6 +204,38 @@ class VerticalGridSpanTest {
202204
}
203205
}
204206

207+
@Test
208+
fun testAllOverSpanItemsAreNotPlaced() {
209+
paparazzi.snapshot {
210+
Box(
211+
modifier = Modifier
212+
.fillMaxSize()
213+
.background(Color.DarkGray)
214+
) {
215+
VerticalGrid(
216+
modifier = Modifier
217+
.fillMaxWidth()
218+
.background(Color.LightGray),
219+
columns = SimpleGridCells.Fixed(3),
220+
verticalArrangement = Arrangement.spacedBy(8.dp),
221+
) {
222+
Box(
223+
modifier = Modifier
224+
.size(100.dp)
225+
.background(Color.Blue)
226+
.span { maxLineSpan + 1 }
227+
)
228+
Box(
229+
modifier = Modifier
230+
.size(100.dp)
231+
.background(Color.Green)
232+
.span { maxLineSpan + 2 }
233+
)
234+
}
235+
}
236+
}
237+
}
238+
205239
@Test
206240
fun testOverrideSpan() {
207241
paparazzi.snapshot {
3.02 KB
Loading
3.02 KB
Loading

0 commit comments

Comments
 (0)