Skip to content

Commit

Permalink
fix: Click listeners triggers even when swiping
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamim Attafi authored and Tamim Attafi committed Aug 31, 2021
1 parent a1e8831 commit 7e741aa
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1018,30 +1018,21 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
onScrollerFinished(mAdjustScroller);
} else if (mLastDownEventX >= mLeftDividerLeft
&& mLastDownEventX <= mRightDividerRight) {
if (mOnClickListener != null) {
mOnClickListener.onClick(this);
}
} else if (mLastDownEventX < mLeftDividerLeft) {
postChangeCurrentByOneFromLongPress(false);
} else if (mLastDownEventX > mRightDividerRight) {
postChangeCurrentByOneFromLongPress(true);
}
} else {
mLastDownOrMoveEventY = mLastDownEventY = event.getY();
mLastDownOrMoveEventY = mLastDownEventY;
mLastDownEventY = event.getY();
if (!mFlingScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
} else if (!mAdjustScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
} else if (mLastDownEventY >= mTopDividerTop
&& mLastDownEventY <= mBottomDividerBottom) {
if (mOnClickListener != null) {
mOnClickListener.onClick(this);
}
} else if (mLastDownEventY < mTopDividerTop) {
postChangeCurrentByOneFromLongPress(false);
} else if (mLastDownEventY > mBottomDividerBottom) {
Expand Down Expand Up @@ -1118,6 +1109,9 @@ public boolean onTouchEvent(MotionEvent event) {
changeValueByOne(false);
} else {
ensureScrollWheelAdjusted();
if (mOnClickListener != null) {
mOnClickListener.onClick(this);
}
}
} else {
ensureScrollWheelAdjusted();
Expand All @@ -1141,13 +1135,17 @@ public boolean onTouchEvent(MotionEvent event) {
changeValueByOne(false);
} else {
ensureScrollWheelAdjusted();
if (mOnClickListener != null) {
mOnClickListener.onClick(this);
}
}
} else {
ensureScrollWheelAdjusted();
}
onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
}
}

mVelocityTracker.recycle();
mVelocityTracker = null;
}
Expand Down

0 comments on commit 7e741aa

Please sign in to comment.