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

Fix touch offsets #422

Merged
merged 2 commits into from
Mar 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {PureComponent} from 'react';

Check failure on line 1 in src/index.tsx

View workflow job for this annotation

GitHub Actions / build (14.x)

Parameter 'prevProps' implicitly has an 'any' type.

Check failure on line 1 in src/index.tsx

View workflow job for this annotation

GitHub Actions / build (14.x)

Argument of type 'number | number[] | Value | undefined' is not assignable to parameter of type 'number | number[] | undefined'.

Check failure on line 1 in src/index.tsx

View workflow job for this annotation

GitHub Actions / build (14.x)

Type 'Value[] | undefined' is not assignable to type 'number | number[] | Value | Value[]'.
import {
Animated,
Easing,
Expand Down Expand Up @@ -217,7 +217,7 @@
if (this.props.value !== prevProps.value) {
const newValues = normalizeValue(this.props, this.props.value);

this.setState({

Check warning on line 220 in src/index.tsx

View workflow job for this annotation

GitHub Actions / build (14.x)

Do not use setState in componentDidUpdate
values: updateValues({
values: this.state.values,
newValues: newValues,
Expand Down Expand Up @@ -247,7 +247,7 @@
}
}

_getRawValues(

Check warning on line 250 in src/index.tsx

View workflow job for this annotation

GitHub Actions / build (14.x)

Do not use setState in componentDidUpdate
values: Array<Animated.Value> | Array<Animated.AnimatedInterpolation>,
) {
return values.map((value) => value.__getValue());
Expand All @@ -271,6 +271,11 @@
? 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 @@
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 @@
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
Loading