@react-native-oh-tpl/react-native-gesture-handler 2.14.8-rc.1 → 2.14.13
Sign up to get free protection for your applications and to get access to all the features.
- package/DrawerLayout/index.ts +2 -2
- package/Swipeable/index.ts +2 -2
- package/harmony/gesture_handler/BuildProfile.ets +17 -0
- package/harmony/gesture_handler/build-profile.json5 +19 -0
- package/harmony/gesture_handler/hvigorfile.ts +2 -0
- package/harmony/gesture_handler/index.ets +3 -0
- package/harmony/gesture_handler/oh-package-lock.json5 +18 -0
- package/harmony/gesture_handler/oh-package.json5 +12 -0
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -0
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +149 -0
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +21 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +36 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +32 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +22 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +15 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +36 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +25 -0
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +27 -0
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +242 -0
- package/harmony/gesture_handler/src/main/ets/core/CircularBuffer.ts +42 -0
- package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +690 -0
- package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +335 -0
- package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +63 -0
- package/harmony/gesture_handler/src/main/ets/core/IncomingEvent.ts +78 -0
- package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +144 -0
- package/harmony/gesture_handler/src/main/ets/core/LeastSquareSolver.ts +182 -0
- package/harmony/gesture_handler/src/main/ets/core/OutgoingEvent.ts +34 -0
- package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +12 -0
- package/harmony/gesture_handler/src/main/ets/core/PointerTracker.ts +239 -0
- package/harmony/gesture_handler/src/main/ets/core/RNGHError.ts +5 -0
- package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +12 -0
- package/harmony/gesture_handler/src/main/ets/core/State.ts +47 -0
- package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +80 -0
- package/harmony/gesture_handler/src/main/ets/core/VelocityTracker.ts +106 -0
- package/harmony/gesture_handler/src/main/ets/core/View.ts +21 -0
- package/harmony/gesture_handler/src/main/ets/core/ViewFinder.ts +11 -0
- package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +8 -0
- package/harmony/gesture_handler/src/main/ets/core/index.ts +15 -0
- package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +169 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +211 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +64 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +127 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +42 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +115 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +342 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +159 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +164 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +206 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +167 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +1 -0
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +24 -0
- package/harmony/gesture_handler/src/main/ets/namespace/components/RNGestureHandlerButton.ts +139 -0
- package/harmony/gesture_handler/src/main/ets/namespace/components/RNGestureHandlerRootView.ts +101 -0
- package/harmony/gesture_handler/src/main/ets/namespace/components/ts.ts +2 -0
- package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +2 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerArkUIAdapter.ts +240 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +22 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +49 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +71 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +98 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +110 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerButton.ets +38 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +233 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerRootView.ets +53 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +24 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +32 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +134 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +97 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/types.ts +25 -0
- package/harmony/gesture_handler/src/main/module.json5 +9 -0
- package/harmony/gesture_handler/src/main/resources/base/element/color.json +8 -0
- package/harmony/gesture_handler/src/main/resources/base/element/string.json +16 -0
- package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
- package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -0
- package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +16 -0
- package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +16 -0
- package/harmony/gesture_handler/ts.ts +2 -0
- package/harmony/gesture_handler.har +0 -0
- package/lib/commonjs/RNGestureHandlerModule.js +3 -2
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js +3 -3
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +18 -15
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/index.js +36 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +2 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +3 -2
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +3 -2
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.js.map +1 -1
- package/lib/module/handlers/createHandler.js +15 -12
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/index.js +5 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
- package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
- package/lib/typescript/handlers/createHandler.d.ts +11 -11
- package/lib/typescript/index.d.ts +47 -42
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
- package/package.json +73 -69
- package/src/RNGestureHandlerModule.ts +4 -4
- package/src/components/GestureHandlerRootView.tsx +23 -23
- package/src/handlers/createHandler.tsx +534 -534
- package/src/index.ts +172 -172
- package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
- package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
- package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
@@ -0,0 +1,127 @@
|
|
1
|
+
import { GestureHandler, IncomingEvent, GestureConfig, State, GestureHandlerDependencies } from '../core';
|
2
|
+
|
3
|
+
const DEFAULT_MIN_DURATION_MS = 500;
|
4
|
+
const DEFAULT_MAX_DIST_DP = 10;
|
5
|
+
const SCALING_FACTOR = 10;
|
6
|
+
|
7
|
+
export class LongPressGestureHandler extends GestureHandler {
|
8
|
+
private minDurationMs = DEFAULT_MIN_DURATION_MS;
|
9
|
+
private defaultMaxDistSq = DEFAULT_MAX_DIST_DP * SCALING_FACTOR;
|
10
|
+
|
11
|
+
private maxDistSq = this.defaultMaxDistSq;
|
12
|
+
private startX = 0;
|
13
|
+
private startY = 0;
|
14
|
+
|
15
|
+
private startTime = 0;
|
16
|
+
private previousTime = 0;
|
17
|
+
|
18
|
+
private activationTimeout: number | undefined;
|
19
|
+
|
20
|
+
constructor(deps: GestureHandlerDependencies) {
|
21
|
+
super({...deps, logger: deps.logger.cloneWithPrefix("LongPressGestureHandler")})
|
22
|
+
}
|
23
|
+
|
24
|
+
public getDefaultConfig() {
|
25
|
+
return {}
|
26
|
+
}
|
27
|
+
|
28
|
+
protected transformNativeEvent() {
|
29
|
+
return {
|
30
|
+
...super.transformNativeEvent(),
|
31
|
+
duration: Date.now() - this.startTime,
|
32
|
+
};
|
33
|
+
}
|
34
|
+
|
35
|
+
public updateGestureConfig({ enabled = true, ...props }: GestureConfig): void {
|
36
|
+
super.updateGestureConfig({ enabled: enabled, ...props });
|
37
|
+
|
38
|
+
if (this.config.minDurationMs !== undefined) {
|
39
|
+
this.minDurationMs = this.config.minDurationMs;
|
40
|
+
}
|
41
|
+
|
42
|
+
if (this.config.maxDist !== undefined) {
|
43
|
+
this.maxDistSq = this.config.maxDist * this.config.maxDist;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
protected resetConfig(): void {
|
50
|
+
super.resetConfig();
|
51
|
+
this.minDurationMs = DEFAULT_MIN_DURATION_MS;
|
52
|
+
this.maxDistSq = this.defaultMaxDistSq;
|
53
|
+
}
|
54
|
+
|
55
|
+
protected onStateChange(newState: State, oldState: State): void {
|
56
|
+
super.onStateChange(newState, oldState)
|
57
|
+
clearTimeout(this.activationTimeout);
|
58
|
+
}
|
59
|
+
|
60
|
+
public onPointerDown(event: IncomingEvent): void {
|
61
|
+
this.tracker.addToTracker(event);
|
62
|
+
super.onPointerDown(event);
|
63
|
+
this.tryBegin(event);
|
64
|
+
this.tryActivate();
|
65
|
+
this.checkDistanceFail(event);
|
66
|
+
}
|
67
|
+
|
68
|
+
public onPointerMove(event: IncomingEvent): void {
|
69
|
+
super.onPointerMove(event);
|
70
|
+
this.tracker.track(event);
|
71
|
+
this.checkDistanceFail(event);
|
72
|
+
}
|
73
|
+
|
74
|
+
public onPointerUp(event: IncomingEvent): void {
|
75
|
+
super.onPointerUp(event);
|
76
|
+
this.tracker.removeFromTracker(event.pointerId);
|
77
|
+
|
78
|
+
if (this.currentState === State.ACTIVE) {
|
79
|
+
this.end();
|
80
|
+
} else {
|
81
|
+
this.fail();
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
private tryBegin(event: IncomingEvent): void {
|
86
|
+
if (this.currentState !== State.UNDETERMINED) {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
|
90
|
+
this.previousTime = Date.now();
|
91
|
+
this.startTime = this.previousTime;
|
92
|
+
|
93
|
+
this.begin();
|
94
|
+
|
95
|
+
this.startX = event.x;
|
96
|
+
this.startY = event.y;
|
97
|
+
}
|
98
|
+
|
99
|
+
private tryActivate(): void {
|
100
|
+
if (this.minDurationMs > 0) {
|
101
|
+
if (this.activationTimeout) {
|
102
|
+
clearTimeout(this.activationTimeout)
|
103
|
+
}
|
104
|
+
this.activationTimeout = setTimeout(() => {
|
105
|
+
this.activate();
|
106
|
+
}, this.minDurationMs);
|
107
|
+
} else if (this.minDurationMs === 0) {
|
108
|
+
this.activate();
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
private checkDistanceFail(event: IncomingEvent): void {
|
113
|
+
const dx = event.x - this.startX;
|
114
|
+
const dy = event.y - this.startY;
|
115
|
+
const distSq = dx * dx + dy * dy;
|
116
|
+
|
117
|
+
if (distSq <= this.maxDistSq) {
|
118
|
+
return;
|
119
|
+
}
|
120
|
+
|
121
|
+
if (this.currentState === State.ACTIVE) {
|
122
|
+
this.cancel();
|
123
|
+
} else {
|
124
|
+
this.fail();
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { GestureHandler, GestureHandlerDependencies, IncomingEvent } from '../core';
|
2
|
+
|
3
|
+
export class ManualGestureHandler extends GestureHandler {
|
4
|
+
constructor(deps: GestureHandlerDependencies) {
|
5
|
+
super({...deps, logger: deps.logger.cloneWithPrefix("ManualGestureHandler")})
|
6
|
+
}
|
7
|
+
|
8
|
+
public getDefaultConfig() {
|
9
|
+
return {}
|
10
|
+
}
|
11
|
+
|
12
|
+
public onPointerDown(event: IncomingEvent): void {
|
13
|
+
this.tracker.addToTracker(event);
|
14
|
+
super.onPointerDown(event);
|
15
|
+
this.begin();
|
16
|
+
}
|
17
|
+
|
18
|
+
public onAdditionalPointerAdd(event: IncomingEvent): void {
|
19
|
+
this.tracker.addToTracker(event);
|
20
|
+
super.onAdditionalPointerAdd(event);
|
21
|
+
}
|
22
|
+
|
23
|
+
public onPointerMove(event: IncomingEvent): void {
|
24
|
+
this.tracker.track(event);
|
25
|
+
super.onPointerMove(event);
|
26
|
+
}
|
27
|
+
|
28
|
+
public onPointerOutOfBounds(event: IncomingEvent): void {
|
29
|
+
this.tracker.track(event);
|
30
|
+
super.onPointerOutOfBounds(event);
|
31
|
+
}
|
32
|
+
|
33
|
+
public onPointerUp(event: IncomingEvent): void {
|
34
|
+
super.onPointerUp(event);
|
35
|
+
this.tracker.removeFromTracker(event.pointerId);
|
36
|
+
}
|
37
|
+
|
38
|
+
public onAdditionalPointerRemove(event: IncomingEvent): void {
|
39
|
+
super.onAdditionalPointerRemove(event);
|
40
|
+
this.tracker.removeFromTracker(event.pointerId);
|
41
|
+
}
|
42
|
+
}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
import { GestureHandler, GestureHandlerDependencies, DEFAULT_TOUCH_SLOP, Vector2D, State, IncomingEvent } from "../core"
|
2
|
+
|
3
|
+
|
4
|
+
export class NativeViewGestureHandler extends GestureHandler {
|
5
|
+
private minDistSq = DEFAULT_TOUCH_SLOP * DEFAULT_TOUCH_SLOP;
|
6
|
+
|
7
|
+
protected startPos = new Vector2D()
|
8
|
+
|
9
|
+
public canBeInterrupted() {
|
10
|
+
return !(this.config.disallowInterruption ?? false)
|
11
|
+
}
|
12
|
+
|
13
|
+
constructor(deps: GestureHandlerDependencies) {
|
14
|
+
super({ ...deps, logger: deps.logger.cloneWithPrefix("NativeViewGestureHandler") })
|
15
|
+
}
|
16
|
+
|
17
|
+
public getDefaultConfig() {
|
18
|
+
return {}
|
19
|
+
}
|
20
|
+
|
21
|
+
public onPointerDown(e: IncomingEvent) {
|
22
|
+
this.tracker.addToTracker(e);
|
23
|
+
super.onPointerDown(e);
|
24
|
+
this.onNewPointer();
|
25
|
+
}
|
26
|
+
|
27
|
+
protected onNewPointer() {
|
28
|
+
this.startPos = this.tracker.getLastAvgPos();
|
29
|
+
if (this.currentState !== State.UNDETERMINED)
|
30
|
+
return;
|
31
|
+
this.begin();
|
32
|
+
if(this.view.hasButtonRole()) {
|
33
|
+
this.activate();
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
public onAdditionalPointerAdd(e: IncomingEvent) {
|
38
|
+
this.tracker.addToTracker(e);
|
39
|
+
super.onPointerDown(e);
|
40
|
+
this.onNewPointer();
|
41
|
+
}
|
42
|
+
|
43
|
+
public onPointerMove(e: IncomingEvent): void {
|
44
|
+
this.tracker.track(e);
|
45
|
+
const {x: dx, y: dy} = this.startPos.clone().subtract(this.tracker.getLastAvgPos()).value
|
46
|
+
const distSq = dx * dx + dy * dy;
|
47
|
+
|
48
|
+
if (distSq >= this.minDistSq) {
|
49
|
+
if (this.view.hasButtonRole() && this.currentState === State.ACTIVE) {
|
50
|
+
this.cancel();
|
51
|
+
} else if (!this.view.hasButtonRole() && this.currentState === State.BEGAN) {
|
52
|
+
this.activate();
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
public onPointerLeave(): void {
|
58
|
+
// TODO: add this method to GestureHandler
|
59
|
+
if (this.currentState === State.BEGAN || this.currentState === State.ACTIVE) {
|
60
|
+
this.cancel();
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
public onPointerUp(event: IncomingEvent): void {
|
65
|
+
super.onPointerUp(event);
|
66
|
+
this.onAnyPointerUp(event);
|
67
|
+
}
|
68
|
+
|
69
|
+
private onAnyPointerUp(e: IncomingEvent) {
|
70
|
+
this.tracker.removeFromTracker(e.pointerId);
|
71
|
+
if (this.tracker.getTrackedPointersCount() === 0) {
|
72
|
+
if (this.currentState === State.ACTIVE) {
|
73
|
+
this.end();
|
74
|
+
} else {
|
75
|
+
this.fail();
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
public onAdditionalPointerRemove(e: IncomingEvent) {
|
81
|
+
super.onAdditionalPointerRemove(e)
|
82
|
+
this.onAnyPointerUp(e)
|
83
|
+
}
|
84
|
+
|
85
|
+
public shouldRecognizeSimultaneously(handler: GestureHandler): boolean {
|
86
|
+
if (super.shouldRecognizeSimultaneously(handler)) {
|
87
|
+
return true;
|
88
|
+
}
|
89
|
+
if (
|
90
|
+
handler instanceof NativeViewGestureHandler &&
|
91
|
+
handler.getState() === State.ACTIVE &&
|
92
|
+
!handler.canBeInterrupted()
|
93
|
+
) {
|
94
|
+
return false;
|
95
|
+
}
|
96
|
+
|
97
|
+
if (
|
98
|
+
this.currentState === State.ACTIVE &&
|
99
|
+
handler.getState() === State.ACTIVE &&
|
100
|
+
this.canBeInterrupted()
|
101
|
+
) {
|
102
|
+
return false;
|
103
|
+
}
|
104
|
+
|
105
|
+
return (
|
106
|
+
this.currentState === State.ACTIVE &&
|
107
|
+
this.canBeInterrupted() &&
|
108
|
+
handler.getTag() > 0
|
109
|
+
);
|
110
|
+
}
|
111
|
+
|
112
|
+
public shouldBeCancelledByOther(_handler: GestureHandler): boolean {
|
113
|
+
return this.canBeInterrupted();
|
114
|
+
}
|
115
|
+
}
|
@@ -0,0 +1,342 @@
|
|
1
|
+
import {
|
2
|
+
GestureHandler,
|
3
|
+
GestureConfig,
|
4
|
+
GestureHandlerDependencies,
|
5
|
+
DEFAULT_TOUCH_SLOP,
|
6
|
+
IncomingEvent,
|
7
|
+
State,
|
8
|
+
Vector2D,
|
9
|
+
getStateName
|
10
|
+
} from "../core"
|
11
|
+
|
12
|
+
|
13
|
+
const DEFAULT_MIN_DIST_SQ = DEFAULT_TOUCH_SLOP * DEFAULT_TOUCH_SLOP;
|
14
|
+
|
15
|
+
type PanGestureHandlerConfig = GestureConfig
|
16
|
+
|
17
|
+
export class PanGestureHandler extends GestureHandler<PanGestureHandlerConfig> {
|
18
|
+
private startPos = new Vector2D();
|
19
|
+
private offset = new Vector2D()
|
20
|
+
private lastPos = new Vector2D();
|
21
|
+
private velocity = new Vector2D();
|
22
|
+
private activationTimeout = 0;
|
23
|
+
|
24
|
+
private get failOffsetXStart() {
|
25
|
+
if (this.config.failOffsetXStart === undefined
|
26
|
+
&& this.config.failOffsetXEnd === undefined)
|
27
|
+
return undefined
|
28
|
+
return this.config.failOffsetXStart ?? Number.MIN_SAFE_INTEGER
|
29
|
+
}
|
30
|
+
|
31
|
+
private get failOffsetXEnd() {
|
32
|
+
if (this.config.failOffsetXStart === undefined
|
33
|
+
&& this.config.failOffsetXEnd === undefined)
|
34
|
+
return undefined
|
35
|
+
return this.config.failOffsetXEnd ?? Number.MAX_SAFE_INTEGER
|
36
|
+
}
|
37
|
+
|
38
|
+
private get failOffsetYStart() {
|
39
|
+
if (this.config.failOffsetYStart === undefined
|
40
|
+
&& this.config.failOffsetYEnd === undefined)
|
41
|
+
return undefined
|
42
|
+
return this.config.failOffsetYStart ?? Number.MIN_SAFE_INTEGER
|
43
|
+
}
|
44
|
+
|
45
|
+
private get failOffsetYEnd() {
|
46
|
+
return this.config.failOffsetYEnd ?? Number.MAX_SAFE_INTEGER
|
47
|
+
}
|
48
|
+
|
49
|
+
private get activeOffsetXStart() {
|
50
|
+
if (this.config.activeOffsetXStart === undefined
|
51
|
+
&& this.config.activeOffsetXEnd === undefined)
|
52
|
+
return undefined
|
53
|
+
return this.config.activeOffsetXStart ?? Number.MIN_SAFE_INTEGER
|
54
|
+
}
|
55
|
+
|
56
|
+
private get activeOffsetXEnd() {
|
57
|
+
if (this.config.activeOffsetXStart === undefined
|
58
|
+
&& this.config.activeOffsetXEnd === undefined)
|
59
|
+
return undefined
|
60
|
+
return this.config.activeOffsetXEnd ?? Number.MAX_SAFE_INTEGER
|
61
|
+
}
|
62
|
+
|
63
|
+
private get activeOffsetYStart() {
|
64
|
+
if (this.config.activeOffsetYStart === undefined
|
65
|
+
&& this.config.activeOffsetYEnd === undefined)
|
66
|
+
return undefined
|
67
|
+
return this.config.activeOffsetYStart ?? Number.MIN_SAFE_INTEGER
|
68
|
+
}
|
69
|
+
|
70
|
+
private get activeOffsetYEnd() {
|
71
|
+
if (this.config.activeOffsetYStart === undefined
|
72
|
+
&& this.config.activeOffsetYEnd === undefined)
|
73
|
+
return undefined
|
74
|
+
return this.config.activeOffsetYEnd ?? Number.MAX_SAFE_INTEGER
|
75
|
+
}
|
76
|
+
|
77
|
+
private get minVelocityX() {
|
78
|
+
return this.config.minVelocityX ?? this.config.minVelocity ?? Number.MAX_SAFE_INTEGER
|
79
|
+
}
|
80
|
+
|
81
|
+
private get minVelocityY() {
|
82
|
+
return this.config.minVelocityY ?? this.config.minVelocityY ?? Number.MAX_SAFE_INTEGER
|
83
|
+
}
|
84
|
+
|
85
|
+
private minVelocitySq = Number.MAX_SAFE_INTEGER
|
86
|
+
|
87
|
+
private get minPointers() {
|
88
|
+
return this.config.minPointers ?? 1
|
89
|
+
}
|
90
|
+
|
91
|
+
private unlockScrolls: (() => void) | undefined
|
92
|
+
private unlockRNGestureResponder: (() => void) | undefined
|
93
|
+
|
94
|
+
public constructor(deps: GestureHandlerDependencies) {
|
95
|
+
super({ ...deps, logger: deps.logger.cloneWithPrefix("PanGestureHandler") })
|
96
|
+
}
|
97
|
+
|
98
|
+
public onPointerDown(e) {
|
99
|
+
this.tracker.addToTracker(e);
|
100
|
+
super.onPointerDown(e);
|
101
|
+
this.lastPos = this.tracker.getLastAvgPos()
|
102
|
+
this.startPos = this.lastPos.clone()
|
103
|
+
this.tryBegin(e);
|
104
|
+
this.tryActivating();
|
105
|
+
}
|
106
|
+
|
107
|
+
private tryActivating(): void {
|
108
|
+
if (this.currentState === State.BEGAN) {
|
109
|
+
if (this.shouldFail()) {
|
110
|
+
this.fail();
|
111
|
+
} else if (this.shouldActivate()) {
|
112
|
+
this.activate();
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
private shouldFail(): boolean {
|
118
|
+
const {x: dx, y: dy} = this.getTranslation().value;
|
119
|
+
const distanceSq = dx * dx + dy * dy;
|
120
|
+
if (this.activateAfterLongPress > 0 && distanceSq > DEFAULT_MIN_DIST_SQ) {
|
121
|
+
this.clearActivationTimeout();
|
122
|
+
return true;
|
123
|
+
}
|
124
|
+
if (this.failOffsetXStart !== Number.MIN_SAFE_INTEGER && dx < this.failOffsetXStart) {
|
125
|
+
return true;
|
126
|
+
}
|
127
|
+
if (this.failOffsetXEnd !== Number.MAX_SAFE_INTEGER && dx > this.failOffsetXEnd) {
|
128
|
+
return true;
|
129
|
+
}
|
130
|
+
if (this.failOffsetYStart !== Number.MIN_SAFE_INTEGER && dy < this.failOffsetYStart) {
|
131
|
+
return true;
|
132
|
+
}
|
133
|
+
return (this.failOffsetYEnd !== Number.MAX_SAFE_INTEGER && dy > this.failOffsetYEnd);
|
134
|
+
}
|
135
|
+
|
136
|
+
private getTranslation() {
|
137
|
+
return this.lastPos.clone().subtract(this.startPos).add(this.offset)
|
138
|
+
}
|
139
|
+
|
140
|
+
private shouldActivate(): boolean {
|
141
|
+
const {x: dx, y: dy} = this.getTranslation().value;
|
142
|
+
if (this.activeOffsetXStart !== Number.MAX_SAFE_INTEGER && dx < this.activeOffsetXStart
|
143
|
+
) {
|
144
|
+
return true;
|
145
|
+
}
|
146
|
+
if (this.activeOffsetXEnd !== Number.MIN_SAFE_INTEGER && dx > this.activeOffsetXEnd) {
|
147
|
+
return true;
|
148
|
+
}
|
149
|
+
if (this.activeOffsetYStart !== Number.MAX_SAFE_INTEGER && dy < this.activeOffsetYStart) {
|
150
|
+
return true;
|
151
|
+
}
|
152
|
+
if (this.activeOffsetYEnd !== Number.MIN_SAFE_INTEGER && dy > this.activeOffsetYEnd) {
|
153
|
+
return true;
|
154
|
+
}
|
155
|
+
const distanceSq: number = dx * dx + dy * dy;
|
156
|
+
if (this.minDistSq !== Number.MAX_SAFE_INTEGER && distanceSq >= this.minDistSq) {
|
157
|
+
return true;
|
158
|
+
}
|
159
|
+
const {x: vx, y: vy} = this.velocity
|
160
|
+
if (
|
161
|
+
this.minVelocityX !== Number.MAX_SAFE_INTEGER &&
|
162
|
+
((this.minVelocityX < 0 && vx <= this.minVelocityX) ||
|
163
|
+
(this.minVelocityX >= 0 && this.minVelocityX <= vx))
|
164
|
+
) {
|
165
|
+
return true;
|
166
|
+
}
|
167
|
+
if (
|
168
|
+
this.minVelocityY !== Number.MAX_SAFE_INTEGER &&
|
169
|
+
((this.minVelocityY < 0 && vy <= this.minVelocityY) ||
|
170
|
+
(this.minVelocityY >= 0 && this.minVelocityY <= vy))
|
171
|
+
) {
|
172
|
+
return true;
|
173
|
+
}
|
174
|
+
const velocitySq: number = vx * vx + vy * vy;
|
175
|
+
return (
|
176
|
+
this.minVelocitySq !== Number.MAX_SAFE_INTEGER &&
|
177
|
+
velocitySq >= this.minVelocitySq
|
178
|
+
);
|
179
|
+
}
|
180
|
+
|
181
|
+
private clearActivationTimeout(): void {
|
182
|
+
clearTimeout(this.activationTimeout);
|
183
|
+
}
|
184
|
+
|
185
|
+
private tryBegin(e: IncomingEvent): void {
|
186
|
+
this.logger.cloneWithPrefix("tryBegin").debug({currentState: getStateName(this.currentState), trackedPointersCount: this.tracker.getTrackedPointersCount(), minPointers: this.minPointers})
|
187
|
+
if (
|
188
|
+
(this.currentState === State.UNDETERMINED) &&
|
189
|
+
this.tracker.getTrackedPointersCount() >= this.minPointers
|
190
|
+
) {
|
191
|
+
this.resetProgress();
|
192
|
+
this.offset = new Vector2D();
|
193
|
+
this.velocity = new Vector2D();
|
194
|
+
|
195
|
+
this.begin();
|
196
|
+
|
197
|
+
if (this.activateAfterLongPress > 0) {
|
198
|
+
this.activationTimeout = setTimeout(() => {
|
199
|
+
this.activate();
|
200
|
+
}, this.activateAfterLongPress);
|
201
|
+
}
|
202
|
+
} else {
|
203
|
+
this.velocity = this.tracker.getVelocity(e.pointerId)
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
public getDefaultConfig() {
|
208
|
+
return {}
|
209
|
+
}
|
210
|
+
|
211
|
+
private get activateAfterLongPress() {
|
212
|
+
return this.config.activateAfterLongPress ?? 0
|
213
|
+
}
|
214
|
+
|
215
|
+
private get minDistSq() {
|
216
|
+
if (this.config.minDist !== undefined) {
|
217
|
+
return this.config.minDist * this.config.minDist;
|
218
|
+
} else if (this.hasCustomActivationCriteria()) {
|
219
|
+
return Number.MAX_SAFE_INTEGER;
|
220
|
+
}
|
221
|
+
return DEFAULT_MIN_DIST_SQ
|
222
|
+
}
|
223
|
+
|
224
|
+
private hasCustomActivationCriteria() {
|
225
|
+
const criterias: (keyof PanGestureHandlerConfig)[] = [
|
226
|
+
'activeOffsetXStart',
|
227
|
+
'activeOffsetXEnd',
|
228
|
+
'failOffsetXStart',
|
229
|
+
'failOffsetXEnd',
|
230
|
+
'activeOffsetYStart',
|
231
|
+
'activeOffsetYEnd',
|
232
|
+
'failOffsetYStart',
|
233
|
+
'failOffsetYEnd',
|
234
|
+
'minVelocityX',
|
235
|
+
'minVelocityY',
|
236
|
+
]
|
237
|
+
for (const key in this.config) {
|
238
|
+
if (criterias.indexOf(key as keyof PanGestureHandlerConfig) >= 0) {
|
239
|
+
return true
|
240
|
+
}
|
241
|
+
}
|
242
|
+
return false
|
243
|
+
}
|
244
|
+
|
245
|
+
public onAdditionalPointerAdd(event: IncomingEvent): void {
|
246
|
+
this.tracker.addToTracker(event);
|
247
|
+
super.onAdditionalPointerAdd(event);
|
248
|
+
this.tryBegin(event);
|
249
|
+
this.offset.add(this.lastPos).subtract(this.startPos)
|
250
|
+
this.lastPos = this.tracker.getLastAvgPos()
|
251
|
+
this.startPos = this.lastPos.clone()
|
252
|
+
if (this.tracker.getTrackedPointersCount() > (this.config.maxPointers ?? 10)) {
|
253
|
+
if (this.currentState === State.ACTIVE) {
|
254
|
+
this.cancel();
|
255
|
+
} else {
|
256
|
+
this.fail();
|
257
|
+
}
|
258
|
+
} else {
|
259
|
+
this.tryActivating();
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
public onPointerUp(event: IncomingEvent): void {
|
264
|
+
super.onPointerUp(event);
|
265
|
+
if (this.currentState === State.ACTIVE) {
|
266
|
+
this.lastPos = this.tracker.getLastAvgPos();
|
267
|
+
}
|
268
|
+
this.tracker.removeFromTracker(event.pointerId);
|
269
|
+
if (this.currentState === State.ACTIVE) {
|
270
|
+
this.end();
|
271
|
+
} else {
|
272
|
+
this.resetProgress();
|
273
|
+
this.fail();
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
public onAdditionalPointerRemove(event: IncomingEvent): void {
|
278
|
+
super.onAdditionalPointerRemove(event);
|
279
|
+
this.tracker.removeFromTracker(event.pointerId);
|
280
|
+
this.offset.add(this.lastPos).subtract(this.startPos)
|
281
|
+
this.lastPos = this.tracker.getLastAvgPos()
|
282
|
+
this.startPos = this.lastPos.clone()
|
283
|
+
if (
|
284
|
+
!(
|
285
|
+
this.currentState === State.ACTIVE &&
|
286
|
+
this.tracker.getTrackedPointersCount() < this.minPointers
|
287
|
+
)
|
288
|
+
) {
|
289
|
+
this.tryActivating();
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
public onPointerMove(event: IncomingEvent): void {
|
294
|
+
this.tracker.track(event);
|
295
|
+
this.lastPos = this.tracker.getLastAvgPos()
|
296
|
+
this.velocity = this.tracker.getVelocity(event.pointerId)
|
297
|
+
this.tryActivating();
|
298
|
+
super.onPointerMove(event);
|
299
|
+
}
|
300
|
+
|
301
|
+
public onPointerOutOfBounds(event: IncomingEvent): void {
|
302
|
+
if (this.shouldCancelWhenOutside) {
|
303
|
+
return;
|
304
|
+
}
|
305
|
+
this.tracker.track(event);
|
306
|
+
this.lastPos = this.tracker.getLastAvgPos()
|
307
|
+
this.velocity = this.tracker.getVelocity(event.pointerId)
|
308
|
+
this.tryActivating();
|
309
|
+
if (this.currentState === State.ACTIVE) {
|
310
|
+
super.onPointerOutOfBounds(event);
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
protected transformNativeEvent() {
|
315
|
+
const rect = this.view.getBoundingRect();
|
316
|
+
const translation = this.getTranslation()
|
317
|
+
return {
|
318
|
+
translationX: translation.x,
|
319
|
+
translationY: translation.y,
|
320
|
+
absoluteX: this.tracker.getLastAvgX(),
|
321
|
+
absoluteY: this.tracker.getLastAvgY(),
|
322
|
+
velocityX: this.velocity.x,
|
323
|
+
velocityY: this.velocity.y,
|
324
|
+
x: this.tracker.getLastAvgX() - rect.x,
|
325
|
+
y: this.tracker.getLastAvgY() - rect.y,
|
326
|
+
};
|
327
|
+
}
|
328
|
+
|
329
|
+
protected onStateChange(newState: State, oldState: State) {
|
330
|
+
super.onStateChange(newState, oldState)
|
331
|
+
if (newState === State.BEGAN) {
|
332
|
+
this.unlockScrolls = this.scrollLocker.lockScrollContainingViewTag(this.view.getTag())
|
333
|
+
} else if (newState !== State.ACTIVE) {
|
334
|
+
this.unlockScrolls?.()
|
335
|
+
}
|
336
|
+
if (newState === State.ACTIVE) {
|
337
|
+
this.unlockRNGestureResponder = this.rnGestureResponder.lock(this.view.getTag())
|
338
|
+
} else {
|
339
|
+
this.unlockRNGestureResponder?.()
|
340
|
+
}
|
341
|
+
}
|
342
|
+
}
|