react-native-gesture-handler 2.14.0 → 2.15.0
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 -0
- package/RNGestureHandler.podspec +2 -2
- package/android/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java +55 -0
- package/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +64 -4
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +12 -2
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +53 -19
- package/{ios → apple}/Handlers/RNFlingHandler.m +25 -5
- package/{ios → apple}/Handlers/RNForceTouchHandler.m +25 -7
- package/{ios → apple}/Handlers/RNHoverHandler.m +26 -1
- package/{ios → apple}/Handlers/RNLongPressHandler.m +24 -4
- package/{ios → apple}/Handlers/RNManualHandler.m +24 -4
- package/{ios → apple}/Handlers/RNNativeViewHandler.mm +42 -6
- package/{ios → apple}/Handlers/RNPanHandler.m +100 -15
- package/apple/Handlers/RNPinchHandler.m +162 -0
- package/{ios → apple}/Handlers/RNRotationHandler.m +71 -9
- package/{ios → apple}/Handlers/RNTapHandler.m +96 -26
- package/apple/RNGHUIKit.h +27 -0
- package/{ios → apple}/RNGestureHandler.h +3 -3
- package/{ios → apple}/RNGestureHandler.m +31 -5
- package/{ios → apple}/RNGestureHandlerButton.h +4 -1
- package/{ios → apple}/RNGestureHandlerButton.m +12 -4
- package/{ios → apple}/RNGestureHandlerButtonManager.m +4 -2
- package/{ios → apple}/RNGestureHandlerEvents.h +1 -1
- package/{ios → apple}/RNGestureHandlerManager.h +2 -2
- package/{ios → apple}/RNGestureHandlerManager.mm +46 -11
- package/apple/RNGestureHandlerModule.h +17 -0
- package/{ios → apple}/RNGestureHandlerModule.mm +46 -60
- package/{ios → apple}/RNGestureHandlerPointerTracker.h +5 -5
- package/{ios → apple}/RNGestureHandlerPointerTracker.m +19 -14
- package/{ios → apple}/RNGestureHandlerRegistry.h +1 -1
- package/{ios → apple}/RNGestureHandlerRegistry.m +1 -1
- package/{ios → apple}/RNManualActivationRecognizer.h +8 -0
- package/{ios → apple}/RNManualActivationRecognizer.m +27 -7
- package/{ios → apple}/RNRootViewGestureRecognizer.m +72 -4
- package/lib/commonjs/RNGestureHandlerModule.js +5 -18
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/RNGestureHandlerModule.windows.js +10 -102
- package/lib/commonjs/RNGestureHandlerModule.windows.js.map +1 -1
- package/lib/commonjs/components/DrawerLayout.js +2 -0
- package/lib/commonjs/components/DrawerLayout.js.map +1 -1
- package/lib/commonjs/components/gestureHandlerRootHOC.js.map +1 -1
- package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js.map +1 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js +1 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +11 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gesture.js +5 -0
- package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gestureStateManager.js +39 -37
- package/lib/commonjs/handlers/gestures/gestureStateManager.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +13 -0
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
- package/lib/commonjs/web/handlers/FlingGestureHandler.js +8 -6
- package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js +13 -1
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js +8 -6
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js +4 -0
- package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/TapGestureHandler.js +4 -0
- package/lib/commonjs/web/handlers/TapGestureHandler.js.map +1 -1
- package/lib/commonjs/web/interfaces.js +12 -14
- package/lib/commonjs/web/interfaces.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +35 -0
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/commonjs/web/tools/NodeManager.js +3 -2
- package/lib/commonjs/web/tools/NodeManager.js.map +1 -1
- package/lib/commonjs/web/tools/PointerEventManager.js +16 -6
- package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/TouchEventManager.js +0 -1
- package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.js +4 -18
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.windows.js +10 -81
- package/lib/module/RNGestureHandlerModule.windows.js.map +1 -1
- package/lib/module/components/DrawerLayout.js +2 -0
- package/lib/module/components/DrawerLayout.js.map +1 -1
- package/lib/module/components/gestureHandlerRootHOC.js.map +1 -1
- package/lib/module/components/touchables/TouchableWithoutFeedback.js.map +1 -1
- package/lib/module/handlers/gestureHandlerCommon.js +1 -1
- package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector.js +11 -1
- package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/module/handlers/gestures/gesture.js +5 -0
- package/lib/module/handlers/gestures/gesture.js.map +1 -1
- package/lib/module/handlers/gestures/gestureStateManager.js +44 -42
- package/lib/module/handlers/gestures/gestureStateManager.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeRNGestureHandlerModule.js +3 -0
- package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -0
- package/lib/module/web/handlers/FlingGestureHandler.js +8 -6
- package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +14 -2
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/LongPressGestureHandler.js +8 -5
- package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js +4 -0
- package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/TapGestureHandler.js +4 -0
- package/lib/module/web/handlers/TapGestureHandler.js.map +1 -1
- package/lib/module/web/interfaces.js +9 -11
- package/lib/module/web/interfaces.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerWebDelegate.js +34 -0
- package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/module/web/tools/NodeManager.js +3 -2
- package/lib/module/web/tools/NodeManager.js.map +1 -1
- package/lib/module/web/tools/PointerEventManager.js +16 -7
- package/lib/module/web/tools/PointerEventManager.js.map +1 -1
- package/lib/module/web/tools/TouchEventManager.js +1 -2
- package/lib/module/web/tools/TouchEventManager.js.map +1 -1
- package/lib/typescript/RNGestureHandlerModule.d.ts +2 -13
- package/lib/typescript/RNGestureHandlerModule.windows.d.ts +5 -21
- package/lib/typescript/components/DrawerLayout.d.ts +11 -0
- package/lib/typescript/components/gestureHandlerRootHOC.d.ts +1 -1
- package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts +1 -1
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -1
- package/lib/typescript/handlers/PanGestureHandler.d.ts +1 -1
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +4 -1
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts +2 -1
- package/lib/typescript/handlers/gestures/gesture.d.ts +2 -0
- package/lib/typescript/handlers/gestures/gestureStateManager.d.ts +3 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -0
- package/lib/typescript/web/handlers/GestureHandler.d.ts +3 -1
- package/lib/typescript/web/interfaces.d.ts +9 -9
- package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +2 -0
- package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +7 -0
- package/lib/typescript/web/tools/PointerEventManager.d.ts +2 -0
- package/package.json +14 -11
- package/src/RNGestureHandlerModule.ts +4 -49
- package/src/RNGestureHandlerModule.windows.ts +18 -100
- package/src/components/DrawerLayout.tsx +15 -0
- package/src/components/gestureHandlerRootHOC.tsx +1 -3
- package/src/components/touchables/TouchableWithoutFeedback.tsx +3 -3
- package/src/handlers/gestureHandlerCommon.ts +5 -0
- package/src/handlers/gestures/GestureDetector.tsx +16 -2
- package/src/handlers/gestures/gesture.ts +6 -0
- package/src/handlers/gestures/gestureStateManager.ts +42 -40
- package/src/index.ts +1 -0
- package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
- package/src/web/handlers/FlingGestureHandler.ts +9 -5
- package/src/web/handlers/GestureHandler.ts +17 -0
- package/src/web/handlers/LongPressGestureHandler.ts +8 -5
- package/src/web/handlers/PanGestureHandler.ts +4 -0
- package/src/web/handlers/TapGestureHandler.ts +4 -0
- package/src/web/interfaces.ts +10 -10
- package/src/web/tools/GestureHandlerDelegate.ts +3 -0
- package/src/web/tools/GestureHandlerWebDelegate.ts +39 -0
- package/src/web/tools/NodeManager.ts +5 -1
- package/src/web/tools/PointerEventManager.ts +23 -5
- package/src/web/tools/TouchEventManager.ts +0 -2
- package/ios/Handlers/RNPinchHandler.m +0 -95
- package/ios/RNGestureHandlerModule.h +0 -7
- package/lib/commonjs/RNGestureHandlerModule.macos.js +0 -149
- package/lib/commonjs/RNGestureHandlerModule.macos.js.map +0 -1
- package/lib/module/RNGestureHandlerModule.macos.js +0 -110
- package/lib/module/RNGestureHandlerModule.macos.js.map +0 -1
- package/lib/typescript/RNGestureHandlerModule.macos.d.ts +0 -47
- package/src/RNGestureHandlerModule.macos.ts +0 -133
- /package/{ios → apple}/Handlers/RNFlingHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNForceTouchHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNHoverHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNLongPressHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNManualHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNNativeViewHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNPanHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNPinchHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNRotationHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNTapHandler.h +0 -0
- /package/{ios → apple}/RNGHTouchEventType.h +0 -0
- /package/{ios → apple}/RNGestureHandler.xcodeproj/project.pbxproj +0 -0
- /package/{ios → apple}/RNGestureHandler.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
- /package/{ios → apple}/RNGestureHandlerActionType.h +0 -0
- /package/{ios → apple}/RNGestureHandlerButtonComponentView.h +0 -0
- /package/{ios → apple}/RNGestureHandlerButtonComponentView.mm +0 -0
- /package/{ios → apple}/RNGestureHandlerButtonManager.h +0 -0
- /package/{ios → apple}/RNGestureHandlerDirection.h +0 -0
- /package/{ios → apple}/RNGestureHandlerEvents.m +0 -0
- /package/{ios → apple}/RNGestureHandlerRootViewComponentView.mm +0 -0
- /package/{ios → apple}/RNGestureHandlerState.h +0 -0
- /package/{ios → apple}/RNGestureHandlerStateManager.h +0 -0
- /package/{ios → apple}/RNRootViewGestureRecognizer.h +0 -0
|
@@ -18,45 +18,47 @@ const warningMessage = tagMessage(
|
|
|
18
18
|
const REANIMATED_AVAILABLE = Reanimated?.useSharedValue !== undefined;
|
|
19
19
|
const setGestureState = Reanimated?.setGestureState;
|
|
20
20
|
|
|
21
|
+
function create(handlerTag: number): GestureStateManagerType {
|
|
22
|
+
'worklet';
|
|
23
|
+
return {
|
|
24
|
+
begin: () => {
|
|
25
|
+
'worklet';
|
|
26
|
+
if (REANIMATED_AVAILABLE) {
|
|
27
|
+
setGestureState(handlerTag, State.BEGAN);
|
|
28
|
+
} else {
|
|
29
|
+
console.warn(warningMessage);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
activate: () => {
|
|
34
|
+
'worklet';
|
|
35
|
+
if (REANIMATED_AVAILABLE) {
|
|
36
|
+
setGestureState(handlerTag, State.ACTIVE);
|
|
37
|
+
} else {
|
|
38
|
+
console.warn(warningMessage);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
fail: () => {
|
|
43
|
+
'worklet';
|
|
44
|
+
if (REANIMATED_AVAILABLE) {
|
|
45
|
+
setGestureState(handlerTag, State.FAILED);
|
|
46
|
+
} else {
|
|
47
|
+
console.warn(warningMessage);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
end: () => {
|
|
52
|
+
'worklet';
|
|
53
|
+
if (REANIMATED_AVAILABLE) {
|
|
54
|
+
setGestureState(handlerTag, State.END);
|
|
55
|
+
} else {
|
|
56
|
+
console.warn(warningMessage);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
21
62
|
export const GestureStateManager = {
|
|
22
|
-
create
|
|
23
|
-
'worklet';
|
|
24
|
-
return {
|
|
25
|
-
begin: () => {
|
|
26
|
-
'worklet';
|
|
27
|
-
if (REANIMATED_AVAILABLE) {
|
|
28
|
-
setGestureState(handlerTag, State.BEGAN);
|
|
29
|
-
} else {
|
|
30
|
-
console.warn(warningMessage);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
activate: () => {
|
|
35
|
-
'worklet';
|
|
36
|
-
if (REANIMATED_AVAILABLE) {
|
|
37
|
-
setGestureState(handlerTag, State.ACTIVE);
|
|
38
|
-
} else {
|
|
39
|
-
console.warn(warningMessage);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
fail: () => {
|
|
44
|
-
'worklet';
|
|
45
|
-
if (REANIMATED_AVAILABLE) {
|
|
46
|
-
setGestureState(handlerTag, State.FAILED);
|
|
47
|
-
} else {
|
|
48
|
-
console.warn(warningMessage);
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
end: () => {
|
|
53
|
-
'worklet';
|
|
54
|
-
if (REANIMATED_AVAILABLE) {
|
|
55
|
-
setGestureState(handlerTag, State.END);
|
|
56
|
-
} else {
|
|
57
|
-
console.warn(warningMessage);
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
},
|
|
63
|
+
create,
|
|
62
64
|
};
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { initialize } from './init';
|
|
|
2
2
|
|
|
3
3
|
export { Directions } from './Directions';
|
|
4
4
|
export { State } from './State';
|
|
5
|
+
export { MouseButton } from './web/interfaces';
|
|
5
6
|
export { default as gestureHandlerRootHOC } from './components/gestureHandlerRootHOC';
|
|
6
7
|
export { default as GestureHandlerRootView } from './components/GestureHandlerRootView';
|
|
7
8
|
export type {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TurboModuleRegistry, TurboModule } from 'react-native';
|
|
2
|
+
import { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
handleSetJSResponder: (tag: Int32, blockNativeResponder: boolean) => void;
|
|
6
|
+
handleClearJSResponder: () => void;
|
|
7
|
+
createGestureHandler: (
|
|
8
|
+
handlerName: string,
|
|
9
|
+
handlerTag: Int32,
|
|
10
|
+
// Record<> is not supported by codegen
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
12
|
+
config: Object
|
|
13
|
+
) => void;
|
|
14
|
+
attachGestureHandler: (
|
|
15
|
+
handlerTag: Int32,
|
|
16
|
+
newView: Int32,
|
|
17
|
+
actionType: Int32
|
|
18
|
+
) => void;
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
20
|
+
updateGestureHandler: (handlerTag: Int32, newConfig: Object) => void;
|
|
21
|
+
dropGestureHandler: (handlerTag: Int32) => void;
|
|
22
|
+
install: () => boolean;
|
|
23
|
+
flushOperations: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('RNGestureHandlerModule');
|
|
@@ -5,7 +5,7 @@ import { AdaptedEvent, Config } from '../interfaces';
|
|
|
5
5
|
import GestureHandler from './GestureHandler';
|
|
6
6
|
|
|
7
7
|
const DEFAULT_MAX_DURATION_MS = 800;
|
|
8
|
-
const DEFAULT_MIN_ACCEPTABLE_DELTA =
|
|
8
|
+
const DEFAULT_MIN_ACCEPTABLE_DELTA = 32;
|
|
9
9
|
const DEFAULT_DIRECTION = Direction.RIGHT;
|
|
10
10
|
const DEFAULT_NUMBER_OF_TOUCHES_REQUIRED = 1;
|
|
11
11
|
|
|
@@ -83,6 +83,10 @@ export default class FlingGestureHandler extends GestureHandler {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
protected onPointerDown(event: AdaptedEvent): void {
|
|
86
|
+
if (!this.isButtonInConfig(event.button)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
this.tracker.addToTracker(event);
|
|
87
91
|
this.keyPointer = event.pointerId;
|
|
88
92
|
|
|
@@ -141,11 +145,11 @@ export default class FlingGestureHandler extends GestureHandler {
|
|
|
141
145
|
}
|
|
142
146
|
|
|
143
147
|
private onUp(event: AdaptedEvent): void {
|
|
144
|
-
this.
|
|
145
|
-
|
|
146
|
-
return;
|
|
148
|
+
if (this.currentState === State.BEGAN) {
|
|
149
|
+
this.endFling();
|
|
147
150
|
}
|
|
148
|
-
|
|
151
|
+
|
|
152
|
+
this.tracker.removeFromTracker(event.pointerId);
|
|
149
153
|
}
|
|
150
154
|
|
|
151
155
|
public activate(force?: boolean): void {
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
PointerType,
|
|
11
11
|
TouchEventType,
|
|
12
12
|
EventTypes,
|
|
13
|
+
MouseButton,
|
|
13
14
|
} from '../interfaces';
|
|
14
15
|
import EventManager from '../tools/EventManager';
|
|
15
16
|
import GestureHandlerOrchestrator from '../tools/GestureHandlerOrchestrator';
|
|
@@ -117,6 +118,10 @@ export default abstract class GestureHandler {
|
|
|
117
118
|
);
|
|
118
119
|
|
|
119
120
|
this.onStateChange(newState, oldState);
|
|
121
|
+
|
|
122
|
+
if (!this.enabled && this.isFinished()) {
|
|
123
|
+
this.currentState = State.UNDETERMINED;
|
|
124
|
+
}
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
protected onStateChange(_newState: State, _oldState: State): void {}
|
|
@@ -736,8 +741,20 @@ export default abstract class GestureHandler {
|
|
|
736
741
|
return false;
|
|
737
742
|
}
|
|
738
743
|
|
|
744
|
+
public isButtonInConfig(mouseButton: MouseButton | undefined) {
|
|
745
|
+
return (
|
|
746
|
+
!mouseButton ||
|
|
747
|
+
(!this.config.mouseButton && mouseButton === MouseButton.LEFT) ||
|
|
748
|
+
(this.config.mouseButton && mouseButton & this.config.mouseButton)
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
|
|
739
752
|
protected resetConfig(): void {}
|
|
740
753
|
|
|
754
|
+
public onDestroy(): void {
|
|
755
|
+
this.delegate.destroy(this.config);
|
|
756
|
+
}
|
|
757
|
+
|
|
741
758
|
//
|
|
742
759
|
// Getters and setters
|
|
743
760
|
//
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
1
|
import { State } from '../../State';
|
|
3
2
|
import { AdaptedEvent, Config } from '../interfaces';
|
|
4
3
|
|
|
@@ -22,11 +21,11 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
|
22
21
|
private activationTimeout: number | undefined;
|
|
23
22
|
|
|
24
23
|
public init(ref: number, propsRef: React.RefObject<unknown>) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (Platform.OS === 'web') {
|
|
28
|
-
(this.delegate.getView() as HTMLElement).oncontextmenu = () => false;
|
|
24
|
+
if (this.config.enableContextMenu === undefined) {
|
|
25
|
+
this.config.enableContextMenu = false;
|
|
29
26
|
}
|
|
27
|
+
|
|
28
|
+
super.init(ref, propsRef);
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
protected transformNativeEvent() {
|
|
@@ -59,6 +58,10 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
protected onPointerDown(event: AdaptedEvent): void {
|
|
61
|
+
if (!this.isButtonInConfig(event.button)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
62
65
|
this.tracker.addToTracker(event);
|
|
63
66
|
super.onPointerDown(event);
|
|
64
67
|
this.tryBegin(event);
|
|
@@ -211,6 +211,10 @@ export default class PanGestureHandler extends GestureHandler {
|
|
|
211
211
|
|
|
212
212
|
//EventsHandling
|
|
213
213
|
protected onPointerDown(event: AdaptedEvent): void {
|
|
214
|
+
if (!this.isButtonInConfig(event.button)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
214
218
|
this.tracker.addToTracker(event);
|
|
215
219
|
super.onPointerDown(event);
|
|
216
220
|
|
|
@@ -105,6 +105,10 @@ export default class TapGestureHandler extends GestureHandler {
|
|
|
105
105
|
|
|
106
106
|
//Handling Events
|
|
107
107
|
protected onPointerDown(event: AdaptedEvent): void {
|
|
108
|
+
if (!this.isButtonInConfig(event.button)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
108
112
|
this.tracker.addToTracker(event);
|
|
109
113
|
super.onPointerDown(event);
|
|
110
114
|
|
package/src/web/interfaces.ts
CHANGED
|
@@ -37,6 +37,8 @@ export interface Config extends Record<string, ConfigArgs> {
|
|
|
37
37
|
shouldCancelWhenOutside?: boolean;
|
|
38
38
|
userSelect?: UserSelect;
|
|
39
39
|
activeCursor?: ActiveCursor;
|
|
40
|
+
mouseButton?: MouseButton;
|
|
41
|
+
enableContextMenu?: boolean;
|
|
40
42
|
|
|
41
43
|
activateAfterLongPress?: number;
|
|
42
44
|
failOffsetXStart?: number;
|
|
@@ -122,22 +124,20 @@ export interface AdaptedEvent {
|
|
|
122
124
|
pointerId: number;
|
|
123
125
|
eventType: EventTypes;
|
|
124
126
|
pointerType: PointerType;
|
|
125
|
-
buttons: number;
|
|
126
127
|
time: number;
|
|
128
|
+
button?: MouseButton;
|
|
127
129
|
allTouches?: TouchList;
|
|
128
130
|
changedTouches?: TouchList;
|
|
129
131
|
touchEventType?: TouchEventType;
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
export enum
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
RIGHT,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
SCROLL_RIGHT,
|
|
140
|
-
SCROLL_LEFT_RIGHT,
|
|
134
|
+
export enum MouseButton {
|
|
135
|
+
LEFT = 1,
|
|
136
|
+
MIDDLE = 2,
|
|
137
|
+
RIGHT = 4,
|
|
138
|
+
BUTTON_4 = 8,
|
|
139
|
+
BUTTON_5 = 16,
|
|
140
|
+
ALL = 31,
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
export enum EventTypes {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type GestureHandler from '../handlers/GestureHandler';
|
|
2
|
+
import { Config } from '../interfaces';
|
|
2
3
|
|
|
3
4
|
export interface MeasureResult {
|
|
4
5
|
pageX: number;
|
|
@@ -20,4 +21,6 @@ export interface GestureHandlerDelegate<T> {
|
|
|
20
21
|
onEnd(): void;
|
|
21
22
|
onCancel(): void;
|
|
22
23
|
onFail(): void;
|
|
24
|
+
|
|
25
|
+
destroy(config: Config): void;
|
|
23
26
|
}
|
|
@@ -9,6 +9,7 @@ import TouchEventManager from './TouchEventManager';
|
|
|
9
9
|
import { State } from '../../State';
|
|
10
10
|
import { isPointerInBounds } from '../utils';
|
|
11
11
|
import EventManager from './EventManager';
|
|
12
|
+
import { Config, MouseButton } from '../interfaces';
|
|
12
13
|
|
|
13
14
|
export class GestureHandlerWebDelegate
|
|
14
15
|
implements GestureHandlerDelegate<HTMLElement>
|
|
@@ -37,6 +38,8 @@ export class GestureHandlerWebDelegate
|
|
|
37
38
|
|
|
38
39
|
const config = handler.getConfig();
|
|
39
40
|
|
|
41
|
+
this.addContextMenuListeners(config);
|
|
42
|
+
|
|
40
43
|
if (!config.userSelect) {
|
|
41
44
|
this.view.style['webkitUserSelect'] = 'none';
|
|
42
45
|
this.view.style['userSelect'] = 'none';
|
|
@@ -86,6 +89,38 @@ export class GestureHandlerWebDelegate
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
|
|
92
|
+
private shouldDisableContextMenu(config: Config) {
|
|
93
|
+
return (
|
|
94
|
+
(config.enableContextMenu === undefined &&
|
|
95
|
+
this.gestureHandler.isButtonInConfig(MouseButton.RIGHT)) ||
|
|
96
|
+
config.enableContextMenu === false
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private addContextMenuListeners(config: Config): void {
|
|
101
|
+
if (this.shouldDisableContextMenu(config)) {
|
|
102
|
+
this.view.addEventListener('contextmenu', this.disableContextMenu);
|
|
103
|
+
} else if (config.enableContextMenu) {
|
|
104
|
+
this.view.addEventListener('contextmenu', this.enableContextMenu);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private removeContextMenuListeners(config: Config): void {
|
|
109
|
+
if (this.shouldDisableContextMenu(config)) {
|
|
110
|
+
this.view.removeEventListener('contextmenu', this.disableContextMenu);
|
|
111
|
+
} else if (config.enableContextMenu) {
|
|
112
|
+
this.view.removeEventListener('contextmenu', this.enableContextMenu);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private disableContextMenu(this: void, e: MouseEvent): void {
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private enableContextMenu(this: void, e: MouseEvent): void {
|
|
121
|
+
e.stopPropagation();
|
|
122
|
+
}
|
|
123
|
+
|
|
89
124
|
onBegin(): void {
|
|
90
125
|
// no-op for now
|
|
91
126
|
}
|
|
@@ -112,4 +147,8 @@ export class GestureHandlerWebDelegate
|
|
|
112
147
|
onFail(): void {
|
|
113
148
|
this.tryResetCursor();
|
|
114
149
|
}
|
|
150
|
+
|
|
151
|
+
public destroy(config: Config): void {
|
|
152
|
+
this.removeContextMenuListeners(config);
|
|
153
|
+
}
|
|
115
154
|
}
|
|
@@ -21,7 +21,9 @@ export default abstract class NodeManager {
|
|
|
21
21
|
handler: InstanceType<ValueOf<typeof Gestures>>
|
|
22
22
|
): void {
|
|
23
23
|
if (handlerTag in this.gestures) {
|
|
24
|
-
throw new Error(
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Handler with tag ${handlerTag} already exists. Please ensure that no Gesture instance is used across multiple GestureDetectors.`
|
|
26
|
+
);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
this.gestures[handlerTag] = handler;
|
|
@@ -33,6 +35,8 @@ export default abstract class NodeManager {
|
|
|
33
35
|
return;
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
this.gestures[handlerTag].onDestroy();
|
|
39
|
+
|
|
36
40
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
37
41
|
delete this.gestures[handlerTag];
|
|
38
42
|
}
|
|
@@ -1,9 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AdaptedEvent,
|
|
3
|
+
EventTypes,
|
|
4
|
+
MouseButton,
|
|
5
|
+
PointerType,
|
|
6
|
+
} from '../interfaces';
|
|
2
7
|
import EventManager from './EventManager';
|
|
3
8
|
import { isPointerInBounds } from '../utils';
|
|
4
9
|
|
|
10
|
+
const POINTER_CAPTURE_EXCLUDE_LIST = new Set<string>(['SELECT', 'INPUT']);
|
|
11
|
+
|
|
5
12
|
export default class PointerEventManager extends EventManager<HTMLElement> {
|
|
6
13
|
private trackedPointers = new Set<number>();
|
|
14
|
+
private readonly mouseButtonsMapper = new Map<number, MouseButton>();
|
|
15
|
+
|
|
16
|
+
constructor(view: HTMLElement) {
|
|
17
|
+
super(view);
|
|
18
|
+
|
|
19
|
+
this.mouseButtonsMapper.set(0, MouseButton.LEFT);
|
|
20
|
+
this.mouseButtonsMapper.set(1, MouseButton.MIDDLE);
|
|
21
|
+
this.mouseButtonsMapper.set(2, MouseButton.RIGHT);
|
|
22
|
+
this.mouseButtonsMapper.set(3, MouseButton.BUTTON_4);
|
|
23
|
+
this.mouseButtonsMapper.set(4, MouseButton.BUTTON_5);
|
|
24
|
+
}
|
|
7
25
|
|
|
8
26
|
public setListeners(): void {
|
|
9
27
|
this.view.addEventListener('pointerdown', (event: PointerEvent): void => {
|
|
@@ -19,7 +37,7 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
|
|
|
19
37
|
const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.DOWN);
|
|
20
38
|
const target = event.target as HTMLElement;
|
|
21
39
|
|
|
22
|
-
if (target
|
|
40
|
+
if (!POINTER_CAPTURE_EXCLUDE_LIST.has(target.tagName)) {
|
|
23
41
|
target.setPointerCapture(adaptedEvent.pointerId);
|
|
24
42
|
}
|
|
25
43
|
|
|
@@ -50,7 +68,7 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
|
|
|
50
68
|
const adaptedEvent: AdaptedEvent = this.mapEvent(event, EventTypes.UP);
|
|
51
69
|
const target = event.target as HTMLElement;
|
|
52
70
|
|
|
53
|
-
if (target
|
|
71
|
+
if (!POINTER_CAPTURE_EXCLUDE_LIST.has(target.tagName)) {
|
|
54
72
|
target.releasePointerCapture(adaptedEvent.pointerId);
|
|
55
73
|
}
|
|
56
74
|
|
|
@@ -87,7 +105,7 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
|
|
|
87
105
|
// God, I do love web development.
|
|
88
106
|
if (
|
|
89
107
|
!target.hasPointerCapture(event.pointerId) &&
|
|
90
|
-
target
|
|
108
|
+
!POINTER_CAPTURE_EXCLUDE_LIST.has(target.tagName)
|
|
91
109
|
) {
|
|
92
110
|
target.setPointerCapture(event.pointerId);
|
|
93
111
|
}
|
|
@@ -190,7 +208,7 @@ export default class PointerEventManager extends EventManager<HTMLElement> {
|
|
|
190
208
|
pointerId: event.pointerId,
|
|
191
209
|
eventType: eventType,
|
|
192
210
|
pointerType: event.pointerType as PointerType,
|
|
193
|
-
|
|
211
|
+
button: this.mouseButtonsMapper.get(event.button),
|
|
194
212
|
time: event.timeStamp,
|
|
195
213
|
};
|
|
196
214
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AdaptedEvent,
|
|
3
3
|
EventTypes,
|
|
4
|
-
MouseButtons,
|
|
5
4
|
PointerType,
|
|
6
5
|
TouchEventType,
|
|
7
6
|
} from '../interfaces';
|
|
@@ -157,7 +156,6 @@ export default class TouchEventManager extends EventManager<HTMLElement> {
|
|
|
157
156
|
pointerId: event.changedTouches[index].identifier,
|
|
158
157
|
eventType: eventType,
|
|
159
158
|
pointerType: PointerType.TOUCH,
|
|
160
|
-
buttons: MouseButtons.NONE,
|
|
161
159
|
time: event.timeStamp,
|
|
162
160
|
allTouches: event.touches,
|
|
163
161
|
changedTouches: event.changedTouches,
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
// RNPinchHandler.m
|
|
5
|
-
// RNGestureHandler
|
|
6
|
-
//
|
|
7
|
-
// Created by Krzysztof Magiera on 12/10/2017.
|
|
8
|
-
// Copyright © 2017 Software Mansion. All rights reserved.
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
#import "RNPinchHandler.h"
|
|
12
|
-
|
|
13
|
-
#if !TARGET_OS_TV
|
|
14
|
-
@interface RNBetterPinchRecognizer : UIPinchGestureRecognizer
|
|
15
|
-
|
|
16
|
-
- (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler;
|
|
17
|
-
|
|
18
|
-
@end
|
|
19
|
-
|
|
20
|
-
@implementation RNBetterPinchRecognizer {
|
|
21
|
-
__weak RNGestureHandler *_gestureHandler;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
- (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler
|
|
25
|
-
{
|
|
26
|
-
if ((self = [super initWithTarget:self action:@selector(handleGesture:)])) {
|
|
27
|
-
_gestureHandler = gestureHandler;
|
|
28
|
-
}
|
|
29
|
-
return self;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
- (void)handleGesture:(UIGestureRecognizer *)recognizer
|
|
33
|
-
{
|
|
34
|
-
if (self.state == UIGestureRecognizerStateBegan) {
|
|
35
|
-
self.scale = 1;
|
|
36
|
-
}
|
|
37
|
-
[_gestureHandler handleGesture:recognizer];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
|
41
|
-
{
|
|
42
|
-
[super touchesBegan:touches withEvent:event];
|
|
43
|
-
[_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
|
47
|
-
{
|
|
48
|
-
[super touchesMoved:touches withEvent:event];
|
|
49
|
-
[_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
|
53
|
-
{
|
|
54
|
-
[super touchesEnded:touches withEvent:event];
|
|
55
|
-
[_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
|
59
|
-
{
|
|
60
|
-
[super touchesCancelled:touches withEvent:event];
|
|
61
|
-
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
- (void)reset
|
|
65
|
-
{
|
|
66
|
-
[_gestureHandler.pointerTracker reset];
|
|
67
|
-
[super reset];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@end
|
|
71
|
-
#endif
|
|
72
|
-
|
|
73
|
-
@implementation RNPinchGestureHandler
|
|
74
|
-
|
|
75
|
-
- (instancetype)initWithTag:(NSNumber *)tag
|
|
76
|
-
{
|
|
77
|
-
if ((self = [super initWithTag:tag])) {
|
|
78
|
-
#if !TARGET_OS_TV
|
|
79
|
-
_recognizer = [[RNBetterPinchRecognizer alloc] initWithGestureHandler:self];
|
|
80
|
-
#endif
|
|
81
|
-
}
|
|
82
|
-
return self;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
#if !TARGET_OS_TV
|
|
86
|
-
- (RNGestureHandlerEventExtraData *)eventExtraData:(UIPinchGestureRecognizer *)recognizer
|
|
87
|
-
{
|
|
88
|
-
return [RNGestureHandlerEventExtraData forPinch:recognizer.scale
|
|
89
|
-
withFocalPoint:[recognizer locationInView:recognizer.view]
|
|
90
|
-
withVelocity:recognizer.velocity
|
|
91
|
-
withNumberOfTouches:recognizer.numberOfTouches];
|
|
92
|
-
}
|
|
93
|
-
#endif
|
|
94
|
-
|
|
95
|
-
@end
|