Fixes to fast scroller

Using android back gesture no longer sometimes jump the screen
Fix issue when sometimes dragging fastscroll tries to drag to the top on release
This commit is contained in:
Jays2Kings 2021-04-24 14:09:49 -04:00
parent 0327accecb
commit bc760cf7b1
3 changed files with 28 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager import androidx.recyclerview.widget.StaggeredGridLayoutManager
import eu.davidea.fastscroller.FastScroller import eu.davidea.fastscroller.FastScroller
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.dpToPxEnd import eu.kanade.tachiyomi.util.system.dpToPxEnd
import eu.kanade.tachiyomi.util.view.marginTop import eu.kanade.tachiyomi.util.view.marginTop
import kotlin.math.abs import kotlin.math.abs
@ -53,7 +54,7 @@ class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: Attr
} }
MotionEvent.ACTION_MOVE -> { MotionEvent.ACTION_MOVE -> {
val y = event.y val y = event.y
if (!canScroll && abs(y - startY) > 10) { if (!canScroll && abs(y - startY) > 15.dpToPx) {
canScroll = true canScroll = true
handle.isSelected = true handle.isSelected = true
notifyScrollStateChange(true) notifyScrollStateChange(true)
@ -69,6 +70,22 @@ class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: Attr
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
startY = 0f startY = 0f
canScroll = false canScroll = false
val newEvent = MotionEvent.obtain(event)
recyclerView.post {
// Mimic touch event for recycler so it doesn't scroll back
val lastTag = recyclerView.tag
recyclerView.tag = noUpdate
newEvent.action = MotionEvent.ACTION_MOVE
recyclerView.dispatchTouchEvent(newEvent)
val newEvent2 = MotionEvent.obtain(newEvent)
newEvent2.action = MotionEvent.ACTION_CANCEL
recyclerView.dispatchTouchEvent(newEvent2)
newEvent2.recycle()
newEvent.recycle()
recyclerView.post {
recyclerView.tag = lastTag
}
}
} }
} }
return super.onTouchEvent(event) return super.onTouchEvent(event)
@ -91,7 +108,10 @@ class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: Attr
scrollOffset scrollOffset
) )
} else { } else {
(layoutManager as LinearLayoutManager).scrollToPositionWithOffset(targetPos, scrollOffset) (layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
targetPos,
scrollOffset
)
} }
updateBubbleText(targetPos) updateBubbleText(targetPos)
} }
@ -114,4 +134,8 @@ class MaterialFastScroll @JvmOverloads constructor(context: Context, attrs: Attr
} }
} }
} }
companion object {
const val noUpdate = "don't update scroll"
}
} }

View File

@ -219,6 +219,7 @@ class LibraryController(
private var scrollListener = object : RecyclerView.OnScrollListener() { private var scrollListener = object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy) super.onScrolled(recyclerView, dx, dy)
if (recyclerView.tag == MaterialFastScroll.noUpdate) return
val recyclerCover = binding.recyclerCover val recyclerCover = binding.recyclerCover
if (!recyclerCover.isClickable && isAnimatingHopper != true) { if (!recyclerCover.isClickable && isAnimatingHopper != true) {
if (preferences.autohideHopper().get()) { if (preferences.autohideHopper().get()) {

View File

@ -251,6 +251,7 @@ fun Controller.scrollViewWith(
object : RecyclerView.OnScrollListener() { object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy) super.onScrolled(recyclerView, dx, dy)
if (recyclerView.tag == MaterialFastScroll.noUpdate) return
if (router?.backstack?.lastOrNull() if (router?.backstack?.lastOrNull()
?.controller() == this@scrollViewWith && statusBarHeight > -1 && ?.controller() == this@scrollViewWith && statusBarHeight > -1 &&
activity != null && activityBinding!!.appBar.height > 0 && activity != null && activityBinding!!.appBar.height > 0 &&