react-native-gesture-handler 2.21.2 → 2.22.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/android/build.gradle +10 -0
- package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java +3 -2
- package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerDelegate.java +3 -2
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +16 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt +45 -8
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +18 -0
- package/apple/Handlers/RNFlingHandler.m +0 -1
- package/apple/Handlers/RNForceTouchHandler.m +0 -1
- package/apple/Handlers/RNLongPressHandler.m +0 -1
- package/apple/Handlers/RNManualHandler.m +0 -1
- package/apple/Handlers/RNPanHandler.m +0 -3
- package/apple/Handlers/RNPinchHandler.m +0 -1
- package/apple/Handlers/RNRotationHandler.m +0 -1
- package/apple/Handlers/RNTapHandler.m +0 -1
- package/apple/RNGestureHandlerButton.h +1 -0
- package/apple/RNGestureHandlerButton.mm +51 -0
- package/apple/RNGestureHandlerManager.mm +6 -1
- package/apple/RNManualActivationRecognizer.m +1 -0
- package/lib/commonjs/ActionType.js.map +1 -1
- package/lib/commonjs/Directions.js.map +1 -1
- package/lib/commonjs/EnableNewWebImplementation.js +14 -1
- package/lib/commonjs/EnableNewWebImplementation.js.map +1 -1
- package/lib/commonjs/State.js.map +1 -1
- package/lib/commonjs/TouchEventType.js.map +1 -1
- package/lib/commonjs/components/Pressable/Pressable.js +1 -1
- package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
- package/lib/commonjs/components/ReanimatedSwipeable.js.map +1 -1
- package/lib/commonjs/components/Swipeable.js.map +1 -1
- package/lib/commonjs/components/Text.js +61 -0
- package/lib/commonjs/components/Text.js.map +1 -0
- package/lib/commonjs/components/touchables/GenericTouchable.js.map +1 -1
- package/lib/commonjs/getShadowNodeFromRef.js +10 -2
- package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
- package/lib/commonjs/ghQueueMicrotask.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +12 -0
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js +4 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/dropHandlers.js +4 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/dropHandlers.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/index.js +3 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/index.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/useMountReactions.js +48 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/useMountReactions.js.map +1 -0
- package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
- package/lib/commonjs/handlers/utils.js +1 -0
- package/lib/commonjs/handlers/utils.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/jestUtils/jestUtils.js.map +1 -1
- package/lib/commonjs/mountRegistry.js +49 -0
- package/lib/commonjs/mountRegistry.js.map +1 -0
- package/lib/commonjs/web/detectors/ScaleGestureDetector.js.map +1 -1
- package/lib/commonjs/web/handlers/FlingGestureHandler.js +0 -4
- package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/HoverGestureHandler.js +0 -14
- package/lib/commonjs/web/handlers/HoverGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/ManualGestureHandler.js +0 -14
- package/lib/commonjs/web/handlers/ManualGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +3 -5
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js +0 -4
- package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PinchGestureHandler.js +0 -10
- package/lib/commonjs/web/handlers/PinchGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/RotationGestureHandler.js +0 -14
- package/lib/commonjs/web/handlers/RotationGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/TapGestureHandler.js +0 -4
- package/lib/commonjs/web/handlers/TapGestureHandler.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/commonjs/web_hammer/GestureHandler.js.map +1 -1
- package/lib/commonjs/web_hammer/PressGestureHandler.js.map +1 -1
- package/lib/module/ActionType.js.map +1 -1
- package/lib/module/Directions.js.map +1 -1
- package/lib/module/EnableNewWebImplementation.js +14 -1
- package/lib/module/EnableNewWebImplementation.js.map +1 -1
- package/lib/module/State.js.map +1 -1
- package/lib/module/TouchEventType.js.map +1 -1
- package/lib/module/components/Pressable/Pressable.js +1 -1
- package/lib/module/components/Pressable/Pressable.js.map +1 -1
- package/lib/module/components/ReanimatedSwipeable.js.map +1 -1
- package/lib/module/components/Swipeable.js.map +1 -1
- package/lib/module/components/Text.js +44 -0
- package/lib/module/components/Text.js.map +1 -0
- package/lib/module/components/touchables/GenericTouchable.js.map +1 -1
- package/lib/module/getShadowNodeFromRef.js +10 -2
- package/lib/module/getShadowNodeFromRef.js.map +1 -1
- package/lib/module/ghQueueMicrotask.js.map +1 -1
- package/lib/module/handlers/createHandler.js +11 -0
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js +3 -0
- package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/dropHandlers.js +2 -0
- package/lib/module/handlers/gestures/GestureDetector/dropHandlers.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/index.js +2 -0
- package/lib/module/handlers/gestures/GestureDetector/index.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/useMountReactions.js +39 -0
- package/lib/module/handlers/gestures/GestureDetector/useMountReactions.js.map +1 -0
- package/lib/module/handlers/gestures/gesture.js.map +1 -1
- package/lib/module/handlers/utils.js +1 -3
- package/lib/module/handlers/utils.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/jestUtils/jestUtils.js.map +1 -1
- package/lib/module/mountRegistry.js +40 -0
- package/lib/module/mountRegistry.js.map +1 -0
- package/lib/module/web/detectors/ScaleGestureDetector.js.map +1 -1
- package/lib/module/web/handlers/FlingGestureHandler.js +0 -4
- package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/HoverGestureHandler.js +0 -14
- package/lib/module/web/handlers/HoverGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/ManualGestureHandler.js +0 -14
- package/lib/module/web/handlers/ManualGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/NativeViewGestureHandler.js +3 -5
- package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js +0 -4
- package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PinchGestureHandler.js +0 -10
- package/lib/module/web/handlers/PinchGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/RotationGestureHandler.js +0 -14
- package/lib/module/web/handlers/RotationGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/TapGestureHandler.js +0 -4
- package/lib/module/web/handlers/TapGestureHandler.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/module/web_hammer/GestureHandler.js.map +1 -1
- package/lib/module/web_hammer/PressGestureHandler.js.map +1 -1
- package/lib/typescript/ActionType.d.ts +1 -1
- package/lib/typescript/Directions.d.ts +2 -2
- package/lib/typescript/EnableNewWebImplementation.d.ts +6 -0
- package/lib/typescript/State.d.ts +1 -1
- package/lib/typescript/TouchEventType.d.ts +1 -1
- package/lib/typescript/components/GestureButtonsProps.d.ts +2 -2
- package/lib/typescript/components/Text.d.ts +4 -0
- package/lib/typescript/components/touchables/GenericTouchable.d.ts +1 -1
- package/lib/typescript/handlers/GestureHandlerEventPayload.d.ts +2 -2
- package/lib/typescript/handlers/gestures/GestureDetector/useMountReactions.d.ts +2 -0
- package/lib/typescript/handlers/gestures/gesture.d.ts +1 -1
- package/lib/typescript/handlers/utils.d.ts +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/mocks.d.ts +3 -3
- package/lib/typescript/mountRegistry.d.ts +17 -0
- package/lib/typescript/web/handlers/FlingGestureHandler.d.ts +0 -2
- package/lib/typescript/web/handlers/HoverGestureHandler.d.ts +1 -4
- package/lib/typescript/web/handlers/ManualGestureHandler.d.ts +1 -4
- package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +0 -1
- package/lib/typescript/web/handlers/PanGestureHandler.d.ts +0 -2
- package/lib/typescript/web/handlers/PinchGestureHandler.d.ts +1 -2
- package/lib/typescript/web/handlers/RotationGestureHandler.d.ts +1 -3
- package/lib/typescript/web/handlers/TapGestureHandler.d.ts +0 -2
- package/package.json +16 -17
- package/src/ActionType.ts +1 -1
- package/src/Directions.ts +2 -2
- package/src/EnableNewWebImplementation.ts +18 -0
- package/src/State.ts +1 -1
- package/src/TouchEventType.ts +2 -1
- package/src/components/GestureButtonsProps.ts +4 -2
- package/src/components/Pressable/Pressable.tsx +3 -3
- package/src/components/ReanimatedSwipeable.tsx +8 -8
- package/src/components/Swipeable.tsx +4 -4
- package/src/components/Text.tsx +60 -0
- package/src/components/touchables/GenericTouchable.tsx +1 -1
- package/src/getShadowNodeFromRef.ts +8 -2
- package/src/ghQueueMicrotask.ts +2 -2
- package/src/handlers/GestureHandlerEventPayload.ts +2 -2
- package/src/handlers/createHandler.tsx +14 -1
- package/src/handlers/gestureHandlerCommon.ts +3 -3
- package/src/handlers/gestures/GestureDetector/attachHandlers.ts +3 -0
- package/src/handlers/gestures/GestureDetector/dropHandlers.ts +3 -0
- package/src/handlers/gestures/GestureDetector/index.tsx +3 -0
- package/src/handlers/gestures/GestureDetector/useMountReactions.ts +51 -0
- package/src/handlers/gestures/gesture.ts +3 -3
- package/src/handlers/utils.ts +2 -1
- package/src/index.ts +1 -0
- package/src/jestUtils/jestUtils.ts +10 -12
- package/src/mountRegistry.ts +51 -0
- package/src/web/detectors/ScaleGestureDetector.ts +1 -1
- package/src/web/handlers/FlingGestureHandler.ts +0 -4
- package/src/web/handlers/GestureHandler.ts +1 -3
- package/src/web/handlers/HoverGestureHandler.ts +1 -9
- package/src/web/handlers/ManualGestureHandler.ts +1 -9
- package/src/web/handlers/NativeViewGestureHandler.ts +5 -5
- package/src/web/handlers/PanGestureHandler.ts +0 -4
- package/src/web/handlers/PinchGestureHandler.ts +1 -5
- package/src/web/handlers/RotationGestureHandler.ts +1 -9
- package/src/web/handlers/TapGestureHandler.ts +0 -4
- package/src/web/tools/GestureHandlerWebDelegate.ts +4 -4
- package/src/web_hammer/GestureHandler.ts +1 -1
- package/src/web_hammer/PressGestureHandler.ts +7 -4
- package/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +0 -86
|
@@ -23,6 +23,7 @@ import { useWebEventHandlers } from './utils';
|
|
|
23
23
|
import { Wrap, AnimatedWrap } from './Wrap';
|
|
24
24
|
import { useDetectorUpdater } from './useDetectorUpdater';
|
|
25
25
|
import { useViewRefHandler } from './useViewRefHandler';
|
|
26
|
+
import { useMountReactions } from './useMountReactions';
|
|
26
27
|
|
|
27
28
|
function propagateDetectorConfig(
|
|
28
29
|
props: GestureDetectorProps,
|
|
@@ -174,6 +175,8 @@ export const GestureDetector = (props: GestureDetectorProps) => {
|
|
|
174
175
|
}
|
|
175
176
|
}, [props]);
|
|
176
177
|
|
|
178
|
+
useMountReactions(updateAttachedGestures, preparedGesture);
|
|
179
|
+
|
|
177
180
|
if (shouldUseReanimated) {
|
|
178
181
|
return (
|
|
179
182
|
<AnimatedWrap
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { transformIntoHandlerTags } from '../../utils';
|
|
2
|
+
import { MountRegistry } from '../../../mountRegistry';
|
|
3
|
+
import { AttachedGestureState } from './types';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { GestureRef } from '../gesture';
|
|
6
|
+
|
|
7
|
+
function shouldUpdateDetector(
|
|
8
|
+
relation: GestureRef[] | undefined,
|
|
9
|
+
gesture: { handlerTag: number }
|
|
10
|
+
) {
|
|
11
|
+
if (relation === undefined) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (const tag of transformIntoHandlerTags(relation)) {
|
|
16
|
+
if (tag === gesture.handlerTag) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function useMountReactions(
|
|
25
|
+
updateDetector: () => void,
|
|
26
|
+
state: AttachedGestureState
|
|
27
|
+
) {
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
return MountRegistry.addMountListener((gesture) => {
|
|
30
|
+
// At this point the ref in the gesture config should be updated, so we can check if one of the gestures
|
|
31
|
+
// set in a relation with the gesture got mounted. If so, we need to update the detector to propagate
|
|
32
|
+
// the changes to the native side.
|
|
33
|
+
for (const attachedGesture of state.attachedGestures) {
|
|
34
|
+
const blocksHandlers = attachedGesture.config.blocksHandlers;
|
|
35
|
+
const requireToFail = attachedGesture.config.requireToFail;
|
|
36
|
+
const simultaneousWith = attachedGesture.config.simultaneousWith;
|
|
37
|
+
|
|
38
|
+
if (
|
|
39
|
+
shouldUpdateDetector(blocksHandlers, gesture) ||
|
|
40
|
+
shouldUpdateDetector(requireToFail, gesture) ||
|
|
41
|
+
shouldUpdateDetector(simultaneousWith, gesture)
|
|
42
|
+
) {
|
|
43
|
+
updateDetector();
|
|
44
|
+
|
|
45
|
+
// We can safely return here, if any other gestures should be updated, they will be by the above call
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}, [updateDetector, state]);
|
|
51
|
+
}
|
|
@@ -101,7 +101,7 @@ export const CALLBACK_TYPE = {
|
|
|
101
101
|
|
|
102
102
|
// Allow using CALLBACK_TYPE as object and type
|
|
103
103
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
104
|
-
export type CALLBACK_TYPE = typeof CALLBACK_TYPE[keyof typeof CALLBACK_TYPE];
|
|
104
|
+
export type CALLBACK_TYPE = (typeof CALLBACK_TYPE)[keyof typeof CALLBACK_TYPE];
|
|
105
105
|
|
|
106
106
|
export abstract class Gesture {
|
|
107
107
|
/**
|
|
@@ -125,7 +125,7 @@ export abstract class Gesture {
|
|
|
125
125
|
|
|
126
126
|
let nextGestureId = 0;
|
|
127
127
|
export abstract class BaseGesture<
|
|
128
|
-
EventPayloadT extends Record<string, unknown
|
|
128
|
+
EventPayloadT extends Record<string, unknown>,
|
|
129
129
|
> extends Gesture {
|
|
130
130
|
private gestureId = -1;
|
|
131
131
|
public handlerTag = -1;
|
|
@@ -433,7 +433,7 @@ export abstract class BaseGesture<
|
|
|
433
433
|
|
|
434
434
|
export abstract class ContinousBaseGesture<
|
|
435
435
|
EventPayloadT extends Record<string, unknown>,
|
|
436
|
-
EventChangePayloadT extends Record<string, unknown
|
|
436
|
+
EventChangePayloadT extends Record<string, unknown>,
|
|
437
437
|
> extends BaseGesture<EventPayloadT> {
|
|
438
438
|
/**
|
|
439
439
|
* Set the callback that is being called every time the gesture receives an update while it's active.
|
package/src/handlers/utils.ts
CHANGED
|
@@ -36,7 +36,8 @@ export function filterConfig(
|
|
|
36
36
|
}
|
|
37
37
|
return filteredConfig;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
export function transformIntoHandlerTags(handlerIDs: any) {
|
|
40
41
|
handlerIDs = toArray(handlerIDs);
|
|
41
42
|
|
|
42
43
|
if (Platform.OS === 'web') {
|
package/src/index.ts
CHANGED
|
@@ -78,7 +78,7 @@ try {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
type GestureHandlerTestEvent<
|
|
81
|
-
TEventPayload extends Record<string, unknown> = Record<string, unknown
|
|
81
|
+
TEventPayload extends Record<string, unknown> = Record<string, unknown>,
|
|
82
82
|
> = (
|
|
83
83
|
| GestureEvent<TEventPayload>
|
|
84
84
|
| HandlerStateChangeEvent<TEventPayload>
|
|
@@ -454,17 +454,15 @@ type AllHandlers =
|
|
|
454
454
|
// prettier-ignore
|
|
455
455
|
type ClassComponentConstructor<P> = new (props: P) => React.Component<P, any, any>;
|
|
456
456
|
|
|
457
|
-
type ExtractPayloadFromProps<T> =
|
|
458
|
-
infer TPayload
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
? ExtractPayloadFromProps<THandlerProps>
|
|
467
|
-
: Record<string, unknown>;
|
|
457
|
+
type ExtractPayloadFromProps<T> =
|
|
458
|
+
T extends BaseGestureHandlerProps<infer TPayload> ? TPayload : never;
|
|
459
|
+
|
|
460
|
+
type ExtractConfig<T> =
|
|
461
|
+
T extends BaseGesture<infer TGesturePayload>
|
|
462
|
+
? TGesturePayload
|
|
463
|
+
: T extends ClassComponentConstructor<infer THandlerProps>
|
|
464
|
+
? ExtractPayloadFromProps<THandlerProps>
|
|
465
|
+
: Record<string, unknown>;
|
|
468
466
|
|
|
469
467
|
export function fireGestureHandler<THandler extends AllGestures | AllHandlers>(
|
|
470
468
|
componentOrGesture: ReactTestInstance | GestureType,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { GestureType } from './handlers/gestures/gesture';
|
|
2
|
+
|
|
3
|
+
interface ReactComponentWithHandlerTag extends React.Component {
|
|
4
|
+
handlerTag: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type GestureMountListener = (
|
|
8
|
+
gesture: GestureType | ReactComponentWithHandlerTag
|
|
9
|
+
) => void;
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
12
|
+
export class MountRegistry {
|
|
13
|
+
private static mountListeners = new Set<GestureMountListener>();
|
|
14
|
+
private static unmountListeners = new Set<GestureMountListener>();
|
|
15
|
+
|
|
16
|
+
static addMountListener(listener: GestureMountListener): () => void {
|
|
17
|
+
this.mountListeners.add(listener);
|
|
18
|
+
|
|
19
|
+
return () => {
|
|
20
|
+
this.mountListeners.delete(listener);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static addUnmountListener(listener: GestureMountListener): () => void {
|
|
25
|
+
this.unmountListeners.add(listener);
|
|
26
|
+
|
|
27
|
+
return () => {
|
|
28
|
+
this.unmountListeners.delete(listener);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static gestureHandlerWillMount(handler: React.Component) {
|
|
33
|
+
this.mountListeners.forEach((listener) =>
|
|
34
|
+
listener(handler as ReactComponentWithHandlerTag)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static gestureHandlerWillUnmount(handler: React.Component) {
|
|
39
|
+
this.unmountListeners.forEach((listener) =>
|
|
40
|
+
listener(handler as ReactComponentWithHandlerTag)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static gestureWillMount(gesture: GestureType) {
|
|
45
|
+
this.mountListeners.forEach((listener) => listener(gesture));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static gestureWillUnmount(gesture: GestureType) {
|
|
49
|
+
this.unmountListeners.forEach((listener) => listener(gesture));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -29,7 +29,7 @@ export default class ScaleGestureDetector implements ScaleGestureListener {
|
|
|
29
29
|
private spanSlop: number;
|
|
30
30
|
private minSpan: number;
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
constructor(callbacks: ScaleGestureListener) {
|
|
33
33
|
this.onScaleBegin = callbacks.onScaleBegin;
|
|
34
34
|
this.onScale = callbacks.onScale;
|
|
35
35
|
this.onScaleEnd = callbacks.onScaleEnd;
|
|
@@ -26,10 +26,6 @@ export default class FlingGestureHandler extends GestureHandler {
|
|
|
26
26
|
private maxNumberOfPointersSimultaneously = 0;
|
|
27
27
|
private keyPointer = NaN;
|
|
28
28
|
|
|
29
|
-
public init(ref: number, propsRef: React.RefObject<unknown>): void {
|
|
30
|
-
super.init(ref, propsRef);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
29
|
public updateGestureConfig({ enabled = true, ...props }: Config): void {
|
|
34
30
|
super.updateGestureConfig({ enabled: enabled, ...props });
|
|
35
31
|
|
|
@@ -43,9 +43,7 @@ export default abstract class GestureHandler implements IGestureHandler {
|
|
|
43
43
|
|
|
44
44
|
protected delegate: GestureHandlerDelegate<unknown, IGestureHandler>;
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
delegate: GestureHandlerDelegate<unknown, IGestureHandler>
|
|
48
|
-
) {
|
|
46
|
+
constructor(delegate: GestureHandlerDelegate<unknown, IGestureHandler>) {
|
|
49
47
|
this.delegate = delegate;
|
|
50
48
|
}
|
|
51
49
|
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { State } from '../../State';
|
|
2
|
-
import { AdaptedEvent,
|
|
2
|
+
import { AdaptedEvent, StylusData } from '../interfaces';
|
|
3
3
|
import GestureHandlerOrchestrator from '../tools/GestureHandlerOrchestrator';
|
|
4
4
|
import GestureHandler from './GestureHandler';
|
|
5
5
|
|
|
6
6
|
export default class HoverGestureHandler extends GestureHandler {
|
|
7
7
|
private stylusData: StylusData | undefined;
|
|
8
8
|
|
|
9
|
-
public init(ref: number, propsRef: React.RefObject<unknown>) {
|
|
10
|
-
super.init(ref, propsRef);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
9
|
protected transformNativeEvent(): Record<string, unknown> {
|
|
14
10
|
return {
|
|
15
11
|
...super.transformNativeEvent(),
|
|
@@ -17,10 +13,6 @@ export default class HoverGestureHandler extends GestureHandler {
|
|
|
17
13
|
};
|
|
18
14
|
}
|
|
19
15
|
|
|
20
|
-
public updateGestureConfig({ enabled = true, ...props }: Config): void {
|
|
21
|
-
super.updateGestureConfig({ enabled: enabled, ...props });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
16
|
protected onPointerMoveOver(event: AdaptedEvent): void {
|
|
25
17
|
GestureHandlerOrchestrator.getInstance().recordHandlerIfNotPresent(this);
|
|
26
18
|
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import { AdaptedEvent
|
|
1
|
+
import { AdaptedEvent } from '../interfaces';
|
|
2
2
|
import GestureHandler from './GestureHandler';
|
|
3
3
|
|
|
4
4
|
export default class ManualGestureHandler extends GestureHandler {
|
|
5
|
-
public init(ref: number, propsRef: React.RefObject<unknown>) {
|
|
6
|
-
super.init(ref, propsRef);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public updateGestureConfig({ enabled = true, ...props }: Config): void {
|
|
10
|
-
super.updateGestureConfig({ enabled: enabled, ...props });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
5
|
protected onPointerDown(event: AdaptedEvent): void {
|
|
14
6
|
this.tracker.addToTracker(event);
|
|
15
7
|
super.onPointerDown(event);
|
|
@@ -55,10 +55,6 @@ export default class NativeViewGestureHandler extends GestureHandler {
|
|
|
55
55
|
view.style['WebkitTouchCallout'] = 'auto';
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
protected resetConfig(): void {
|
|
59
|
-
super.resetConfig();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
58
|
protected onPointerDown(event: AdaptedEvent): void {
|
|
63
59
|
this.tracker.addToTracker(event);
|
|
64
60
|
super.onPointerDown(event);
|
|
@@ -83,7 +79,11 @@ export default class NativeViewGestureHandler extends GestureHandler {
|
|
|
83
79
|
}
|
|
84
80
|
|
|
85
81
|
this.begin();
|
|
86
|
-
|
|
82
|
+
|
|
83
|
+
const view = this.delegate.getView() as HTMLElement;
|
|
84
|
+
const isRNGHText = view.hasAttribute('rnghtext');
|
|
85
|
+
|
|
86
|
+
if (this.buttonRole || isRNGHText) {
|
|
87
87
|
this.activate();
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -61,10 +61,6 @@ export default class PanGestureHandler extends GestureHandler {
|
|
|
61
61
|
private endWheelTimeout = 0;
|
|
62
62
|
private wheelDevice = WheelDevice.UNDETERMINED;
|
|
63
63
|
|
|
64
|
-
public init(ref: number, propsRef: React.RefObject<unknown>): void {
|
|
65
|
-
super.init(ref, propsRef);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
64
|
public updateGestureConfig({ enabled = true, ...props }: Config): void {
|
|
69
65
|
this.resetConfig();
|
|
70
66
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { State } from '../../State';
|
|
2
2
|
import { DEFAULT_TOUCH_SLOP } from '../constants';
|
|
3
|
-
import { AdaptedEvent
|
|
3
|
+
import { AdaptedEvent } from '../interfaces';
|
|
4
4
|
|
|
5
5
|
import GestureHandler from './GestureHandler';
|
|
6
6
|
import ScaleGestureDetector, {
|
|
@@ -55,10 +55,6 @@ export default class PinchGestureHandler extends GestureHandler {
|
|
|
55
55
|
this.setShouldCancelWhenOutside(false);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
public updateGestureConfig({ enabled = true, ...props }: Config): void {
|
|
59
|
-
super.updateGestureConfig({ enabled: enabled, ...props });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
58
|
protected transformNativeEvent() {
|
|
63
59
|
return {
|
|
64
60
|
focalX: this.scaleGestureDetector.getFocusX(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { State } from '../../State';
|
|
2
|
-
import { AdaptedEvent
|
|
2
|
+
import { AdaptedEvent } from '../interfaces';
|
|
3
3
|
|
|
4
4
|
import GestureHandler from './GestureHandler';
|
|
5
5
|
import RotationGestureDetector, {
|
|
@@ -50,10 +50,6 @@ export default class RotationGestureHandler extends GestureHandler {
|
|
|
50
50
|
this.setShouldCancelWhenOutside(false);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
public updateGestureConfig({ enabled = true, ...props }: Config): void {
|
|
54
|
-
super.updateGestureConfig({ enabled: enabled, ...props });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
53
|
protected transformNativeEvent() {
|
|
58
54
|
return {
|
|
59
55
|
rotation: this.rotation ? this.rotation : 0,
|
|
@@ -158,10 +154,6 @@ export default class RotationGestureHandler extends GestureHandler {
|
|
|
158
154
|
this.begin();
|
|
159
155
|
}
|
|
160
156
|
|
|
161
|
-
public activate(_force?: boolean): void {
|
|
162
|
-
super.activate();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
157
|
protected onReset(): void {
|
|
166
158
|
if (this.currentState === State.ACTIVE) {
|
|
167
159
|
return;
|
|
@@ -31,10 +31,6 @@ export default class TapGestureHandler extends GestureHandler {
|
|
|
31
31
|
|
|
32
32
|
private tapsSoFar = 0;
|
|
33
33
|
|
|
34
|
-
public init(ref: number, propsRef: React.RefObject<unknown>): void {
|
|
35
|
-
super.init(ref, propsRef);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
34
|
public updateGestureConfig({ enabled = true, ...props }: Config): void {
|
|
39
35
|
super.updateGestureConfig({ enabled: enabled, ...props });
|
|
40
36
|
|
|
@@ -135,11 +135,11 @@ export class GestureHandlerWebDelegate
|
|
|
135
135
|
const { userSelect } = this.gestureHandler.getConfig();
|
|
136
136
|
|
|
137
137
|
this.view.style['userSelect'] = isHandlerEnabled
|
|
138
|
-
? userSelect ?? 'none'
|
|
138
|
+
? (userSelect ?? 'none')
|
|
139
139
|
: this.defaultViewStyles.userSelect;
|
|
140
140
|
|
|
141
141
|
this.view.style['webkitUserSelect'] = isHandlerEnabled
|
|
142
|
-
? userSelect ?? 'none'
|
|
142
|
+
? (userSelect ?? 'none')
|
|
143
143
|
: this.defaultViewStyles.userSelect;
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -147,12 +147,12 @@ export class GestureHandlerWebDelegate
|
|
|
147
147
|
const { touchAction } = this.gestureHandler.getConfig();
|
|
148
148
|
|
|
149
149
|
this.view.style['touchAction'] = isHandlerEnabled
|
|
150
|
-
? touchAction ?? 'none'
|
|
150
|
+
? (touchAction ?? 'none')
|
|
151
151
|
: this.defaultViewStyles.touchAction;
|
|
152
152
|
|
|
153
153
|
// @ts-ignore This one disables default events on Safari
|
|
154
154
|
this.view.style['WebkitTouchCallout'] = isHandlerEnabled
|
|
155
|
-
? touchAction ?? 'none'
|
|
155
|
+
? (touchAction ?? 'none')
|
|
156
156
|
: this.defaultViewStyles.touchAction;
|
|
157
157
|
}
|
|
158
158
|
|
|
@@ -538,7 +538,7 @@ abstract class GestureHandler {
|
|
|
538
538
|
'activeOffsetYStart',
|
|
539
539
|
'activeOffsetYEnd',
|
|
540
540
|
] as const;
|
|
541
|
-
configProps.forEach((prop: typeof configProps[number]) => {
|
|
541
|
+
configProps.forEach((prop: (typeof configProps)[number]) => {
|
|
542
542
|
if (typeof props[prop] === 'undefined') {
|
|
543
543
|
props[prop] = Number.NaN;
|
|
544
544
|
}
|
|
@@ -87,10 +87,13 @@ class PressGestureHandler extends DiscreteGestureHandler {
|
|
|
87
87
|
this.isGestureRunning = true;
|
|
88
88
|
clearTimeout(this.visualFeedbackTimer);
|
|
89
89
|
this.initialEvent = ev;
|
|
90
|
-
this.visualFeedbackTimer = fireAfterInterval(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
this.visualFeedbackTimer = fireAfterInterval(
|
|
91
|
+
() => {
|
|
92
|
+
this.sendGestureStartedEvent(this.initialEvent as HammerInputExt);
|
|
93
|
+
this.initialEvent = null;
|
|
94
|
+
},
|
|
95
|
+
this.shouldDelayTouchForEvent(ev) && CONTENT_TOUCHES_DELAY
|
|
96
|
+
);
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
sendGestureStartedEvent(ev: HammerInputExt) {
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
package com.swmansion.gesturehandler
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.TurboReactPackage
|
|
4
|
-
import com.facebook.react.ViewManagerOnDemandReactPackage
|
|
5
|
-
import com.facebook.react.bridge.ModuleSpec
|
|
6
|
-
import com.facebook.react.bridge.NativeModule
|
|
7
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
-
import com.facebook.react.module.annotations.ReactModule
|
|
9
|
-
import com.facebook.react.module.annotations.ReactModuleList
|
|
10
|
-
import com.facebook.react.module.model.ReactModuleInfo
|
|
11
|
-
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
12
|
-
import com.facebook.react.uimanager.ViewManager
|
|
13
|
-
import com.swmansion.gesturehandler.react.RNGestureHandlerButtonViewManager
|
|
14
|
-
import com.swmansion.gesturehandler.react.RNGestureHandlerModule
|
|
15
|
-
import com.swmansion.gesturehandler.react.RNGestureHandlerRootViewManager
|
|
16
|
-
|
|
17
|
-
@ReactModuleList(
|
|
18
|
-
nativeModules = [
|
|
19
|
-
RNGestureHandlerModule::class
|
|
20
|
-
]
|
|
21
|
-
)
|
|
22
|
-
class RNGestureHandlerPackage : TurboReactPackage(), ViewManagerOnDemandReactPackage {
|
|
23
|
-
private val viewManagers: Map<String, ModuleSpec> by lazy {
|
|
24
|
-
mapOf(
|
|
25
|
-
RNGestureHandlerRootViewManager.REACT_CLASS to ModuleSpec.viewManagerSpec {
|
|
26
|
-
RNGestureHandlerRootViewManager()
|
|
27
|
-
},
|
|
28
|
-
RNGestureHandlerButtonViewManager.REACT_CLASS to ModuleSpec.viewManagerSpec {
|
|
29
|
-
RNGestureHandlerButtonViewManager()
|
|
30
|
-
}
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
override fun createViewManagers(reactContext: ReactApplicationContext) =
|
|
35
|
-
listOf<ViewManager<*, *>>(
|
|
36
|
-
RNGestureHandlerRootViewManager(),
|
|
37
|
-
RNGestureHandlerButtonViewManager()
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
override fun getViewManagerNames(reactContext: ReactApplicationContext?) =
|
|
41
|
-
viewManagers.keys.toList()
|
|
42
|
-
|
|
43
|
-
override fun getViewManagers(reactContext: ReactApplicationContext?): MutableList<ModuleSpec> =
|
|
44
|
-
viewManagers.values.toMutableList()
|
|
45
|
-
|
|
46
|
-
override fun createViewManager(
|
|
47
|
-
reactContext: ReactApplicationContext?,
|
|
48
|
-
viewManagerName: String?
|
|
49
|
-
) = viewManagers[viewManagerName]?.provider?.get() as? ViewManager<*, *>
|
|
50
|
-
|
|
51
|
-
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
52
|
-
return if (name == RNGestureHandlerModule.NAME) {
|
|
53
|
-
RNGestureHandlerModule(reactContext)
|
|
54
|
-
} else {
|
|
55
|
-
null
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
60
|
-
try {
|
|
61
|
-
val reactModuleInfoProviderClass =
|
|
62
|
-
Class.forName("com.swmansion.gesturehandler.RNGestureHandlerPackage$\$ReactModuleInfoProvider")
|
|
63
|
-
return reactModuleInfoProviderClass.getDeclaredConstructor().newInstance() as ReactModuleInfoProvider
|
|
64
|
-
} catch (e: ClassNotFoundException) {
|
|
65
|
-
return ReactModuleInfoProvider {
|
|
66
|
-
val reactModule: ReactModule = RNGestureHandlerModule::class.java.getAnnotation(ReactModule::class.java)!!
|
|
67
|
-
|
|
68
|
-
mutableMapOf(
|
|
69
|
-
RNGestureHandlerModule.NAME to ReactModuleInfo(
|
|
70
|
-
reactModule.name,
|
|
71
|
-
RNGestureHandlerModule::class.java.name,
|
|
72
|
-
reactModule.canOverrideExistingModule,
|
|
73
|
-
reactModule.needsEagerInit,
|
|
74
|
-
true, // Has constants is hardcoded to return true, so replacing it with `true` changes nothing.
|
|
75
|
-
reactModule.isCxxModule,
|
|
76
|
-
true
|
|
77
|
-
)
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
} catch (e: InstantiationException) {
|
|
81
|
-
throw RuntimeException("No ReactModuleInfoProvider for RNGestureHandlerPackage$\$ReactModuleInfoProvider", e)
|
|
82
|
-
} catch (e: IllegalAccessException) {
|
|
83
|
-
throw RuntimeException("No ReactModuleInfoProvider for RNGestureHandlerPackage$\$ReactModuleInfoProvider", e)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|