Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Making fast scroller still be available to scroll its last part. (Fixes
Browse files Browse the repository at this point in the history
#1986) (#2364)

Good catch @daoshengmu, works great
  • Loading branch information
daoshengmu authored and keianhzo committed Nov 25, 2019
1 parent 259d171 commit d588b85
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,18 +498,23 @@ private void horizontalScrollTo(float x) {

private int scrollTo(float oldDragPos, float newDragPos, int[] scrollbarRange, int scrollRange,
int scrollOffset, int viewLength) {
int scrollbarLength = scrollbarRange[1] - scrollbarRange[0];
final int scrollbarLength = scrollbarRange[1] - scrollbarRange[0];
if (scrollbarLength == 0) {
return 0;
}
float percentage = ((newDragPos - oldDragPos) / (float) scrollbarLength);
int totalPossibleOffset = scrollRange - viewLength;
int scrollingBy = (int) (percentage * totalPossibleOffset);
int absoluteOffset = scrollOffset + scrollingBy;
final float percentage = ((newDragPos - oldDragPos) / (float)scrollbarLength);
final int totalPossibleOffset = scrollRange - viewLength;
final float scrollingBy = percentage * scrollRange;
final float absoluteOffset = scrollOffset + scrollingBy;

if (absoluteOffset < totalPossibleOffset && absoluteOffset >= 0) {
return scrollingBy;
// Java is down-casting and scrollingBy is a float. Therefore, we need to use ceil() or floor()
// to find out the nearest integer of pixels.
return scrollingBy > 0.0f ? (int) Math.ceil(scrollingBy) : (int) Math.floor(scrollingBy);
} else {
return 0;
// When scrolling the last part and its absoluteOffset is out of range of scrollbarLength,
// we still can scroll by its remaining scrollOffset.
return absoluteOffset < 0.0f ? -scrollOffset : totalPossibleOffset - scrollOffset;
}
}

Expand Down

0 comments on commit d588b85

Please sign in to comment.