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

Minor TS changes #2872

Merged
merged 5 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions src/handlers/PanGestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export interface PanGestureHandlerProps
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
*/
activeOffsetY?: number | number[];
activeOffsetY?:
| number
| [activeOffsetYStart: number, activeOffsetYEnd: number];
j-piasecki marked this conversation as resolved.
Show resolved Hide resolved

/**
* Range along X axis (in points) where fingers travels without activation of
Expand All @@ -160,7 +162,9 @@ export interface PanGestureHandlerProps
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
*/
activeOffsetX?: number | number[];
activeOffsetX?:
| number
| [activeOffsetXStart: number, activeOffsetXEnd: number];

/**
* When the finger moves outside this range (in points) along Y axis and
Expand All @@ -170,7 +174,7 @@ export interface PanGestureHandlerProps
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
*/
failOffsetY?: number | number[];
failOffsetY?: number | [failOffsetYStart: number, failOffsetYEnd: number];

/**
* When the finger moves outside this range (in points) along X axis and
Expand All @@ -180,7 +184,7 @@ export interface PanGestureHandlerProps
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
*/
failOffsetX?: number | number[];
failOffsetX?: number | [failOffsetXStart: number, failOffsetXEnd: number];
}

export const panHandlerName = 'PanGestureHandler';
Expand Down
16 changes: 12 additions & 4 deletions src/handlers/gestures/panGesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export class PanGesture extends ContinousBaseGesture<
this.handlerName = 'PanGestureHandler';
}

activeOffsetY(offset: number | number[]) {
activeOffsetY(
offset: number | [activeOffsetYStart: number, activeOffsetYEnd: number]
) {
if (Array.isArray(offset)) {
this.config.activeOffsetYStart = offset[0];
this.config.activeOffsetYEnd = offset[1];
Expand All @@ -55,7 +57,9 @@ export class PanGesture extends ContinousBaseGesture<
return this;
}

activeOffsetX(offset: number | number[]) {
activeOffsetX(
offset: number | [activeOffsetXStart: number, activeOffsetXEnd: number]
) {
if (Array.isArray(offset)) {
this.config.activeOffsetXStart = offset[0];
this.config.activeOffsetXEnd = offset[1];
Expand All @@ -67,7 +71,9 @@ export class PanGesture extends ContinousBaseGesture<
return this;
}

failOffsetY(offset: number | number[]) {
failOffsetY(
offset: number | [failOffsetYStart: number, failOffsetYEnd: number]
) {
if (Array.isArray(offset)) {
this.config.failOffsetYStart = offset[0];
this.config.failOffsetYEnd = offset[1];
Expand All @@ -79,7 +85,9 @@ export class PanGesture extends ContinousBaseGesture<
return this;
}

failOffsetX(offset: number | number[]) {
failOffsetX(
offset: number | [failOffsetXStart: number, failOffsetXEnd: number]
) {
if (Array.isArray(offset)) {
this.config.failOffsetXStart = offset[0];
this.config.failOffsetXEnd = offset[1];
Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export function withPrevAndCurrent<T, Transformed>(
const currentArr = [...array];
const transformedArr: Transformed[] = [];
currentArr.forEach((current, i) => {
const previous = previousArr[i];
// This type cast is fine and solves problem mentioned in https://github.com/software-mansion/react-native-gesture-handler/pull/2867 (namely that `previous` can be undefined).
// Unfortunately, linter on our CI does not allow this type of casting as it is unnecessary. To bypass that we use eslint-disable.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const previous = previousArr[i] as Transformed | null;
const transformed = mapFn(previous, current);
previousArr.push(transformed);
transformedArr.push(transformed);
Expand Down
Loading