aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-13 23:12:56 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2022-06-13 23:12:56 +0000
commit9d2c9c1df865faad192b60da847ee9bc6e9bf345 (patch)
treea854ca01b36a0a3ebafa81010af382bf1a3d4e45
parent2278f81c643524c22487958beca5d5d8813aca28 (diff)
parent0a36077b10a731491b6bd19feb179a074dd981de (diff)
downloadsupport-9d2c9c1df865faad192b60da847ee9bc6e9bf345.tar.gz
Merge "Fix for a crash in IntervalList" into snap-temp-L22600000955094635
-rw-r--r--compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyGridTest.kt20
-rw-r--r--compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/LazyListTest.kt22
-rw-r--r--compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.kt2
-rw-r--r--compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/lazy/MutableIntervalListTest.kt26
4 files changed, 69 insertions, 1 deletions
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyGridTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyGridTest.kt
index 7b5e760aad2..396ec8dbb82 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyGridTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyGridTest.kt
@@ -721,6 +721,26 @@ class LazyGridTest(
}
@Test
+ fun maxIntElements_withKey_startInMiddle() {
+ val itemSize = with(rule.density) { 15.toDp() }
+
+ rule.setContent {
+ LazyGrid(
+ cells = 1,
+ modifier = Modifier.size(itemSize),
+ state = LazyGridState(firstVisibleItemIndex = Int.MAX_VALUE / 2)
+ ) {
+ items(Int.MAX_VALUE, key = { it }) {
+ Box(Modifier.size(itemSize).testTag("$it"))
+ }
+ }
+ }
+
+ rule.onNodeWithTag("${Int.MAX_VALUE / 2}")
+ .assertMainAxisStartPositionInRootIsEqualTo(0.dp)
+ }
+
+ @Test
fun pointerInputScrollingIsAllowedWhenUserScrollingIsEnabled() {
val itemSize = with(rule.density) { 30.toDp() }
rule.setContentWithTestViewConfiguration {
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/LazyListTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/LazyListTest.kt
index e38956c49e4..48a7d4bc94e 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/LazyListTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/list/LazyListTest.kt
@@ -1508,6 +1508,28 @@ class LazyListTest(orientation: Orientation) : BaseLazyListTestWithOrientation(o
}
@Test
+ fun maxIntElements_withKey_startInMiddle() {
+ val itemSize = with(rule.density) { 15.toDp() }
+
+ rule.setContent {
+ LazyColumnOrRow(
+ modifier = Modifier.requiredSize(itemSize),
+ state = LazyListState(firstVisibleItemIndex = Int.MAX_VALUE / 2)
+ ) {
+ items(Int.MAX_VALUE, key = { it }) {
+ Box(
+ Modifier
+ .size(itemSize)
+ .testTag("$it"))
+ }
+ }
+ }
+
+ rule.onNodeWithTag("${Int.MAX_VALUE / 2}")
+ .assertStartPositionInRootIsEqualTo(0.dp)
+ }
+
+ @Test
fun scrollingByExactlyTheItemSize_switchesTheFirstVisibleItem() {
val itemSize = with(rule.density) { 30.toDp() }
lateinit var state: LazyListState
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.kt
index 19c8d19e586..f855bea50b5 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/layout/IntervalList.kt
@@ -147,7 +147,7 @@ class MutableIntervalList<T> : IntervalList<T> {
}
var intervalIndex = intervals.binarySearch(fromIndex)
- var itemIndex = fromIndex
+ var itemIndex = intervals[intervalIndex].startIndex
while (itemIndex <= toIndex) {
val interval = intervals[intervalIndex]
block(interval)
diff --git a/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/lazy/MutableIntervalListTest.kt b/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/lazy/MutableIntervalListTest.kt
index 9ec910c8a65..78b57260a32 100644
--- a/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/lazy/MutableIntervalListTest.kt
+++ b/compose/foundation/foundation/src/test/kotlin/androidx/compose/foundation/lazy/MutableIntervalListTest.kt
@@ -211,6 +211,20 @@ class MutableIntervalListTest {
}
@Test
+ fun forEach_fromIndexIsInTheMiddleOfInterval() {
+ intervalList.addInterval(10, 0) // startIndex = 0
+ intervalList.addInterval(1, 1) // startIndex = 10
+ intervalList.addInterval(1, 2) // startIndex = 11
+ val intervals = mutableListOf<IntervalList.Interval<Int>>()
+
+ intervalList.forEach(fromIndex = 5, toIndex = 10) {
+ intervals.add(it)
+ }
+
+ assertThat(intervals.map { it.startIndex }).isEqualTo(listOf(0, 10))
+ }
+
+ @Test
fun forEach_startLargerThanEndThrows() {
addFiveSingleIntervals()
@@ -261,6 +275,18 @@ class MutableIntervalListTest {
assertThat(wasException4).isTrue()
}
+ @Test
+ fun forEach_MAX_VALUE_size_andFromIndexIsInTheMiddle() {
+ intervalList.addInterval(Int.MAX_VALUE, 0)
+ val intervals = mutableListOf<IntervalList.Interval<Int>>()
+
+ intervalList.forEach(fromIndex = Int.MAX_VALUE / 2, toIndex = Int.MAX_VALUE - 1) {
+ intervals.add(it)
+ }
+
+ assertThat(intervals.map { it.startIndex }).isEqualTo(listOf(0))
+ }
+
private fun addFiveSingleIntervals() {
intervalList.addInterval(1, 10)
intervalList.addInterval(1, 20)