Skip to content

Commit

Permalink
Corner case fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Olifer committed Aug 22, 2018
1 parent 9bb74c4 commit 76696cc
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

@Override
protected void onDraw(Canvas canvas) {
if (getDotCount() < visibleDotThreshold) {
int dotCount = getDotCount();
if (dotCount < visibleDotThreshold) {
return;
}

Expand All @@ -391,6 +392,12 @@ protected void onDraw(Canvas canvas) {
+ (int) (visibleFramePosition + visibleFrameWidth - getDotOffsetAt(firstVisibleDotPos))
/ spaceBetweenDotCenters;

// If real dots count is less than we can draw inside visible frame, we move lastVisibleDotPos
// to the last item
if (firstVisibleDotPos == 0 && lastVisibleDotPos + 1 > dotCount) {
lastVisibleDotPos = dotCount - 1;
}

for (int i = firstVisibleDotPos; i <= lastVisibleDotPos; i++) {
float dot = getDotOffsetAt(i);
if (dot >= visibleFramePosition && dot < visibleFramePosition + visibleFrameWidth) {
Expand All @@ -417,7 +424,7 @@ protected void onDraw(Canvas canvas) {
// Additional scale for dots at corners
if (itemCount > visibleDotCount) {
float currentScaleDistance;
if (!looped && (i == 0 || i == getDotCount() - 1)) {
if (!looped && (i == 0 || i == dotCount - 1)) {
currentScaleDistance = smallScaleDistance;
} else {
currentScaleDistance = scaleDistance;
Expand Down

0 comments on commit 76696cc

Please sign in to comment.