Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Slider] Fix the handle width when touched #4151

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 22 additions & 9 deletions lib/java/com/google/android/material/slider/BaseSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -2357,8 +2357,7 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {

requestFocus();
thumbIsPressed = true;
snapTouchPosition();
updateHaloHotspot();

// Update the thumb width when pressed.
if (hasGapBetweenThumbAndTrack()) {
defaultThumbWidth = thumbWidth;
Expand All @@ -2368,8 +2367,11 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {
setThumbWidth(pressedThumbWidth);
setThumbTrackGapSize(thumbTrackGapSize - delta / 2);
}
invalidate();
onStartTrackingTouch();

snapTouchPosition();
updateHaloHotspot();
invalidate();
break;
case MotionEvent.ACTION_MOVE:
if (!thumbIsPressed) {
Expand All @@ -2378,15 +2380,26 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {
return false;
}
getParent().requestDisallowInterceptTouchEvent(true);
onStartTrackingTouch();
}

if (!pickActiveThumb()) {
// Couldn't determine the active thumb yet.
break;
if (!pickActiveThumb()) {
// Couldn't determine the active thumb yet.
break;
}

thumbIsPressed = true;

// Update the thumb width when pressed.
if (hasGapBetweenThumbAndTrack()) {
defaultThumbWidth = thumbWidth;
defaultThumbTrackGapSize = thumbTrackGapSize;
int pressedThumbWidth = Math.round(thumbWidth * THUMB_WIDTH_PRESSED_RATIO);
int delta = thumbWidth - pressedThumbWidth;
setThumbWidth(pressedThumbWidth);
setThumbTrackGapSize(thumbTrackGapSize - delta / 2);
}
onStartTrackingTouch();
}

thumbIsPressed = true;
snapTouchPosition();
updateHaloHotspot();
invalidate();
Expand Down