avoid unnecessary recyclerview.scrollby calls at the fastscroller

This commit is contained in:
tibbi 2021-04-18 21:15:17 +02:00
parent c9c5682bc1
commit 4c93c0a510

View file

@ -298,15 +298,21 @@ class FastScroller : FrameLayout {
val movePercent = diffInMove / (recyclerViewWidth.toFloat() - handleWidth)
val target = (recyclerViewContentWidth - recyclerViewWidth) * movePercent
val diff = target.toInt() - currScrollX
if (diff != 0) {
recyclerView!!.scrollBy(diff, 0)
}
} else {
targetProportion = currScrollY / recyclerViewContentHeight.toFloat()
val diffInMove = pos - handleYOffset
val movePercent = diffInMove / (recyclerViewHeight.toFloat() - handleHeight)
val target = (recyclerViewContentHeight - recyclerViewHeight) * movePercent
val diff = target.toInt() - currScrollY
if (diff != 0) {
recyclerView!!.scrollBy(0, diff)
}
}
val itemCount = recyclerView!!.adapter!!.itemCount
val targetPos = getValueInRange(0, itemCount - 1, targetProportion * itemCount).toInt()