react-native-gesture-handler 2.6.1 → 2.6.2
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/RNGestureHandlerModule.macos.js +2 -4
- package/lib/commonjs/RNGestureHandlerModule.macos.js.map +1 -1
- package/lib/commonjs/components/GestureComponents.js +6 -4
- package/lib/commonjs/components/GestureComponents.js.map +1 -1
- package/lib/commonjs/components/Swipeable.js +4 -4
- package/lib/commonjs/components/Swipeable.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +4 -2
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/commonjs/utils.js +10 -6
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js +48 -0
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.macos.js +2 -4
- package/lib/module/RNGestureHandlerModule.macos.js.map +1 -1
- package/lib/module/components/GestureComponents.js +6 -4
- package/lib/module/components/GestureComponents.js.map +1 -1
- package/lib/module/components/Swipeable.js +4 -4
- package/lib/module/components/Swipeable.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector.js +5 -3
- package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/module/utils.js +7 -6
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +48 -0
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/typescript/RNGestureHandlerModule.macos.d.ts +1 -1
- package/lib/typescript/components/Swipeable.d.ts +3 -3
- package/lib/typescript/utils.d.ts +4 -0
- package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -0
- package/package.json +1 -1
- package/src/RNGestureHandlerModule.macos.ts +3 -3
- package/src/components/GestureComponents.tsx +12 -16
- package/src/components/Swipeable.tsx +11 -7
- package/src/handlers/gestures/GestureDetector.tsx +8 -3
- package/src/utils.ts +6 -6
- package/src/web/handlers/GestureHandler.ts +59 -0
@@ -1,3 +1,7 @@
|
|
1
|
+
export declare const REACT_NATIVE_VERSION: {
|
2
|
+
major: number;
|
3
|
+
minor: number;
|
4
|
+
};
|
1
5
|
export declare function toArray<T>(object: T | T[]): T[];
|
2
6
|
export declare type withPrevAndCurrentMapFn<T, Transformed> = (previous: Transformed | null, current: T) => Transformed;
|
3
7
|
export declare function withPrevAndCurrent<T, Transformed>(array: T[], mapFn: withPrevAndCurrentMapFn<T, Transformed>): Transformed[];
|
@@ -67,6 +67,7 @@ export default abstract class GestureHandler {
|
|
67
67
|
sendEvent: (newState: State, oldState: State) => void;
|
68
68
|
private transformEventData;
|
69
69
|
private transformTouchEvent;
|
70
|
+
private cancelTouches;
|
70
71
|
protected transformNativeEvent(): {};
|
71
72
|
updateGestureConfig({ enabled, ...props }: Config): void;
|
72
73
|
protected checkCustomActivationCriteria(criterias: string[]): void;
|
package/package.json
CHANGED
@@ -46,11 +46,11 @@ export const HammerGestures = {
|
|
46
46
|
};
|
47
47
|
|
48
48
|
export default {
|
49
|
-
handleSetJSResponder(
|
50
|
-
|
49
|
+
handleSetJSResponder(_tag: number, _blockNativeResponder: boolean) {
|
50
|
+
// NO-OP
|
51
51
|
},
|
52
52
|
handleClearJSResponder() {
|
53
|
-
|
53
|
+
// NO-OP
|
54
54
|
},
|
55
55
|
createGestureHandler<T>(
|
56
56
|
handlerName: keyof typeof Gestures,
|
@@ -57,14 +57,12 @@ export const ScrollView = React.forwardRef<
|
|
57
57
|
waitFor={[...toArray(waitFor ?? []), refreshControlGestureRef]}
|
58
58
|
// @ts-ignore we don't pass `refreshing` prop as we only want to override the ref
|
59
59
|
refreshControl={
|
60
|
-
refreshControl
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
refreshControl
|
67
|
-
)
|
60
|
+
refreshControl
|
61
|
+
? React.cloneElement(refreshControl, {
|
62
|
+
// @ts-ignore for reasons unknown to me, `ref` doesn't exist on the type inferred by TS
|
63
|
+
ref: refreshControlGestureRef,
|
64
|
+
})
|
65
|
+
: undefined
|
68
66
|
}
|
69
67
|
/>
|
70
68
|
);
|
@@ -129,14 +127,12 @@ export const FlatList = React.forwardRef((props, ref) => {
|
|
129
127
|
)}
|
130
128
|
// @ts-ignore we don't pass `refreshing` prop as we only want to override the ref
|
131
129
|
refreshControl={
|
132
|
-
refreshControl
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
refreshControl
|
139
|
-
)
|
130
|
+
refreshControl
|
131
|
+
? React.cloneElement(refreshControl, {
|
132
|
+
// @ts-ignore for reasons unknown to me, `ref` doesn't exist on the type inferred by TS
|
133
|
+
ref: refreshControlGestureRef,
|
134
|
+
})
|
135
|
+
: undefined
|
140
136
|
}
|
141
137
|
/>
|
142
138
|
);
|
@@ -106,12 +106,15 @@ export interface SwipeableProps
|
|
106
106
|
/**
|
107
107
|
* Called when action panel gets open (either right or left).
|
108
108
|
*/
|
109
|
-
onSwipeableOpen?: (direction: 'left' | 'right') => void;
|
109
|
+
onSwipeableOpen?: (direction: 'left' | 'right', swipeable: Swipeable) => void;
|
110
110
|
|
111
111
|
/**
|
112
112
|
* Called when action panel is closed.
|
113
113
|
*/
|
114
|
-
onSwipeableClose?: (
|
114
|
+
onSwipeableClose?: (
|
115
|
+
direction: 'left' | 'right',
|
116
|
+
swipeable: Swipeable
|
117
|
+
) => void;
|
115
118
|
|
116
119
|
/**
|
117
120
|
* @deprecated Use `direction` argument of onSwipeableWillOpen()
|
@@ -161,7 +164,8 @@ export interface SwipeableProps
|
|
161
164
|
* */
|
162
165
|
renderRightActions?: (
|
163
166
|
progressAnimatedValue: Animated.AnimatedInterpolation,
|
164
|
-
dragAnimatedValue: Animated.AnimatedInterpolation
|
167
|
+
dragAnimatedValue: Animated.AnimatedInterpolation,
|
168
|
+
swipeable: Swipeable
|
165
169
|
) => React.ReactNode;
|
166
170
|
|
167
171
|
useNativeAnimations?: boolean;
|
@@ -381,13 +385,13 @@ export default class Swipeable extends Component<
|
|
381
385
|
if (finished) {
|
382
386
|
if (toValue > 0) {
|
383
387
|
this.props.onSwipeableLeftOpen?.();
|
384
|
-
this.props.onSwipeableOpen?.('left');
|
388
|
+
this.props.onSwipeableOpen?.('left', this);
|
385
389
|
} else if (toValue < 0) {
|
386
390
|
this.props.onSwipeableRightOpen?.();
|
387
|
-
this.props.onSwipeableOpen?.('right');
|
391
|
+
this.props.onSwipeableOpen?.('right', this);
|
388
392
|
} else {
|
389
393
|
const closingDirection = fromValue > 0 ? 'left' : 'right';
|
390
|
-
this.props.onSwipeableClose?.(closingDirection);
|
394
|
+
this.props.onSwipeableClose?.(closingDirection, this);
|
391
395
|
}
|
392
396
|
}
|
393
397
|
});
|
@@ -463,7 +467,7 @@ export default class Swipeable extends Component<
|
|
463
467
|
styles.rightActions,
|
464
468
|
{ transform: [{ translateX: this.rightActionTranslate! }] },
|
465
469
|
]}>
|
466
|
-
{renderRightActions(this.showRightAction!, this.transX
|
470
|
+
{renderRightActions(this.showRightAction!, this.transX!, this)}
|
467
471
|
<View
|
468
472
|
onLayout={({ nativeEvent }) =>
|
469
473
|
this.setState({ rightOffset: nativeEvent.layout.x })
|
@@ -35,7 +35,7 @@ import { State } from '../../State';
|
|
35
35
|
import { TouchEventType } from '../../TouchEventType';
|
36
36
|
import { ComposedGesture } from './gestureComposition';
|
37
37
|
import { ActionType } from '../../ActionType';
|
38
|
-
import { isFabric, tagMessage } from '../../utils';
|
38
|
+
import { isFabric, REACT_NATIVE_VERSION, tagMessage } from '../../utils';
|
39
39
|
import { getShadowNodeFromRef } from '../../getShadowNodeFromRef';
|
40
40
|
import { Platform } from 'react-native';
|
41
41
|
import type RNGestureHandlerModuleWeb from '../../RNGestureHandlerModule.web';
|
@@ -539,8 +539,13 @@ function validateDetectorChildren(ref: any) {
|
|
539
539
|
// / \
|
540
540
|
// NativeView NativeView
|
541
541
|
if (__DEV__ && Platform.OS !== 'web') {
|
542
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
543
|
-
const wrapType =
|
542
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
543
|
+
const wrapType =
|
544
|
+
REACT_NATIVE_VERSION.minor > 63 || REACT_NATIVE_VERSION.major > 0
|
545
|
+
? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
546
|
+
ref._reactInternals.elementType
|
547
|
+
: // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
548
|
+
ref._reactInternalFiber.elementType;
|
544
549
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
545
550
|
let instance = RNRenderer.findHostInstance_DEPRECATED(ref)
|
546
551
|
._internalFiberInstanceHandleDEV;
|
package/src/utils.ts
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
import pack from 'react-native/package.json';
|
2
2
|
|
3
|
-
const
|
3
|
+
const [majorStr, minorStr] = pack.version.split('.');
|
4
|
+
export const REACT_NATIVE_VERSION = {
|
5
|
+
major: parseInt(majorStr, 10),
|
6
|
+
minor: parseInt(minorStr, 10),
|
7
|
+
};
|
4
8
|
|
5
9
|
export function toArray<T>(object: T | T[]): T[] {
|
6
10
|
if (!Array.isArray(object)) {
|
@@ -52,12 +56,8 @@ export function isFabric(): boolean {
|
|
52
56
|
}
|
53
57
|
|
54
58
|
export function shouldUseCodegenNativeComponent(): boolean {
|
55
|
-
const [majorStr, minorStr] = rnVersion.split('.');
|
56
|
-
const major = Number.parseInt(majorStr);
|
57
|
-
const minor = Number.parseInt(minorStr);
|
58
|
-
|
59
59
|
// use codegenNativeComponent starting with RN 0.68
|
60
|
-
return minor >= 68 || major > 0;
|
60
|
+
return REACT_NATIVE_VERSION.minor >= 68 || REACT_NATIVE_VERSION.major > 0;
|
61
61
|
}
|
62
62
|
|
63
63
|
export function isRemoteDebuggingEnabled(): boolean {
|
@@ -121,6 +121,15 @@ export default abstract class GestureHandler {
|
|
121
121
|
return;
|
122
122
|
}
|
123
123
|
|
124
|
+
if (
|
125
|
+
this.tracker.getTrackedPointersCount() > 0 &&
|
126
|
+
(newState === State.END ||
|
127
|
+
newState === State.CANCELLED ||
|
128
|
+
newState === State.FAILED)
|
129
|
+
) {
|
130
|
+
this.cancelTouches();
|
131
|
+
}
|
132
|
+
|
124
133
|
const oldState = this.currentState;
|
125
134
|
this.currentState = newState;
|
126
135
|
|
@@ -507,6 +516,56 @@ export default abstract class GestureHandler {
|
|
507
516
|
};
|
508
517
|
}
|
509
518
|
|
519
|
+
private cancelTouches(): void {
|
520
|
+
const rect = this.view.getBoundingClientRect();
|
521
|
+
|
522
|
+
const all: PointerData[] = [];
|
523
|
+
const changed: PointerData[] = [];
|
524
|
+
|
525
|
+
const trackerData = this.tracker.getData();
|
526
|
+
|
527
|
+
if (trackerData.size === 0) {
|
528
|
+
return;
|
529
|
+
}
|
530
|
+
|
531
|
+
trackerData.forEach((element: TrackerElement, key: number): void => {
|
532
|
+
const id: number = this.tracker.getMappedTouchEventId(key);
|
533
|
+
|
534
|
+
all.push({
|
535
|
+
id: id,
|
536
|
+
x: element.lastX - rect.left,
|
537
|
+
y: element.lastY - rect.top,
|
538
|
+
absoluteX: element.lastX,
|
539
|
+
absoluteY: element.lastY,
|
540
|
+
});
|
541
|
+
|
542
|
+
changed.push({
|
543
|
+
id: id,
|
544
|
+
x: element.lastX - rect.left,
|
545
|
+
y: element.lastY - rect.top,
|
546
|
+
absoluteX: element.lastX,
|
547
|
+
absoluteY: element.lastY,
|
548
|
+
});
|
549
|
+
});
|
550
|
+
|
551
|
+
const cancelEvent: ResultTouchEvent = {
|
552
|
+
nativeEvent: {
|
553
|
+
handlerTag: this.handlerTag,
|
554
|
+
state: this.currentState,
|
555
|
+
eventType: TouchEventType.CANCELLED,
|
556
|
+
changedTouches: changed,
|
557
|
+
allTouches: all,
|
558
|
+
numberOfTouches: all.length,
|
559
|
+
},
|
560
|
+
timeStamp: Date.now(),
|
561
|
+
};
|
562
|
+
|
563
|
+
const { onGestureHandlerEvent }: PropsRef = this.propsRef
|
564
|
+
.current as PropsRef;
|
565
|
+
|
566
|
+
invokeNullableMethod(onGestureHandlerEvent, cancelEvent);
|
567
|
+
}
|
568
|
+
|
510
569
|
protected transformNativeEvent() {
|
511
570
|
return {};
|
512
571
|
}
|