browser scrollbar: record lost release at the end

Open
#23,389 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
67/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin
Domain
mobile, testing

Research direction

Start with AnkiDroid/src/test/java/com/ichi2/anki/ui/RecyclerFastScrollerTest.kt and inspect the existing test for releasing the thumb at the end before layout reaches the last row. Read the fast scroller's touch and layout handling to find why the final row remains scrollable after release. Reproduce the failure with this test, then confirm it passes when release leaves the final row fully visible.

Written by the indexing model from the issue text.

Description

Needs Triage
Subject: [PATCH] [EXISTING] test(scrollbar): record lost release at the end
---
Index: AnkiDroid/src/test/java/com/ichi2/anki/ui/RecyclerFastScrollerTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ui/RecyclerFastScrollerTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ui/RecyclerFastScrollerTest.kt
--- a/AnkiDroid/src/test/java/com/ichi2/anki/ui/RecyclerFastScrollerTest.kt	(revision dd0e6adae7311ec020eb84ad6d723bdf3ccf384b)
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/ui/RecyclerFastScrollerTest.kt	(revision e1115797e35deb6d59ff712b634101f16bb8e3d1)
@@ -17,8 +17,11 @@
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import com.ichi2.anki.EmptyApplicationCategory
 import com.ichi2.testutils.EmptyApplication
+import com.ichi2.testutils.rules.ExistingIssue
+import com.ichi2.testutils.rules.ExistingIssueRule
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
+import org.junit.Rule
 import org.junit.Test
 import org.junit.experimental.categories.Category
 import org.junit.runner.RunWith
@@ -31,6 +34,21 @@
 @Config(application = EmptyApplication::class)
 @Category(EmptyApplicationCategory::class)
 class RecyclerFastScrollerTest {
+    @get:Rule(order = Int.MIN_VALUE)
+    val existingIssueRule = ExistingIssueRule()
+
+    @Test
+    @ExistingIssue
+    fun `releasing the thumb at the end before layout reaches the last row`() {
+        val list = FastScrollerTestList(evenRows(200))
+        assertThat("the test starts away from the end", list.canScrollDown, equalTo(true))
+        list.press()
+        list.moveTo(trackProportion = 1f, advanceFrame = false)
+        list.release()
+
+        assertThat("the release leaves the final row fully visible", list.canScrollDown, equalTo(false))
+    }
+
     @Test
     fun `scroller hides after a thumb drag`() {
         val list = FastScrollerTestList(evenRows(200))
@@ -87,6 +105,8 @@
 
     val isScrollerHidden: Boolean get() = scroller.translationX == scroller.hiddenTranslationX.toFloat()
 
+    val canScrollDown: Boolean get() = recyclerView.canScrollVertically(1)
+
     init {
         scroller.attachRecyclerView(recyclerView)
         activity.setContentView(root, ViewGroup.LayoutParams(WIDTH, HEIGHT))
@@ -95,9 +115,13 @@
 
     fun press() = touch(MotionEvent.ACTION_DOWN, (scroller.handle.top + scroller.handle.bottom) / 2f)
 
-    fun moveTo(trackProportion: Float) {
+    fun moveTo(
+        trackProportion: Float,
+        advanceFrame: Boolean = true,
+    ) {
         val thumbHeight = scroller.handle.height
-        touch(MotionEvent.ACTION_MOVE, thumbHeight / 2f + trackProportion * (HEIGHT - thumbHeight))
+        val travel = scroller.height - scroller.handleBottomInset - thumbHeight
+        touch(MotionEvent.ACTION_MOVE, thumbHeight / 2f + trackProportion * travel, advanceFrame)
     }
 
     fun release() = touch(MotionEvent.ACTION_UP, fingerY)
@@ -107,12 +131,13 @@
     private fun touch(
         action: Int,
         y: Float,
+        advanceFrame: Boolean = true,
     ) {
         fingerY = y
         val event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), action, scroller.width / 2f, y, 0)
         scroller.dispatchTouchEvent(event)
         event.recycle()
-        showNextFrame()
+        if (advanceFrame) showNextFrame()
     }
 
     private fun showNextFrame() = shadowOf(Looper.getMainLooper()).idleFor(FRAME_INTERVAL)
Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
1d 11h
Merged PRs (30d)
383

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ankidroid/Anki-Android

All issues in ankidroid/Anki-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.