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