Skip to content

Commit d85b73f

Browse files
pubiqqafohrman
authored andcommitted
[Slider] Fix the handle width when touched in a scrolling container and when more than one handle is in the touch position.
Resolves #4151 Resolves #4149 Resolves #4150 GIT_ORIGIN_REV_ID=d78e6e24416135fa1a21dc6e298902ab6b893490 PiperOrigin-RevId: 635894036
1 parent 8edae9b commit d85b73f

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

lib/java/com/google/android/material/slider/BaseSlider.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,19 +2357,12 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {
23572357

23582358
requestFocus();
23592359
thumbIsPressed = true;
2360+
updateThumbWidthWhenPressed();
2361+
onStartTrackingTouch();
2362+
23602363
snapTouchPosition();
23612364
updateHaloHotspot();
2362-
// Update the thumb width when pressed.
2363-
if (hasGapBetweenThumbAndTrack()) {
2364-
defaultThumbWidth = thumbWidth;
2365-
defaultThumbTrackGapSize = thumbTrackGapSize;
2366-
int pressedThumbWidth = Math.round(thumbWidth * THUMB_WIDTH_PRESSED_RATIO);
2367-
int delta = thumbWidth - pressedThumbWidth;
2368-
setThumbWidth(pressedThumbWidth);
2369-
setThumbTrackGapSize(thumbTrackGapSize - delta / 2);
2370-
}
23712365
invalidate();
2372-
onStartTrackingTouch();
23732366
break;
23742367
case MotionEvent.ACTION_MOVE:
23752368
if (!thumbIsPressed) {
@@ -2378,15 +2371,17 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {
23782371
return false;
23792372
}
23802373
getParent().requestDisallowInterceptTouchEvent(true);
2381-
onStartTrackingTouch();
2382-
}
23832374

2384-
if (!pickActiveThumb()) {
2385-
// Couldn't determine the active thumb yet.
2386-
break;
2375+
if (!pickActiveThumb()) {
2376+
// Couldn't determine the active thumb yet.
2377+
break;
2378+
}
2379+
2380+
thumbIsPressed = true;
2381+
updateThumbWidthWhenPressed();
2382+
onStartTrackingTouch();
23872383
}
23882384

2389-
thumbIsPressed = true;
23902385
snapTouchPosition();
23912386
updateHaloHotspot();
23922387
invalidate();
@@ -2430,6 +2425,18 @@ && abs(lastEvent.getY() - event.getY()) <= scaledTouchSlop) {
24302425
return true;
24312426
}
24322427

2428+
private void updateThumbWidthWhenPressed() {
2429+
// Update thumb width and track gap size when pressed.
2430+
if (hasGapBetweenThumbAndTrack()) {
2431+
defaultThumbWidth = thumbWidth;
2432+
defaultThumbTrackGapSize = thumbTrackGapSize;
2433+
int pressedThumbWidth = Math.round(thumbWidth * THUMB_WIDTH_PRESSED_RATIO);
2434+
int delta = thumbWidth - pressedThumbWidth;
2435+
setThumbWidth(pressedThumbWidth);
2436+
setThumbTrackGapSize(thumbTrackGapSize - delta / 2);
2437+
}
2438+
}
2439+
24332440
private double snapPosition(float position) {
24342441
if (stepSize > 0.0f) {
24352442
int stepCount = (int) ((valueTo - valueFrom) / stepSize);

0 commit comments

Comments
 (0)