browse: nav reveal during thumb drag

Open Beginner friendly
#23,390 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/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/BottomNavigationScrollTest.kt and read the existing browser navigation scroll tests. Run the new thumb drag test to reproduce the behavior: during a drag toward later rows, navigation should stay hidden while more rows remain below the viewport. Then trace the scroll and navigation behavior involved and confirm the test passes.

Written by the indexing model from the issue text.

Description

Needs Triage
Subject: [PATCH] [EXISTING] test(browse): record nav reveal during thumb drag
---
Index: AnkiDroid/src/test/java/com/ichi2/anki/BottomNavigationScrollTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/BottomNavigationScrollTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/BottomNavigationScrollTest.kt
--- a/AnkiDroid/src/test/java/com/ichi2/anki/BottomNavigationScrollTest.kt	(revision e1115797e35deb6d59ff712b634101f16bb8e3d1)
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/BottomNavigationScrollTest.kt	(revision 1d7069aafdd8a0cdc6afa17486841adaccc6c4fb)
@@ -32,10 +32,13 @@
 import com.ichi2.anki.settings.Prefs
 import com.ichi2.anki.ui.RecyclerFastScroller
 import com.ichi2.testutils.dispatchInsets
+import com.ichi2.testutils.rules.ExistingIssue
+import com.ichi2.testutils.rules.ExistingIssueRule
 import com.ichi2.testutils.withPref
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
 import org.hamcrest.Matchers.lessThanOrEqualTo
+import org.junit.Rule
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.robolectric.Shadows.shadowOf
@@ -45,6 +48,9 @@
 
 @RunWith(AndroidJUnit4::class)
 class BottomNavigationScrollTest : RobolectricTest() {
+    @get:Rule(order = Int.MIN_VALUE)
+    val existingIssueRule = ExistingIssueRule()
+
     @Test
     fun `reaching the last browser row shows navigation and keeps the row above it`() {
         repeat(80) { addBasicNote("Card $it", "Answer") }
@@ -111,6 +117,58 @@
         }
     }
 
+    @Test
+    @ExistingIssue
+    fun `dragging the scrollbar toward later rows keeps navigation hidden mid-list`() {
+        repeat(200) { addBasicNote("Card $it", "Answer") }
+        withBottomNavigation { activity ->
+            val nav = activity.bottomNav
+            nav.selectedItemId = NavigationItem.BROWSER.id
+            advanceRobolectricLooper()
+            val list = activity.findViewById<RecyclerView>(R.id.card_browser_list)
+            list.descendantFocusability = ViewGroup.FOCUS_BLOCK_DESCENDANTS
+            val layout = list.layoutManager as LinearLayoutManager
+            list.scrollToPosition(50)
+            advanceRobolectricLooper()
+            val behavior = HideViewOnScrollBehavior.from(nav)
+            behavior.slideOut(nav)
+            advanceRobolectricLooper()
+            assertThat("navigation starts hidden", behavior.isScrolledOut, equalTo(true))
+
+            val scroller = activity.findViewById<RecyclerFastScroller>(R.id.browser_scroller)
+            scroller.isHidingEnabled = false
+            scroller.show(animate = false)
+            advanceRobolectricLooper()
+            val startPosition = layout.findFirstVisibleItemPosition()
+            val position = IntArray(2).also(scroller::getLocationInWindow)
+            val startY = position[1] + scroller.handle.top + scroller.handle.height / 2f
+            val endY = position[1] + scroller.height * 0.6f
+            val startTime = SystemClock.uptimeMillis()
+            val x = position[0] + scroller.width / 2f
+
+            fun touch(
+                action: Int,
+                elapsed: Long,
+                y: Float,
+            ) {
+                val event = MotionEvent.obtain(startTime, startTime + elapsed, action, x, y, 0)
+                activity.dispatchTouchEvent(event)
+                event.recycle()
+            }
+
+            touch(MotionEvent.ACTION_DOWN, 0, startY)
+            for (step in 1..5) {
+                touch(MotionEvent.ACTION_MOVE, step * 10L, startY + (endY - startY) * step / 5f)
+            }
+            touch(MotionEvent.ACTION_UP, 60, endY)
+            advanceRobolectricLooper()
+
+            assertThat("the thumb drag moved toward later rows", layout.findFirstVisibleItemPosition() > startPosition, equalTo(true))
+            assertThat("more rows remain below the viewport", list.canScrollVertically(1), equalTo(true))
+            assertThat("navigation stays hidden in the middle of the list", behavior.isScrolledOut, equalTo(true))
+        }
+    }
+
     @Test
     fun `navigation stays visible when the browser list fits on screen`() =
         withBottomNavigation { activity ->
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.