@react-native-oh-tpl/react-native-gesture-handler 2.12.9 → 2.14.4-1
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.har +0 -0
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/index.js +91 -137
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- 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.map +1 -1
- package/lib/module/index.js +10 -141
- 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 +42 -9
- 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 +69 -66
- 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
- package/harmony/gesture_handler/BuildProfile.ets +0 -5
- package/harmony/gesture_handler/build-profile.json5 +0 -19
- package/harmony/gesture_handler/hvigorfile.ts +0 -2
- package/harmony/gesture_handler/index.ets +0 -3
- package/harmony/gesture_handler/oh-package-lock.json5 +0 -17
- package/harmony/gesture_handler/oh-package.json5 +0 -12
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +0 -8
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +0 -103
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +0 -21
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +0 -36
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentInstance.h +0 -27
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +0 -32
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +0 -22
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +0 -15
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +0 -72
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +0 -36
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +0 -78
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +0 -25
- package/harmony/gesture_handler/src/main/ets/CircularBuffer.ts +0 -42
- package/harmony/gesture_handler/src/main/ets/Event.ts +0 -68
- package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +0 -53
- package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +0 -663
- 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/GestureHandlerOrchestrator.ts +0 -280
- package/harmony/gesture_handler/src/main/ets/GestureHandlerPackage.ts +0 -22
- package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +0 -28
- package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +0 -109
- package/harmony/gesture_handler/src/main/ets/LeastSquareSolver.ts +0 -182
- package/harmony/gesture_handler/src/main/ets/NativeViewGestureHandler.ts +0 -115
- package/harmony/gesture_handler/src/main/ets/OutgoingEvent.ts +0 -34
- package/harmony/gesture_handler/src/main/ets/PanGestureHandler.ts +0 -328
- package/harmony/gesture_handler/src/main/ets/PointerTracker.ts +0 -239
- package/harmony/gesture_handler/src/main/ets/RNGHError.ts +0 -5
- 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/RNGestureHandlerButton.ets +0 -38
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +0 -183
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +0 -53
- package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +0 -23
- package/harmony/gesture_handler/src/main/ets/State.ts +0 -47
- package/harmony/gesture_handler/src/main/ets/TapGestureHandler.ts +0 -206
- package/harmony/gesture_handler/src/main/ets/Vector2D.ts +0 -36
- package/harmony/gesture_handler/src/main/ets/VelocityTracker.ts +0 -98
- 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/namespace/RNGestureHandlerButton.ts +0 -140
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +0 -25
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerRootView.ts +0 -101
- package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +0 -3
- package/harmony/gesture_handler/src/main/ets/pages/Index.ets +0 -17
- package/harmony/gesture_handler/src/main/ets/types.ts +0 -25
- package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +0 -41
- package/harmony/gesture_handler/src/main/module.json5 +0 -7
- package/harmony/gesture_handler/src/main/resources/base/element/color.json +0 -8
- package/harmony/gesture_handler/src/main/resources/base/element/string.json +0 -16
- 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 +0 -5
- package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +0 -16
- package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +0 -16
- package/harmony/gesture_handler/ts.ts +0 -2
@@ -1,182 +0,0 @@
|
|
1
|
-
// Implementation taken from Flutter's LeastSquareSolver
|
2
|
-
// https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/gestures/lsq_solver.dart
|
3
|
-
|
4
|
-
class Vector {
|
5
|
-
private offset: number;
|
6
|
-
private length: number;
|
7
|
-
private elements: number[];
|
8
|
-
|
9
|
-
constructor(length: number) {
|
10
|
-
this.offset = 0;
|
11
|
-
this.length = length;
|
12
|
-
this.elements = new Array<number>(length);
|
13
|
-
}
|
14
|
-
|
15
|
-
public static fromVOL(
|
16
|
-
values: number[],
|
17
|
-
offset: number,
|
18
|
-
length: number
|
19
|
-
): Vector {
|
20
|
-
const result = new Vector(0);
|
21
|
-
|
22
|
-
result.offset = offset;
|
23
|
-
result.length = length;
|
24
|
-
result.elements = values;
|
25
|
-
|
26
|
-
return result;
|
27
|
-
}
|
28
|
-
|
29
|
-
public get(index: number): number {
|
30
|
-
return this.elements[this.offset + index];
|
31
|
-
}
|
32
|
-
|
33
|
-
public set(index: number, value: number): void {
|
34
|
-
this.elements[this.offset + index] = value;
|
35
|
-
}
|
36
|
-
|
37
|
-
public dot(other: Vector): number {
|
38
|
-
let result = 0;
|
39
|
-
for (let i = 0; i < this.length; i++) {
|
40
|
-
result += this.get(i) * other.get(i);
|
41
|
-
}
|
42
|
-
return result;
|
43
|
-
}
|
44
|
-
|
45
|
-
public norm() {
|
46
|
-
return Math.sqrt(this.dot(this));
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
class Matrix {
|
51
|
-
private columns: number;
|
52
|
-
private elements: number[];
|
53
|
-
|
54
|
-
constructor(rows: number, columns: number) {
|
55
|
-
this.columns = columns;
|
56
|
-
this.elements = new Array<number>(rows * columns);
|
57
|
-
}
|
58
|
-
|
59
|
-
public get(row: number, column: number): number {
|
60
|
-
return this.elements[row * this.columns + column];
|
61
|
-
}
|
62
|
-
|
63
|
-
public set(row: number, column: number, value: number): void {
|
64
|
-
this.elements[row * this.columns + column] = value;
|
65
|
-
}
|
66
|
-
|
67
|
-
public getRow(row: number): Vector {
|
68
|
-
return Vector.fromVOL(this.elements, row * this.columns, this.columns);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
/// An nth degree polynomial fit to a dataset.
|
73
|
-
class PolynomialFit {
|
74
|
-
/// The polynomial coefficients of the fit.
|
75
|
-
///
|
76
|
-
/// For each `i`, the element `coefficients[i]` is the coefficient of
|
77
|
-
/// the `i`-th power of the variable.
|
78
|
-
public coefficients: number[];
|
79
|
-
|
80
|
-
/// Creates a polynomial fit of the given degree.
|
81
|
-
///
|
82
|
-
/// There are n + 1 coefficients in a fit of degree n.
|
83
|
-
constructor(degree: number) {
|
84
|
-
this.coefficients = new Array<number>(degree + 1);
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
const precisionErrorTolerance = 1e-10;
|
89
|
-
|
90
|
-
/// Uses the least-squares algorithm to fit a polynomial to a set of data.
|
91
|
-
export class LeastSquareSolver {
|
92
|
-
/// The x-coordinates of each data point.
|
93
|
-
private x: number[];
|
94
|
-
/// The y-coordinates of each data point.
|
95
|
-
private y: number[];
|
96
|
-
/// The weight to use for each data point.
|
97
|
-
private w: number[];
|
98
|
-
|
99
|
-
/// Creates a least-squares solver.
|
100
|
-
///
|
101
|
-
/// The [x], [y], and [w] arguments must not be null.
|
102
|
-
constructor(x: number[], y: number[], w: number[]) {
|
103
|
-
this.x = x;
|
104
|
-
this.y = y;
|
105
|
-
this.w = w;
|
106
|
-
}
|
107
|
-
|
108
|
-
/// Fits a polynomial of the given degree to the data points.
|
109
|
-
///
|
110
|
-
/// When there is not enough data to fit a curve null is returned.
|
111
|
-
public solve(degree: number): PolynomialFit | null {
|
112
|
-
if (degree > this.x.length) {
|
113
|
-
// Not enough data to fit a curve.
|
114
|
-
return null;
|
115
|
-
}
|
116
|
-
|
117
|
-
const result = new PolynomialFit(degree);
|
118
|
-
|
119
|
-
// Shorthands for the purpose of notation equivalence to original C++ code.
|
120
|
-
const m = this.x.length;
|
121
|
-
const n = degree + 1;
|
122
|
-
|
123
|
-
// Expand the X vector to a matrix A, pre-multiplied by the weights.
|
124
|
-
const a = new Matrix(n, m);
|
125
|
-
for (let h = 0; h < m; h++) {
|
126
|
-
a.set(0, h, this.w[h]);
|
127
|
-
|
128
|
-
for (let i = 1; i < n; i++) {
|
129
|
-
a.set(i, h, a.get(i - 1, h) * this.x[h]);
|
130
|
-
}
|
131
|
-
}
|
132
|
-
|
133
|
-
// Apply the Gram-Schmidt process to A to obtain its QR decomposition.
|
134
|
-
|
135
|
-
// Orthonormal basis, column-major ordVectorer.
|
136
|
-
const q = new Matrix(n, m);
|
137
|
-
// Upper triangular matrix, row-major order.
|
138
|
-
const r = new Matrix(n, m);
|
139
|
-
|
140
|
-
for (let j = 0; j < n; j += 1) {
|
141
|
-
for (let h = 0; h < m; h += 1) {
|
142
|
-
q.set(j, h, a.get(j, h));
|
143
|
-
}
|
144
|
-
for (let i = 0; i < j; i += 1) {
|
145
|
-
const dot = q.getRow(j).dot(q.getRow(i));
|
146
|
-
for (let h = 0; h < m; h += 1) {
|
147
|
-
q.set(j, h, q.get(j, h) - dot * q.get(i, h));
|
148
|
-
}
|
149
|
-
}
|
150
|
-
|
151
|
-
const norm = q.getRow(j).norm();
|
152
|
-
if (norm < precisionErrorTolerance) {
|
153
|
-
// Vectors are linearly dependent or zero so no solution.
|
154
|
-
return null;
|
155
|
-
}
|
156
|
-
|
157
|
-
const inverseNorm = 1.0 / norm;
|
158
|
-
for (let h = 0; h < m; h += 1) {
|
159
|
-
q.set(j, h, q.get(j, h) * inverseNorm);
|
160
|
-
}
|
161
|
-
for (let i = 0; i < n; i += 1) {
|
162
|
-
r.set(j, i, i < j ? 0.0 : q.getRow(j).dot(a.getRow(i)));
|
163
|
-
}
|
164
|
-
}
|
165
|
-
|
166
|
-
// Solve R B = Qt W Y to find B. This is easy because R is upper triangular.
|
167
|
-
// We just work from bottom-right to top-left calculating B's coefficients.
|
168
|
-
const wy = new Vector(m);
|
169
|
-
for (let h = 0; h < m; h += 1) {
|
170
|
-
wy.set(h, this.y[h] * this.w[h]);
|
171
|
-
}
|
172
|
-
for (let i = n - 1; i >= 0; i -= 1) {
|
173
|
-
result.coefficients[i] = q.getRow(i).dot(wy);
|
174
|
-
for (let j = n - 1; j > i; j -= 1) {
|
175
|
-
result.coefficients[i] -= r.get(i, j) * result.coefficients[j];
|
176
|
-
}
|
177
|
-
result.coefficients[i] /= r.get(i, i);
|
178
|
-
}
|
179
|
-
|
180
|
-
return result;
|
181
|
-
}
|
182
|
-
}
|
@@ -1,115 +0,0 @@
|
|
1
|
-
import { GestureHandler, GestureHandlerDependencies, DEFAULT_TOUCH_SLOP } from "./GestureHandler"
|
2
|
-
import { Vector2D } from './Vector2D';
|
3
|
-
import { State } from "./State"
|
4
|
-
import { AdaptedEvent } from './Event';
|
5
|
-
|
6
|
-
export class NativeViewGestureHandler extends GestureHandler {
|
7
|
-
private minDistSq = DEFAULT_TOUCH_SLOP * DEFAULT_TOUCH_SLOP;
|
8
|
-
|
9
|
-
protected startPos = new Vector2D()
|
10
|
-
|
11
|
-
public canBeInterrupted() {
|
12
|
-
return !(this.config.disallowInterruption ?? false)
|
13
|
-
}
|
14
|
-
|
15
|
-
constructor(deps: GestureHandlerDependencies) {
|
16
|
-
super({ ...deps, logger: deps.logger.cloneWithPrefix("NativeViewGestureHandler") })
|
17
|
-
}
|
18
|
-
|
19
|
-
public getDefaultConfig() {
|
20
|
-
return {}
|
21
|
-
}
|
22
|
-
|
23
|
-
public onPointerDown(e: AdaptedEvent) {
|
24
|
-
this.tracker.addToTracker(e);
|
25
|
-
super.onPointerDown(e);
|
26
|
-
this.onNewPointer();
|
27
|
-
}
|
28
|
-
|
29
|
-
protected onNewPointer() {
|
30
|
-
this.startPos = this.tracker.getLastAvgPos();
|
31
|
-
if (this.currentState !== State.UNDETERMINED)
|
32
|
-
return;
|
33
|
-
this.begin();
|
34
|
-
this.activate();
|
35
|
-
}
|
36
|
-
|
37
|
-
public onAdditionalPointerAdd(e: AdaptedEvent) {
|
38
|
-
this.tracker.addToTracker(e);
|
39
|
-
super.onPointerDown(e);
|
40
|
-
this.onNewPointer();
|
41
|
-
}
|
42
|
-
|
43
|
-
public onPointerMove(e: AdaptedEvent): 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.currentState === State.ACTIVE) {
|
50
|
-
this.cancel();
|
51
|
-
} else if (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: AdaptedEvent): void {
|
65
|
-
super.onPointerUp(event);
|
66
|
-
this.onAnyPointerUp(event);
|
67
|
-
}
|
68
|
-
|
69
|
-
private onAnyPointerUp(e: AdaptedEvent) {
|
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: AdaptedEvent) {
|
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
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { State } from "./State"
|
2
|
-
import { TouchEventType } from "./Event"
|
3
|
-
|
4
|
-
export interface GestureEventPayload {
|
5
|
-
handlerTag: number;
|
6
|
-
numberOfPointers: number;
|
7
|
-
state: State;
|
8
|
-
}
|
9
|
-
|
10
|
-
export interface HandlerStateChangeEventPayload extends GestureEventPayload {
|
11
|
-
oldState: State;
|
12
|
-
}
|
13
|
-
|
14
|
-
export type GestureUpdateEvent<GestureEventPayloadT = Record<string, unknown>> = GestureEventPayload
|
15
|
-
& GestureEventPayloadT
|
16
|
-
|
17
|
-
export type GestureStateChangeEvent<GestureStateChangeEventPayloadT = Record<string, unknown>> = HandlerStateChangeEventPayload & GestureStateChangeEventPayloadT
|
18
|
-
|
19
|
-
export type TouchData = {
|
20
|
-
id: number;
|
21
|
-
x: number;
|
22
|
-
y: number;
|
23
|
-
absoluteX: number;
|
24
|
-
absoluteY: number;
|
25
|
-
};
|
26
|
-
|
27
|
-
export type GestureTouchEvent = {
|
28
|
-
handlerTag: number;
|
29
|
-
numberOfTouches: number;
|
30
|
-
state: State;
|
31
|
-
eventType: TouchEventType;
|
32
|
-
allTouches: TouchData[];
|
33
|
-
changedTouches: TouchData[];
|
34
|
-
};
|
@@ -1,328 +0,0 @@
|
|
1
|
-
import { GestureHandler, GestureConfig, GestureHandlerDependencies, DEFAULT_TOUCH_SLOP } from "./GestureHandler"
|
2
|
-
import { AdaptedEvent } from "./Event"
|
3
|
-
import { State } from "./State"
|
4
|
-
import { Vector2D } from "./Vector2D"
|
5
|
-
|
6
|
-
const DEFAULT_MIN_DIST_SQ = DEFAULT_TOUCH_SLOP * DEFAULT_TOUCH_SLOP;
|
7
|
-
|
8
|
-
type PanGestureHandlerConfig = GestureConfig
|
9
|
-
|
10
|
-
export class PanGestureHandler extends GestureHandler<PanGestureHandlerConfig> {
|
11
|
-
private startPos = new Vector2D();
|
12
|
-
private offset = new Vector2D()
|
13
|
-
private lastPos = new Vector2D();
|
14
|
-
private velocity = new Vector2D();
|
15
|
-
private activationTimeout = 0;
|
16
|
-
|
17
|
-
private get failOffsetXStart() {
|
18
|
-
if (this.config.failOffsetXStart === undefined
|
19
|
-
&& this.config.failOffsetXEnd === undefined)
|
20
|
-
return undefined
|
21
|
-
return this.config.failOffsetXStart ?? Number.MIN_SAFE_INTEGER
|
22
|
-
}
|
23
|
-
|
24
|
-
private get failOffsetXEnd() {
|
25
|
-
if (this.config.failOffsetXStart === undefined
|
26
|
-
&& this.config.failOffsetXEnd === undefined)
|
27
|
-
return undefined
|
28
|
-
return this.config.failOffsetXEnd ?? Number.MAX_SAFE_INTEGER
|
29
|
-
}
|
30
|
-
|
31
|
-
private get failOffsetYStart() {
|
32
|
-
if (this.config.failOffsetYStart === undefined
|
33
|
-
&& this.config.failOffsetYEnd === undefined)
|
34
|
-
return undefined
|
35
|
-
return this.config.failOffsetYStart ?? Number.MIN_SAFE_INTEGER
|
36
|
-
}
|
37
|
-
|
38
|
-
private get failOffsetYEnd() {
|
39
|
-
return this.config.failOffsetYEnd ?? Number.MAX_SAFE_INTEGER
|
40
|
-
}
|
41
|
-
|
42
|
-
private get activeOffsetXStart() {
|
43
|
-
if (this.config.activeOffsetXStart === undefined
|
44
|
-
&& this.config.activeOffsetXEnd === undefined)
|
45
|
-
return undefined
|
46
|
-
return this.config.activeOffsetXStart ?? Number.MIN_SAFE_INTEGER
|
47
|
-
}
|
48
|
-
|
49
|
-
private get activeOffsetXEnd() {
|
50
|
-
if (this.config.activeOffsetXStart === undefined
|
51
|
-
&& this.config.activeOffsetXEnd === undefined)
|
52
|
-
return undefined
|
53
|
-
return this.config.activeOffsetXEnd ?? Number.MAX_SAFE_INTEGER
|
54
|
-
}
|
55
|
-
|
56
|
-
private get activeOffsetYStart() {
|
57
|
-
if (this.config.activeOffsetYStart === undefined
|
58
|
-
&& this.config.activeOffsetYEnd === undefined)
|
59
|
-
return undefined
|
60
|
-
return this.config.activeOffsetYStart ?? Number.MIN_SAFE_INTEGER
|
61
|
-
}
|
62
|
-
|
63
|
-
private get activeOffsetYEnd() {
|
64
|
-
if (this.config.activeOffsetYStart === undefined
|
65
|
-
&& this.config.activeOffsetYEnd === undefined)
|
66
|
-
return undefined
|
67
|
-
return this.config.activeOffsetYEnd ?? Number.MAX_SAFE_INTEGER
|
68
|
-
}
|
69
|
-
|
70
|
-
private get minVelocityX() {
|
71
|
-
return this.config.minVelocityX ?? this.config.minVelocity ?? Number.MAX_SAFE_INTEGER
|
72
|
-
}
|
73
|
-
|
74
|
-
private get minVelocityY() {
|
75
|
-
return this.config.minVelocityY ?? this.config.minVelocityY ?? Number.MAX_SAFE_INTEGER
|
76
|
-
}
|
77
|
-
|
78
|
-
private minVelocitySq = Number.MAX_SAFE_INTEGER
|
79
|
-
|
80
|
-
private get minPointers() {
|
81
|
-
return this.config.minPointers ?? 1
|
82
|
-
}
|
83
|
-
|
84
|
-
private unlockScrolls: (() => void) | undefined
|
85
|
-
|
86
|
-
public constructor(deps: GestureHandlerDependencies) {
|
87
|
-
super({ ...deps, logger: deps.logger.cloneWithPrefix("PanGestureHandler") })
|
88
|
-
}
|
89
|
-
|
90
|
-
public onPointerDown(e) {
|
91
|
-
this.tracker.addToTracker(e);
|
92
|
-
super.onPointerDown(e);
|
93
|
-
this.lastPos = this.tracker.getLastAvgPos()
|
94
|
-
this.startPos = this.lastPos.clone()
|
95
|
-
this.tryBegin(e);
|
96
|
-
this.tryActivating();
|
97
|
-
}
|
98
|
-
|
99
|
-
private tryActivating(): void {
|
100
|
-
if (this.currentState === State.BEGAN) {
|
101
|
-
if (this.shouldFail()) {
|
102
|
-
this.fail();
|
103
|
-
} else if (this.shouldActivate()) {
|
104
|
-
this.activate();
|
105
|
-
}
|
106
|
-
}
|
107
|
-
}
|
108
|
-
|
109
|
-
private shouldFail(): boolean {
|
110
|
-
const {x: dx, y: dy} = this.getTranslation().value;
|
111
|
-
const distanceSq = dx * dx + dy * dy;
|
112
|
-
if (this.activateAfterLongPress > 0 && distanceSq > DEFAULT_MIN_DIST_SQ) {
|
113
|
-
this.clearActivationTimeout();
|
114
|
-
return true;
|
115
|
-
}
|
116
|
-
if (this.failOffsetXStart !== Number.MIN_SAFE_INTEGER && dx < this.failOffsetXStart) {
|
117
|
-
return true;
|
118
|
-
}
|
119
|
-
if (this.failOffsetXEnd !== Number.MAX_SAFE_INTEGER && dx > this.failOffsetXEnd) {
|
120
|
-
return true;
|
121
|
-
}
|
122
|
-
if (this.failOffsetYStart !== Number.MIN_SAFE_INTEGER && dy < this.failOffsetYStart) {
|
123
|
-
return true;
|
124
|
-
}
|
125
|
-
return (this.failOffsetYEnd !== Number.MAX_SAFE_INTEGER && dy > this.failOffsetYEnd);
|
126
|
-
}
|
127
|
-
|
128
|
-
private getTranslation() {
|
129
|
-
return this.lastPos.clone().subtract(this.startPos).add(this.offset)
|
130
|
-
}
|
131
|
-
|
132
|
-
private shouldActivate(): boolean {
|
133
|
-
const {x: dx, y: dy} = this.getTranslation().value;
|
134
|
-
if (this.activeOffsetXStart !== Number.MAX_SAFE_INTEGER && dx < this.activeOffsetXStart
|
135
|
-
) {
|
136
|
-
return true;
|
137
|
-
}
|
138
|
-
if (this.activeOffsetXEnd !== Number.MIN_SAFE_INTEGER && dx > this.activeOffsetXEnd) {
|
139
|
-
return true;
|
140
|
-
}
|
141
|
-
if (this.activeOffsetYStart !== Number.MAX_SAFE_INTEGER && dy < this.activeOffsetYStart) {
|
142
|
-
return true;
|
143
|
-
}
|
144
|
-
if (this.activeOffsetYEnd !== Number.MIN_SAFE_INTEGER && dy > this.activeOffsetYEnd) {
|
145
|
-
return true;
|
146
|
-
}
|
147
|
-
const distanceSq: number = dx * dx + dy * dy;
|
148
|
-
if (this.minDistSq !== Number.MAX_SAFE_INTEGER && distanceSq >= this.minDistSq) {
|
149
|
-
return true;
|
150
|
-
}
|
151
|
-
const {x: vx, y: vy} = this.velocity
|
152
|
-
if (
|
153
|
-
this.minVelocityX !== Number.MAX_SAFE_INTEGER &&
|
154
|
-
((this.minVelocityX < 0 && vx <= this.minVelocityX) ||
|
155
|
-
(this.minVelocityX >= 0 && this.minVelocityX <= vx))
|
156
|
-
) {
|
157
|
-
return true;
|
158
|
-
}
|
159
|
-
if (
|
160
|
-
this.minVelocityY !== Number.MAX_SAFE_INTEGER &&
|
161
|
-
((this.minVelocityY < 0 && vy <= this.minVelocityY) ||
|
162
|
-
(this.minVelocityY >= 0 && this.minVelocityY <= vy))
|
163
|
-
) {
|
164
|
-
return true;
|
165
|
-
}
|
166
|
-
const velocitySq: number = vx * vx + vy * vy;
|
167
|
-
return (
|
168
|
-
this.minVelocitySq !== Number.MAX_SAFE_INTEGER &&
|
169
|
-
velocitySq >= this.minVelocitySq
|
170
|
-
);
|
171
|
-
}
|
172
|
-
|
173
|
-
private clearActivationTimeout(): void {
|
174
|
-
clearTimeout(this.activationTimeout);
|
175
|
-
}
|
176
|
-
|
177
|
-
private tryBegin(e: AdaptedEvent): void {
|
178
|
-
if (
|
179
|
-
this.currentState === State.UNDETERMINED &&
|
180
|
-
this.tracker.getTrackedPointersCount() >= this.minPointers
|
181
|
-
) {
|
182
|
-
this.resetProgress();
|
183
|
-
this.offset = new Vector2D();
|
184
|
-
this.velocity = new Vector2D();
|
185
|
-
|
186
|
-
this.begin();
|
187
|
-
|
188
|
-
if (this.activateAfterLongPress > 0) {
|
189
|
-
this.activationTimeout = setTimeout(() => {
|
190
|
-
this.activate();
|
191
|
-
}, this.activateAfterLongPress);
|
192
|
-
}
|
193
|
-
} else {
|
194
|
-
this.velocity = this.tracker.getVelocity(e.pointerId)
|
195
|
-
}
|
196
|
-
}
|
197
|
-
|
198
|
-
public getDefaultConfig() {
|
199
|
-
return {}
|
200
|
-
}
|
201
|
-
|
202
|
-
private get activateAfterLongPress() {
|
203
|
-
return this.config.activateAfterLongPress ?? 0
|
204
|
-
}
|
205
|
-
|
206
|
-
private get minDistSq() {
|
207
|
-
if (this.config.minDist !== undefined) {
|
208
|
-
return this.config.minDist * this.config.minDist;
|
209
|
-
} else if (this.hasCustomActivationCriteria()) {
|
210
|
-
return Number.MAX_SAFE_INTEGER;
|
211
|
-
}
|
212
|
-
return DEFAULT_MIN_DIST_SQ
|
213
|
-
}
|
214
|
-
|
215
|
-
private hasCustomActivationCriteria() {
|
216
|
-
const criterias: (keyof PanGestureHandlerConfig)[] = [
|
217
|
-
'activeOffsetXStart',
|
218
|
-
'activeOffsetXEnd',
|
219
|
-
'failOffsetXStart',
|
220
|
-
'failOffsetXEnd',
|
221
|
-
'activeOffsetYStart',
|
222
|
-
'activeOffsetYEnd',
|
223
|
-
'failOffsetYStart',
|
224
|
-
'failOffsetYEnd',
|
225
|
-
'minVelocityX',
|
226
|
-
'minVelocityY',
|
227
|
-
]
|
228
|
-
for (const key in this.config) {
|
229
|
-
if (criterias.indexOf(key as keyof PanGestureHandlerConfig) >= 0) {
|
230
|
-
return true
|
231
|
-
}
|
232
|
-
}
|
233
|
-
return false
|
234
|
-
}
|
235
|
-
|
236
|
-
public onAdditionalPointerAdd(event: AdaptedEvent): void {
|
237
|
-
this.tracker.addToTracker(event);
|
238
|
-
super.onAdditionalPointerAdd(event);
|
239
|
-
this.tryBegin(event);
|
240
|
-
this.offset.add(this.lastPos).subtract(this.startPos)
|
241
|
-
this.lastPos = this.tracker.getLastAvgPos()
|
242
|
-
this.startPos = this.lastPos.clone()
|
243
|
-
if (this.tracker.getTrackedPointersCount() > (this.config.maxPointers ?? 10)) {
|
244
|
-
if (this.currentState === State.ACTIVE) {
|
245
|
-
this.cancel();
|
246
|
-
} else {
|
247
|
-
this.fail();
|
248
|
-
}
|
249
|
-
} else {
|
250
|
-
this.tryActivating();
|
251
|
-
}
|
252
|
-
}
|
253
|
-
|
254
|
-
public onPointerUp(event: AdaptedEvent): void {
|
255
|
-
super.onPointerUp(event);
|
256
|
-
if (this.currentState === State.ACTIVE) {
|
257
|
-
this.lastPos = this.tracker.getLastAvgPos();
|
258
|
-
}
|
259
|
-
this.tracker.removeFromTracker(event.pointerId);
|
260
|
-
if (this.currentState === State.ACTIVE) {
|
261
|
-
this.end();
|
262
|
-
} else {
|
263
|
-
this.resetProgress();
|
264
|
-
this.fail();
|
265
|
-
}
|
266
|
-
}
|
267
|
-
|
268
|
-
public onAdditionalPointerRemove(event: AdaptedEvent): void {
|
269
|
-
super.onAdditionalPointerRemove(event);
|
270
|
-
this.tracker.removeFromTracker(event.pointerId);
|
271
|
-
this.offset.add(this.lastPos).subtract(this.startPos)
|
272
|
-
this.lastPos = this.tracker.getLastAvgPos()
|
273
|
-
this.startPos = this.lastPos.clone()
|
274
|
-
if (
|
275
|
-
!(
|
276
|
-
this.currentState === State.ACTIVE &&
|
277
|
-
this.tracker.getTrackedPointersCount() < this.minPointers
|
278
|
-
)
|
279
|
-
) {
|
280
|
-
this.tryActivating();
|
281
|
-
}
|
282
|
-
}
|
283
|
-
|
284
|
-
public onPointerMove(event: AdaptedEvent): void {
|
285
|
-
this.tracker.track(event);
|
286
|
-
this.lastPos = this.tracker.getLastAvgPos()
|
287
|
-
this.velocity = this.tracker.getVelocity(event.pointerId)
|
288
|
-
this.tryActivating();
|
289
|
-
super.onPointerMove(event);
|
290
|
-
}
|
291
|
-
|
292
|
-
public onPointerOutOfBounds(event: AdaptedEvent): void {
|
293
|
-
if (this.shouldCancelWhenOutside) {
|
294
|
-
return;
|
295
|
-
}
|
296
|
-
this.tracker.track(event);
|
297
|
-
this.lastPos = this.tracker.getLastAvgPos()
|
298
|
-
this.velocity = this.tracker.getVelocity(event.pointerId)
|
299
|
-
this.tryActivating();
|
300
|
-
if (this.currentState === State.ACTIVE) {
|
301
|
-
super.onPointerOutOfBounds(event);
|
302
|
-
}
|
303
|
-
}
|
304
|
-
|
305
|
-
protected transformNativeEvent() {
|
306
|
-
const rect = this.view.getBoundingRect();
|
307
|
-
const translation = this.getTranslation()
|
308
|
-
return {
|
309
|
-
translationX: translation.x,
|
310
|
-
translationY: translation.y,
|
311
|
-
absoluteX: this.tracker.getLastAvgX(),
|
312
|
-
absoluteY: this.tracker.getLastAvgY(),
|
313
|
-
velocityX: this.velocity.x,
|
314
|
-
velocityY: this.velocity.y,
|
315
|
-
x: this.tracker.getLastAvgX() - rect.x,
|
316
|
-
y: this.tracker.getLastAvgY() - rect.y,
|
317
|
-
};
|
318
|
-
}
|
319
|
-
|
320
|
-
protected stateDidChange(newState: State, oldState: State) {
|
321
|
-
super.stateDidChange(newState, oldState)
|
322
|
-
if (newState === State.BEGAN) {
|
323
|
-
this.unlockScrolls = this.scrollLocker.lockScrollContainingViewTag(this.view.getTag())
|
324
|
-
} else if (newState !== State.ACTIVE) {
|
325
|
-
this.unlockScrolls?.()
|
326
|
-
}
|
327
|
-
}
|
328
|
-
}
|