| @@ -12,10 +12,13 @@ import android.widget.LinearLayout |
| 12 | 12 | import android.widget.TextView |
| 13 | 13 | import androidx.recyclerview.widget.GridLayoutManager |
| 14 | 14 | import androidx.recyclerview.widget.LinearLayoutManager |
| 15 | +import androidx.recyclerview.widget.RecyclerView |
| 15 | 16 | import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 16 | 17 | import androidx.test.core.app.ActivityScenario |
| 17 | 18 | import androidx.test.platform.app.InstrumentationRegistry |
| 18 | 19 | import java.util.concurrent.atomic.AtomicInteger |
| 20 | +import java.util.concurrent.CountDownLatch |
| 21 | +import java.util.concurrent.TimeUnit |
| 19 | 22 | import org.json.JSONArray |
| 20 | 23 | import org.json.JSONObject |
| 21 | 24 | import org.junit.Assert.assertEquals |
| @@ -180,26 +183,30 @@ class NativeFlatListTest { |
| 180 | 183 | val scrollCount = AtomicInteger() |
| 181 | 184 | val momentumBeginCount = AtomicInteger() |
| 182 | 185 | val momentumEndCount = AtomicInteger() |
| 186 | + val momentumEnded = CountDownLatch(1) |
| 183 | 187 | val rows = (0 until 100).map(::row) |
| 184 | 188 | try { |
| 185 | 189 | instrumentation.runOnMainSync { |
| 186 | 190 | list.onScrollEvent = { scrollCount.incrementAndGet() } |
| 187 | 191 | list.onMomentumScrollBegin = { momentumBeginCount.incrementAndGet() } |
| 188 | | - list.onMomentumScrollEnd = { momentumEndCount.incrementAndGet() } |
| 192 | + list.onMomentumScrollEnd = { |
| 193 | + momentumEndCount.incrementAndGet() |
| 194 | + momentumEnded.countDown() |
| 195 | + } |
| 189 | 196 | list.apply(rows, false, 1, false, 0.1, renderer(context, AtomicInteger()), { _ -> }, { _ -> }, null) |
| 190 | 197 | } |
| 191 | 198 | awaitCount(list, 100) |
| 192 | 199 | instrumentation.runOnMainSync { |
| 193 | 200 | attach(list) |
| 194 | | - list.smoothScrollToPosition(99) |
| 195 | | - } |
| 196 | | - repeat(50) { |
| 197 | | - if (momentumEndCount.get() > 0) return@repeat |
| 198 | | - SystemClock.sleep(50) |
| 201 | + |
| 202 | + |
| 203 | + list.smoothScrollBy(0, list.height) |
| 199 | 204 | } |
| 205 | + assertTrue("RecyclerView did not finish its native momentum animation", momentumEnded.await(2500, TimeUnit.MILLISECONDS)) |
| 200 | 206 | assertTrue("RecyclerView did not emit scroll callbacks", scrollCount.get() > 0) |
| 201 | 207 | assertEquals(1, momentumBeginCount.get()) |
| 202 | 208 | assertEquals(1, momentumEndCount.get()) |
| 209 | + instrumentation.runOnMainSync { assertEquals(RecyclerView.SCROLL_STATE_IDLE, list.scrollState) } |
| 203 | 210 | } finally { |
| 204 | 211 | scenario.close() |
| 205 | 212 | } |