Skip to content

Commit 42aed92

Browse files
Fix touch offsets (#422)
Co-authored-by: Michael Blanchard <michael.james.blanchard@gmail.com>
1 parent 2cb8a7b commit 42aed92

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/index.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ export class Slider extends PureComponent<SliderProps, SliderState> {
271271
? nativeEvent.locationX - thumbSize.width
272272
: this._getThumbLeft(this._getCurrentValue(this._activeThumbIndex));
273273

274+
if (this.props.thumbTouchSize) {
275+
this._previousLeft -=
276+
(this.props.thumbTouchSize.width - thumbSize.width) / 2;
277+
}
278+
274279
this.props?.onSlidingStart?.(
275280
this._getRawValues(this.state.values),
276281
this._activeThumbIndex,
@@ -486,7 +491,7 @@ export class Slider extends PureComponent<SliderProps, SliderState> {
486491
if (allMeasured) {
487492
size.width = Math.max(
488493
0,
489-
thumbTouchSize?.width || 0 - thumbSize.width,
494+
thumbTouchSize?.width || 0 + thumbSize.width,
490495
);
491496
size.height = Math.max(
492497
0,
@@ -594,10 +599,10 @@ export class Slider extends PureComponent<SliderProps, SliderState> {
594599
thumbLeft: Animated.AnimatedInterpolation,
595600
index: number,
596601
) => {
597-
const {height, y, width} = this._getThumbTouchRect() || {};
602+
const {height, x, y, width} = this._getThumbTouchRect() || {};
598603
const positionStyle = {
599604
height,
600-
left: thumbLeft,
605+
left: x,
601606
top: y,
602607
width,
603608
};

0 commit comments

Comments
 (0)