@react-native-oh-tpl/react-native-gesture-handler 2.12.9 → 2.14.1-2.14.12
Sign up to get free protection for your applications and to get access to all the features.
- package/DrawerLayout/index.ts +2 -0
- package/Swipeable/index.ts +2 -0
- package/harmony/gesture_handler/BuildProfile.ets +15 -3
- package/harmony/gesture_handler/hvigorfile.ts +1 -1
- package/harmony/gesture_handler/index.ets +2 -2
- package/harmony/gesture_handler/oh-package-lock.json5 +4 -3
- package/harmony/gesture_handler/oh-package.json5 +4 -4
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +64 -18
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +3 -3
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +2 -2
- package/harmony/gesture_handler/src/main/cpp/{RNGestureHandlerButtonComponentInstance.h → componentInstances/RNGestureHandlerButtonComponentInstance.h} +2 -2
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +242 -0
- package/harmony/gesture_handler/src/main/ets/{GestureHandler.ts → core/GestureHandler.ts} +46 -25
- package/harmony/gesture_handler/src/main/ets/{GestureHandlerOrchestrator.ts → core/GestureHandlerOrchestrator.ts} +122 -67
- package/harmony/gesture_handler/src/main/ets/{GestureHandlerRegistry.ts → core/GestureHandlerRegistry.ts} +7 -0
- package/harmony/gesture_handler/src/main/ets/{Event.ts → core/IncomingEvent.ts} +30 -20
- package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +144 -0
- package/harmony/gesture_handler/src/main/ets/{OutgoingEvent.ts → core/OutgoingEvent.ts} +1 -1
- package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +12 -0
- package/harmony/gesture_handler/src/main/ets/{PointerTracker.ts → core/PointerTracker.ts} +4 -4
- package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +12 -0
- package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +80 -0
- package/harmony/gesture_handler/src/main/ets/{VelocityTracker.ts → core/VelocityTracker.ts} +13 -5
- package/harmony/gesture_handler/src/main/ets/core/View.ts +21 -0
- package/harmony/gesture_handler/src/main/ets/core/index.ts +13 -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/{NativeViewGestureHandler.ts → gesture-handlers/NativeViewGestureHandler.ts} +15 -15
- package/harmony/gesture_handler/src/main/ets/{PanGestureHandler.ts → gesture-handlers/PanGestureHandler.ts} +27 -13
- 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/{TapGestureHandler.ts → gesture-handlers/TapGestureHandler.ts} +11 -11
- 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 +8 -9
- package/harmony/gesture_handler/src/main/ets/namespace/{RNGestureHandlerButton.ts → components/RNGestureHandlerButton.ts} +35 -36
- package/harmony/gesture_handler/src/main/ets/namespace/{RNGestureHandlerRootView.ts → components/RNGestureHandlerRootView.ts} +23 -23
- package/harmony/gesture_handler/src/main/ets/namespace/components/ts.ts +2 -0
- package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +2 -3
- package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerArkUIAdapter.ts +240 -0
- package/harmony/gesture_handler/src/main/ets/{GestureHandlerPackage.ts → rnoh/GestureHandlerPackage.ts} +4 -4
- 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 +108 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +110 -0
- package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerButton.ets → rnoh/RNGestureHandlerButton.ets} +3 -3
- package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerModule.ts → rnoh/RNGestureHandlerModule.ts} +76 -27
- package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerRootView.ets → rnoh/RNGestureHandlerRootView.ets} +3 -3
- 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 +95 -0
- package/harmony/gesture_handler/src/main/module.json5 +8 -6
- package/harmony/gesture_handler/ts.ts +2 -2
- package/harmony/gesture_handler.har +0 -0
- package/lib/commonjs/index.js +126 -141
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +13 -146
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +39 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +13 -10
- package/src/index.ts +140 -140
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +0 -72
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +0 -78
- package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +0 -53
- package/harmony/gesture_handler/src/main/ets/GestureHandlerArkUIAdapter.ts +0 -203
- package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +0 -45
- package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +0 -109
- package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +0 -48
- package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerArkTS.ts +0 -60
- package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +0 -87
- package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +0 -23
- package/harmony/gesture_handler/src/main/ets/Vector2D.ts +0 -36
- package/harmony/gesture_handler/src/main/ets/View.ts +0 -71
- package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +0 -43
- package/harmony/gesture_handler/src/main/ets/pages/Index.ets +0 -17
- package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +0 -41
- /package/harmony/gesture_handler/src/main/ets/{CircularBuffer.ts → core/CircularBuffer.ts} +0 -0
- /package/harmony/gesture_handler/src/main/ets/{LeastSquareSolver.ts → core/LeastSquareSolver.ts} +0 -0
- /package/harmony/gesture_handler/src/main/ets/{RNGHError.ts → core/RNGHError.ts} +0 -0
- /package/harmony/gesture_handler/src/main/ets/{State.ts → core/State.ts} +0 -0
- /package/harmony/gesture_handler/src/main/ets/{types.ts → rnoh/types.ts} +0 -0
@@ -0,0 +1,211 @@
|
|
1
|
+
import {
|
2
|
+
GestureHandler,
|
3
|
+
State,
|
4
|
+
DiagonalDirections,
|
5
|
+
Directions,
|
6
|
+
Vector2D,
|
7
|
+
IncomingEvent,
|
8
|
+
GestureHandlerDependencies
|
9
|
+
} from '../core';
|
10
|
+
|
11
|
+
const DEFAULT_MAX_DURATION_MS = 800;
|
12
|
+
const DEFAULT_MIN_VELOCITY = 700;
|
13
|
+
/**
|
14
|
+
* DEFAULT_ALIGNMENT_CONE defines the angular tolerance for fling gestures in degrees.
|
15
|
+
* *
|
16
|
+
* *
|
17
|
+
* *
|
18
|
+
* *------------>
|
19
|
+
* *
|
20
|
+
* *
|
21
|
+
* *
|
22
|
+
*/
|
23
|
+
const DEFAULT_ALIGNMENT_CONE = 30;
|
24
|
+
const DEFAULT_DIRECTION: Directions = Directions.RIGHT;
|
25
|
+
const DEFAULT_NUMBER_OF_TOUCHES_REQUIRED = 1;
|
26
|
+
const AXIAL_DEVIATION_COSINE = coneToDeviation(DEFAULT_ALIGNMENT_CONE);
|
27
|
+
const DIAGONAL_DEVIATION_COSINE = coneToDeviation(90 - DEFAULT_ALIGNMENT_CONE);
|
28
|
+
|
29
|
+
export class FlingGestureHandler extends GestureHandler {
|
30
|
+
constructor(deps: GestureHandlerDependencies) {
|
31
|
+
super({ ...deps, logger: deps.logger.cloneWithPrefix("FlingGestureHandler") })
|
32
|
+
}
|
33
|
+
|
34
|
+
getDefaultConfig() {
|
35
|
+
return {}
|
36
|
+
}
|
37
|
+
|
38
|
+
private get direction(): Directions {
|
39
|
+
return this.config.direction ?? DEFAULT_DIRECTION
|
40
|
+
}
|
41
|
+
|
42
|
+
private get numberOfPointersRequired() {
|
43
|
+
return this.config.numberOfPointers ?? DEFAULT_NUMBER_OF_TOUCHES_REQUIRED
|
44
|
+
}
|
45
|
+
|
46
|
+
private get maxDurationMs() {
|
47
|
+
return this.config.maxDurationMs ?? DEFAULT_MAX_DURATION_MS
|
48
|
+
}
|
49
|
+
|
50
|
+
private get minVelocity() {
|
51
|
+
return this.config.minVelocity ?? DEFAULT_MIN_VELOCITY
|
52
|
+
}
|
53
|
+
|
54
|
+
private delayTimeout!: number;
|
55
|
+
private maxNumberOfPointersSimultaneously = 0;
|
56
|
+
private keyPointer = NaN;
|
57
|
+
|
58
|
+
private startFling(): void {
|
59
|
+
this.logger.info("startFling")
|
60
|
+
this.begin();
|
61
|
+
|
62
|
+
this.maxNumberOfPointersSimultaneously = 1;
|
63
|
+
|
64
|
+
this.delayTimeout = setTimeout(() => this.fail(), this.maxDurationMs);
|
65
|
+
}
|
66
|
+
|
67
|
+
private tryEndFling(): boolean {
|
68
|
+
const logger = this.logger.cloneWithPrefix("tryEndFling")
|
69
|
+
const velocityVector = this.tracker.getVelocity(this.keyPointer);
|
70
|
+
|
71
|
+
const getAlignment = (
|
72
|
+
direction: Directions | DiagonalDirections,
|
73
|
+
minimalAlignmentCosine: number
|
74
|
+
) => {
|
75
|
+
return (
|
76
|
+
(direction & this.direction) === direction &&
|
77
|
+
velocityVector.computeCosine(
|
78
|
+
Vector2D.fromDirection(direction),
|
79
|
+
) > minimalAlignmentCosine
|
80
|
+
);
|
81
|
+
};
|
82
|
+
|
83
|
+
const axialDirectionsList = Object.values(Directions);
|
84
|
+
const diagonalDirectionsList = Object.values(DiagonalDirections);
|
85
|
+
|
86
|
+
// list of alignments to all activated directions
|
87
|
+
const axialAlignmentList = axialDirectionsList.map((direction) =>
|
88
|
+
getAlignment(direction, AXIAL_DEVIATION_COSINE)
|
89
|
+
);
|
90
|
+
|
91
|
+
const diagonalAlignmentList = diagonalDirectionsList.map((direction) =>
|
92
|
+
getAlignment(direction, DIAGONAL_DEVIATION_COSINE)
|
93
|
+
);
|
94
|
+
|
95
|
+
const isAligned =
|
96
|
+
axialAlignmentList.some(Boolean) || diagonalAlignmentList.some(Boolean);
|
97
|
+
|
98
|
+
const isFast = velocityVector.magnitude > this.minVelocity;
|
99
|
+
|
100
|
+
if (
|
101
|
+
this.maxNumberOfPointersSimultaneously ===
|
102
|
+
this.numberOfPointersRequired &&
|
103
|
+
isAligned &&
|
104
|
+
isFast
|
105
|
+
) {
|
106
|
+
clearTimeout(this.delayTimeout);
|
107
|
+
this.activate();
|
108
|
+
|
109
|
+
return true;
|
110
|
+
}
|
111
|
+
|
112
|
+
return false;
|
113
|
+
}
|
114
|
+
|
115
|
+
private endFling() {
|
116
|
+
this.logger.info("endFling")
|
117
|
+
if (!this.tryEndFling()) {
|
118
|
+
this.fail();
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
public onPointerDown(event: IncomingEvent): void {
|
123
|
+
this.tracker.addToTracker(event);
|
124
|
+
this.keyPointer = event.pointerId;
|
125
|
+
|
126
|
+
super.onPointerDown(event);
|
127
|
+
this.newPointerAction();
|
128
|
+
}
|
129
|
+
|
130
|
+
public onAdditionalPointerAdd(event: IncomingEvent): void {
|
131
|
+
this.tracker.addToTracker(event);
|
132
|
+
super.onAdditionalPointerAdd(event);
|
133
|
+
this.newPointerAction();
|
134
|
+
}
|
135
|
+
|
136
|
+
private newPointerAction(): void {
|
137
|
+
if (this.currentState === State.UNDETERMINED) {
|
138
|
+
this.startFling();
|
139
|
+
}
|
140
|
+
|
141
|
+
if (this.currentState !== State.BEGAN) {
|
142
|
+
return;
|
143
|
+
}
|
144
|
+
|
145
|
+
this.tryEndFling();
|
146
|
+
|
147
|
+
if (
|
148
|
+
this.tracker.getTrackedPointersCount() >
|
149
|
+
this.maxNumberOfPointersSimultaneously
|
150
|
+
) {
|
151
|
+
this.maxNumberOfPointersSimultaneously =
|
152
|
+
this.tracker.getTrackedPointersCount();
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
private pointerMoveAction(event: IncomingEvent): void {
|
157
|
+
this.logger.cloneWithPrefix("pointerMoveAction").info(JSON.stringify(event))
|
158
|
+
this.tracker.track(event);
|
159
|
+
|
160
|
+
if (this.currentState !== State.BEGAN) {
|
161
|
+
return;
|
162
|
+
}
|
163
|
+
|
164
|
+
this.tryEndFling();
|
165
|
+
}
|
166
|
+
|
167
|
+
public onPointerMove(event: IncomingEvent): void {
|
168
|
+
this.pointerMoveAction(event);
|
169
|
+
super.onPointerMove(event);
|
170
|
+
}
|
171
|
+
|
172
|
+
public onPointerOutOfBounds(event: IncomingEvent): void {
|
173
|
+
this.pointerMoveAction(event);
|
174
|
+
super.onPointerOutOfBounds(event);
|
175
|
+
}
|
176
|
+
|
177
|
+
public onPointerUp(event: IncomingEvent): void {
|
178
|
+
super.onPointerUp(event);
|
179
|
+
this.onUp(event);
|
180
|
+
|
181
|
+
this.keyPointer = NaN;
|
182
|
+
}
|
183
|
+
|
184
|
+
public onAdditionalPointerRemove(event: IncomingEvent): void {
|
185
|
+
super.onAdditionalPointerRemove(event);
|
186
|
+
this.onUp(event);
|
187
|
+
}
|
188
|
+
|
189
|
+
private onUp(event: IncomingEvent): void {
|
190
|
+
const logger = this.logger.cloneWithPrefix("onUp")
|
191
|
+
logger.info("start")
|
192
|
+
if (this.currentState === State.BEGAN) {
|
193
|
+
this.endFling();
|
194
|
+
}
|
195
|
+
logger.info(`removeFromTracker: pointerId=${event.pointerId}`)
|
196
|
+
this.tracker.removeFromTracker(event.pointerId);
|
197
|
+
}
|
198
|
+
|
199
|
+
public activate(): void {
|
200
|
+
super.activate();
|
201
|
+
this.end();
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
function coneToDeviation(degrees: number) {
|
206
|
+
return Math.cos(degToRad(degrees / 2));
|
207
|
+
}
|
208
|
+
|
209
|
+
function degToRad(degrees: number) {
|
210
|
+
return (degrees * Math.PI) / 180;
|
211
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import {
|
2
|
+
RNGHLogger,
|
3
|
+
InteractionManager,
|
4
|
+
RNGHError,
|
5
|
+
PointerTracker,
|
6
|
+
GestureHandler,
|
7
|
+
GestureHandlerDependencies,
|
8
|
+
ScrollLocker,
|
9
|
+
GestureHandlerOrchestrator,
|
10
|
+
RNGestureResponder
|
11
|
+
} from "../core"
|
12
|
+
import { TapGestureHandler } from './TapGestureHandler';
|
13
|
+
import { PanGestureHandler } from "./PanGestureHandler"
|
14
|
+
import { PinchGestureHandler } from "./PinchGestureHandler"
|
15
|
+
import { NativeViewGestureHandler } from "./NativeViewGestureHandler"
|
16
|
+
import { ManualGestureHandler } from './ManualGestureHandler';
|
17
|
+
import { LongPressGestureHandler } from "./LongPressGestureHandler"
|
18
|
+
import { FlingGestureHandler } from "./FlingGestureHandler"
|
19
|
+
import { RotationGestureHandler } from "./RotationGestureHandler"
|
20
|
+
|
21
|
+
export class GestureHandlerFactory {
|
22
|
+
private orchestrator: GestureHandlerOrchestrator
|
23
|
+
private logger: RNGHLogger
|
24
|
+
|
25
|
+
constructor(private cleanLogger: RNGHLogger, private scrollLocker: ScrollLocker, private interactionManager: InteractionManager, private rnGestureResponder: RNGestureResponder) {
|
26
|
+
this.logger = cleanLogger.cloneWithPrefix("Factory")
|
27
|
+
this.orchestrator = new GestureHandlerOrchestrator(cleanLogger.cloneWithPrefix("Orchestrator"))
|
28
|
+
}
|
29
|
+
|
30
|
+
create(handlerName: string, handlerTag: number): GestureHandler {
|
31
|
+
this.logger.info(`create ${handlerName} with handlerTag: ${handlerTag}`)
|
32
|
+
const deps: GestureHandlerDependencies = {
|
33
|
+
tracker: new PointerTracker(),
|
34
|
+
orchestrator: this.orchestrator,
|
35
|
+
handlerTag,
|
36
|
+
interactionManager: this.interactionManager,
|
37
|
+
logger: this.cleanLogger.cloneWithPrefix("GestureHandler"),
|
38
|
+
scrollLocker: this.scrollLocker,
|
39
|
+
rnGestureResponder: this.rnGestureResponder,
|
40
|
+
}
|
41
|
+
switch (handlerName) {
|
42
|
+
case "TapGestureHandler":
|
43
|
+
return new TapGestureHandler(deps)
|
44
|
+
case "PanGestureHandler":
|
45
|
+
return new PanGestureHandler(deps)
|
46
|
+
case "PinchGestureHandler":
|
47
|
+
return new PinchGestureHandler(deps)
|
48
|
+
case "NativeViewGestureHandler":
|
49
|
+
return new NativeViewGestureHandler(deps)
|
50
|
+
case "ManualGestureHandler":
|
51
|
+
return new ManualGestureHandler(deps)
|
52
|
+
case "LongPressGestureHandler":
|
53
|
+
return new LongPressGestureHandler(deps)
|
54
|
+
case "FlingGestureHandler":
|
55
|
+
return new FlingGestureHandler(deps)
|
56
|
+
case "RotationGestureHandler":
|
57
|
+
return new RotationGestureHandler(deps)
|
58
|
+
default:
|
59
|
+
const msg = `Unknown handler type: ${handlerName}`
|
60
|
+
this.logger.info(msg)
|
61
|
+
throw new RNGHError(msg)
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
@@ -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
|
+
}
|
@@ -1,7 +1,5 @@
|
|
1
|
-
import { GestureHandler, GestureHandlerDependencies, DEFAULT_TOUCH_SLOP } from "
|
2
|
-
|
3
|
-
import { State } from "./State"
|
4
|
-
import { AdaptedEvent } from './Event';
|
1
|
+
import { GestureHandler, GestureHandlerDependencies, DEFAULT_TOUCH_SLOP, Vector2D, State, IncomingEvent } from "../core"
|
2
|
+
|
5
3
|
|
6
4
|
export class NativeViewGestureHandler extends GestureHandler {
|
7
5
|
private minDistSq = DEFAULT_TOUCH_SLOP * DEFAULT_TOUCH_SLOP;
|
@@ -20,7 +18,7 @@ export class NativeViewGestureHandler extends GestureHandler {
|
|
20
18
|
return {}
|
21
19
|
}
|
22
20
|
|
23
|
-
public onPointerDown(e:
|
21
|
+
public onPointerDown(e: IncomingEvent) {
|
24
22
|
this.tracker.addToTracker(e);
|
25
23
|
super.onPointerDown(e);
|
26
24
|
this.onNewPointer();
|
@@ -31,24 +29,26 @@ export class NativeViewGestureHandler extends GestureHandler {
|
|
31
29
|
if (this.currentState !== State.UNDETERMINED)
|
32
30
|
return;
|
33
31
|
this.begin();
|
34
|
-
this.
|
32
|
+
if(this.view.hasButtonRole()) {
|
33
|
+
this.activate();
|
34
|
+
}
|
35
35
|
}
|
36
36
|
|
37
|
-
public onAdditionalPointerAdd(e:
|
37
|
+
public onAdditionalPointerAdd(e: IncomingEvent) {
|
38
38
|
this.tracker.addToTracker(e);
|
39
39
|
super.onPointerDown(e);
|
40
40
|
this.onNewPointer();
|
41
41
|
}
|
42
42
|
|
43
|
-
public onPointerMove(e:
|
43
|
+
public onPointerMove(e: IncomingEvent): void {
|
44
44
|
this.tracker.track(e);
|
45
45
|
const {x: dx, y: dy} = this.startPos.clone().subtract(this.tracker.getLastAvgPos()).value
|
46
46
|
const distSq = dx * dx + dy * dy;
|
47
47
|
|
48
48
|
if (distSq >= this.minDistSq) {
|
49
|
-
if (this.currentState === State.ACTIVE) {
|
49
|
+
if (this.view.hasButtonRole() && this.currentState === State.ACTIVE) {
|
50
50
|
this.cancel();
|
51
|
-
} else if (this.currentState === State.BEGAN) {
|
51
|
+
} else if (!this.view.hasButtonRole() && this.currentState === State.BEGAN) {
|
52
52
|
this.activate();
|
53
53
|
}
|
54
54
|
}
|
@@ -61,12 +61,12 @@ export class NativeViewGestureHandler extends GestureHandler {
|
|
61
61
|
}
|
62
62
|
}
|
63
63
|
|
64
|
-
public onPointerUp(event:
|
64
|
+
public onPointerUp(event: IncomingEvent): void {
|
65
65
|
super.onPointerUp(event);
|
66
66
|
this.onAnyPointerUp(event);
|
67
67
|
}
|
68
68
|
|
69
|
-
private onAnyPointerUp(e:
|
69
|
+
private onAnyPointerUp(e: IncomingEvent) {
|
70
70
|
this.tracker.removeFromTracker(e.pointerId);
|
71
71
|
if (this.tracker.getTrackedPointersCount() === 0) {
|
72
72
|
if (this.currentState === State.ACTIVE) {
|
@@ -77,7 +77,7 @@ export class NativeViewGestureHandler extends GestureHandler {
|
|
77
77
|
}
|
78
78
|
}
|
79
79
|
|
80
|
-
public onAdditionalPointerRemove(e:
|
80
|
+
public onAdditionalPointerRemove(e: IncomingEvent) {
|
81
81
|
super.onAdditionalPointerRemove(e)
|
82
82
|
this.onAnyPointerUp(e)
|
83
83
|
}
|
@@ -97,14 +97,14 @@ export class NativeViewGestureHandler extends GestureHandler {
|
|
97
97
|
if (
|
98
98
|
this.currentState === State.ACTIVE &&
|
99
99
|
handler.getState() === State.ACTIVE &&
|
100
|
-
|
100
|
+
this.canBeInterrupted()
|
101
101
|
) {
|
102
102
|
return false;
|
103
103
|
}
|
104
104
|
|
105
105
|
return (
|
106
106
|
this.currentState === State.ACTIVE &&
|
107
|
-
|
107
|
+
this.canBeInterrupted() &&
|
108
108
|
handler.getTag() > 0
|
109
109
|
);
|
110
110
|
}
|
@@ -1,7 +1,14 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
import {
|
2
|
+
GestureHandler,
|
3
|
+
GestureConfig,
|
4
|
+
GestureHandlerDependencies,
|
5
|
+
DEFAULT_TOUCH_SLOP,
|
6
|
+
IncomingEvent,
|
7
|
+
State,
|
8
|
+
Vector2D,
|
9
|
+
getStateName
|
10
|
+
} from "../core"
|
11
|
+
|
5
12
|
|
6
13
|
const DEFAULT_MIN_DIST_SQ = DEFAULT_TOUCH_SLOP * DEFAULT_TOUCH_SLOP;
|
7
14
|
|
@@ -82,6 +89,7 @@ export class PanGestureHandler extends GestureHandler<PanGestureHandlerConfig> {
|
|
82
89
|
}
|
83
90
|
|
84
91
|
private unlockScrolls: (() => void) | undefined
|
92
|
+
private unlockRNGestureResponder: (() => void) | undefined
|
85
93
|
|
86
94
|
public constructor(deps: GestureHandlerDependencies) {
|
87
95
|
super({ ...deps, logger: deps.logger.cloneWithPrefix("PanGestureHandler") })
|
@@ -174,9 +182,10 @@ export class PanGestureHandler extends GestureHandler<PanGestureHandlerConfig> {
|
|
174
182
|
clearTimeout(this.activationTimeout);
|
175
183
|
}
|
176
184
|
|
177
|
-
private tryBegin(e:
|
185
|
+
private tryBegin(e: IncomingEvent): void {
|
186
|
+
this.logger.cloneWithPrefix("tryBegin").debug({currentState: getStateName(this.currentState), trackedPointersCount: this.tracker.getTrackedPointersCount(), minPointers: this.minPointers})
|
178
187
|
if (
|
179
|
-
this.currentState === State.UNDETERMINED &&
|
188
|
+
(this.currentState === State.UNDETERMINED) &&
|
180
189
|
this.tracker.getTrackedPointersCount() >= this.minPointers
|
181
190
|
) {
|
182
191
|
this.resetProgress();
|
@@ -233,7 +242,7 @@ export class PanGestureHandler extends GestureHandler<PanGestureHandlerConfig> {
|
|
233
242
|
return false
|
234
243
|
}
|
235
244
|
|
236
|
-
public onAdditionalPointerAdd(event:
|
245
|
+
public onAdditionalPointerAdd(event: IncomingEvent): void {
|
237
246
|
this.tracker.addToTracker(event);
|
238
247
|
super.onAdditionalPointerAdd(event);
|
239
248
|
this.tryBegin(event);
|
@@ -251,7 +260,7 @@ export class PanGestureHandler extends GestureHandler<PanGestureHandlerConfig> {
|
|
251
260
|
}
|
252
261
|
}
|
253
262
|
|
254
|
-
public onPointerUp(event:
|
263
|
+
public onPointerUp(event: IncomingEvent): void {
|
255
264
|
super.onPointerUp(event);
|
256
265
|
if (this.currentState === State.ACTIVE) {
|
257
266
|
this.lastPos = this.tracker.getLastAvgPos();
|
@@ -265,7 +274,7 @@ export class PanGestureHandler extends GestureHandler<PanGestureHandlerConfig> {
|
|
265
274
|
}
|
266
275
|
}
|
267
276
|
|
268
|
-
public onAdditionalPointerRemove(event:
|
277
|
+
public onAdditionalPointerRemove(event: IncomingEvent): void {
|
269
278
|
super.onAdditionalPointerRemove(event);
|
270
279
|
this.tracker.removeFromTracker(event.pointerId);
|
271
280
|
this.offset.add(this.lastPos).subtract(this.startPos)
|
@@ -281,7 +290,7 @@ export class PanGestureHandler extends GestureHandler<PanGestureHandlerConfig> {
|
|
281
290
|
}
|
282
291
|
}
|
283
292
|
|
284
|
-
public onPointerMove(event:
|
293
|
+
public onPointerMove(event: IncomingEvent): void {
|
285
294
|
this.tracker.track(event);
|
286
295
|
this.lastPos = this.tracker.getLastAvgPos()
|
287
296
|
this.velocity = this.tracker.getVelocity(event.pointerId)
|
@@ -289,7 +298,7 @@ export class PanGestureHandler extends GestureHandler<PanGestureHandlerConfig> {
|
|
289
298
|
super.onPointerMove(event);
|
290
299
|
}
|
291
300
|
|
292
|
-
public onPointerOutOfBounds(event:
|
301
|
+
public onPointerOutOfBounds(event: IncomingEvent): void {
|
293
302
|
if (this.shouldCancelWhenOutside) {
|
294
303
|
return;
|
295
304
|
}
|
@@ -317,12 +326,17 @@ export class PanGestureHandler extends GestureHandler<PanGestureHandlerConfig> {
|
|
317
326
|
};
|
318
327
|
}
|
319
328
|
|
320
|
-
protected
|
321
|
-
super.
|
329
|
+
protected onStateChange(newState: State, oldState: State) {
|
330
|
+
super.onStateChange(newState, oldState)
|
322
331
|
if (newState === State.BEGAN) {
|
323
332
|
this.unlockScrolls = this.scrollLocker.lockScrollContainingViewTag(this.view.getTag())
|
324
333
|
} else if (newState !== State.ACTIVE) {
|
325
334
|
this.unlockScrolls?.()
|
326
335
|
}
|
336
|
+
if (newState === State.ACTIVE) {
|
337
|
+
this.unlockRNGestureResponder = this.rnGestureResponder.lock(this.view.getTag())
|
338
|
+
} else {
|
339
|
+
this.unlockRNGestureResponder?.()
|
340
|
+
}
|
327
341
|
}
|
328
342
|
}
|