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

Making fast scroller still be available to scroll its last part. #2364

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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