Skip to content

Commit

Permalink
Fix touch offsets (#422)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Blanchard <[email protected]>
  • Loading branch information
elliottkember and miblanchard authored Mar 24, 2024
1 parent 2cb8a7b commit 42aed92
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ export class Slider extends PureComponent<SliderProps, SliderState> {
? nativeEvent.locationX - thumbSize.width
: this._getThumbLeft(this._getCurrentValue(this._activeThumbIndex));

if (this.props.thumbTouchSize) {
this._previousLeft -=
(this.props.thumbTouchSize.width - thumbSize.width) / 2;
}

this.props?.onSlidingStart?.(
this._getRawValues(this.state.values),
this._activeThumbIndex,
Expand Down Expand Up @@ -486,7 +491,7 @@ export class Slider extends PureComponent<SliderProps, SliderState> {
if (allMeasured) {
size.width = Math.max(
0,
thumbTouchSize?.width || 0 - thumbSize.width,
thumbTouchSize?.width || 0 + thumbSize.width,
);
size.height = Math.max(
0,
Expand Down Expand Up @@ -594,10 +599,10 @@ export class Slider extends PureComponent<SliderProps, SliderState> {
thumbLeft: Animated.AnimatedInterpolation,
index: number,
) => {
const {height, y, width} = this._getThumbTouchRect() || {};
const {height, x, y, width} = this._getThumbTouchRect() || {};
const positionStyle = {
height,
left: thumbLeft,
left: x,
top: y,
width,
};
Expand Down

0 comments on commit 42aed92

Please sign in to comment.