@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.
Files changed (105) hide show
  1. package/DrawerLayout/index.ts +2 -2
  2. package/Swipeable/index.ts +2 -2
  3. package/harmony/gesture_handler/BuildProfile.ets +17 -0
  4. package/harmony/gesture_handler/build-profile.json5 +19 -0
  5. package/harmony/gesture_handler/hvigorfile.ts +2 -0
  6. package/harmony/gesture_handler/index.ets +2 -0
  7. package/harmony/gesture_handler/oh-package-lock.json5 +18 -0
  8. package/harmony/gesture_handler/oh-package.json5 +12 -0
  9. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -0
  10. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +12 -0
  11. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp +123 -0
  12. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +15 -0
  13. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +27 -0
  14. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +245 -0
  15. package/harmony/gesture_handler/src/main/ets/RNOHPackage.ets +17 -0
  16. package/harmony/gesture_handler/src/main/ets/core/CircularBuffer.ts +42 -0
  17. package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +739 -0
  18. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +344 -0
  19. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +63 -0
  20. package/harmony/gesture_handler/src/main/ets/core/IncomingEvent.ts +78 -0
  21. package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +144 -0
  22. package/harmony/gesture_handler/src/main/ets/core/LeastSquareSolver.ts +182 -0
  23. package/harmony/gesture_handler/src/main/ets/core/Multiset.ts +26 -0
  24. package/harmony/gesture_handler/src/main/ets/core/OutgoingEvent.ts +34 -0
  25. package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +12 -0
  26. package/harmony/gesture_handler/src/main/ets/core/PointerTracker.ts +239 -0
  27. package/harmony/gesture_handler/src/main/ets/core/RNGHError.ts +5 -0
  28. package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +16 -0
  29. package/harmony/gesture_handler/src/main/ets/core/State.ts +47 -0
  30. package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +80 -0
  31. package/harmony/gesture_handler/src/main/ets/core/VelocityTracker.ts +106 -0
  32. package/harmony/gesture_handler/src/main/ets/core/View.ts +21 -0
  33. package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +7 -0
  34. package/harmony/gesture_handler/src/main/ets/core/index.ts +15 -0
  35. package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +169 -0
  36. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +219 -0
  37. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +67 -0
  38. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +139 -0
  39. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +50 -0
  40. package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +124 -0
  41. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +361 -0
  42. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +174 -0
  43. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +172 -0
  44. package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +216 -0
  45. package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +167 -0
  46. package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +1 -0
  47. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +25 -0
  48. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +107 -0
  49. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +94 -0
  50. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootViewController.ts +182 -0
  51. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHView.ts +62 -0
  52. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewController.ts +262 -0
  53. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewRegistry.ts +19 -0
  54. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +267 -0
  55. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +15 -0
  56. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +25 -0
  57. package/harmony/gesture_handler/src/main/ets/rnoh/types.ts +25 -0
  58. package/harmony/gesture_handler/src/main/module.json5 +9 -0
  59. package/harmony/gesture_handler/src/main/resources/base/element/color.json +8 -0
  60. package/harmony/gesture_handler/src/main/resources/base/element/string.json +16 -0
  61. package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
  62. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -0
  63. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +16 -0
  64. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +16 -0
  65. package/harmony/gesture_handler/ts.ts +2 -0
  66. package/harmony/gesture_handler.har +0 -0
  67. package/lib/commonjs/RNGestureHandlerModule.js +3 -2
  68. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  69. package/lib/commonjs/components/GestureHandlerRootView.js +3 -3
  70. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  71. package/lib/commonjs/handlers/createHandler.js +18 -15
  72. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  73. package/lib/commonjs/index.js +36 -8
  74. package/lib/commonjs/index.js.map +1 -1
  75. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +2 -1
  76. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
  77. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +3 -2
  78. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  79. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +3 -2
  80. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  81. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  82. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  83. package/lib/module/handlers/createHandler.js +15 -12
  84. package/lib/module/handlers/createHandler.js.map +1 -1
  85. package/lib/module/index.js +5 -7
  86. package/lib/module/index.js.map +1 -1
  87. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
  88. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  89. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  90. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
  91. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  92. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  93. package/lib/typescript/index.d.ts +47 -42
  94. package/lib/typescript/index.d.ts.map +1 -1
  95. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
  96. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
  97. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
  98. package/package.json +78 -70
  99. package/src/RNGestureHandlerModule.ts +4 -4
  100. package/src/components/GestureHandlerRootView.tsx +23 -23
  101. package/src/handlers/createHandler.tsx +534 -534
  102. package/src/index.ts +172 -172
  103. package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
  104. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
  105. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
@@ -0,0 +1,106 @@
1
+ import { IncomingEvent } from './IncomingEvent';
2
+ import { CircularBuffer } from './CircularBuffer';
3
+ import { LeastSquareSolver } from './LeastSquareSolver';
4
+
5
+ export interface TrackerElement {
6
+ lastX: number;
7
+ lastY: number;
8
+ timeStamp: number;
9
+ velocityX: number;
10
+ velocityY: number;
11
+ }
12
+
13
+ export class VelocityTracker {
14
+ private assumePointerMoveStoppedMilliseconds = 40;
15
+ private historySize = 20;
16
+ private horizonMilliseconds = 300;
17
+ private minSampleSize = 3;
18
+
19
+ private samples: CircularBuffer<IncomingEvent>;
20
+
21
+ constructor() {
22
+ this.samples = new CircularBuffer<IncomingEvent>(this.historySize);
23
+ }
24
+
25
+ public add(event: IncomingEvent): void {
26
+ this.samples.push(event);
27
+ }
28
+
29
+ /// Returns an estimate of the velocity of the object being tracked by the
30
+ /// tracker given the current information available to the tracker.
31
+ ///
32
+ /// Information is added using [addPosition].
33
+ ///
34
+ /// Returns null if there is no data on which to base an estimate.
35
+ private getVelocityEstimate(): [number, number] | null {
36
+ const x = [];
37
+ const y = [];
38
+ const w = [];
39
+ const time = [];
40
+
41
+ let sampleCount = 0;
42
+ let index = this.samples.size - 1;
43
+ const newestSample = this.samples.get(index);
44
+ if (!newestSample) {
45
+ return null;
46
+ }
47
+
48
+ let previousSample = newestSample;
49
+
50
+ // Starting with the most recent PointAtTime sample, iterate backwards while
51
+ // the samples represent continuous motion.
52
+ while (sampleCount < this.samples.size) {
53
+ const sample = this.samples.get(index);
54
+
55
+ const age = newestSample.time - sample.time;
56
+ const delta = Math.abs(sample.time - previousSample.time);
57
+ previousSample = sample;
58
+
59
+ if (
60
+ age > this.horizonMilliseconds ||
61
+ delta > this.assumePointerMoveStoppedMilliseconds
62
+ ) {
63
+ break;
64
+ }
65
+
66
+ x.push(sample.x);
67
+ y.push(sample.y);
68
+ w.push(1);
69
+ time.push(-age);
70
+
71
+ sampleCount++;
72
+ index--;
73
+ }
74
+
75
+ if (sampleCount >= this.minSampleSize) {
76
+ const xSolver = new LeastSquareSolver(time, x, w);
77
+ const xFit = xSolver.solve(2);
78
+
79
+ if (xFit !== null) {
80
+ const ySolver = new LeastSquareSolver(time, y, w);
81
+ const yFit = ySolver.solve(2);
82
+
83
+ if (yFit !== null) {
84
+ const xVelocity = xFit.coefficients[1] * 1000;
85
+ const yVelocity = yFit.coefficients[1] * 1000;
86
+
87
+ return [xVelocity, yVelocity];
88
+ }
89
+ }
90
+ }
91
+
92
+ return null;
93
+ }
94
+
95
+ public getVelocity(): [number, number] {
96
+ const estimate = this.getVelocityEstimate();
97
+ if (estimate !== null) {
98
+ return estimate;
99
+ }
100
+ return [0, 0];
101
+ }
102
+
103
+ public reset(): void {
104
+ this.samples.clear();
105
+ }
106
+ }
@@ -0,0 +1,21 @@
1
+ export type Tag = number
2
+
3
+ export type BoundingBox = {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ };
9
+
10
+ export interface View {
11
+ getTag(): Tag
12
+
13
+ isPositionInBounds({x, y}: {
14
+ x: number;
15
+ y: number
16
+ }): boolean
17
+
18
+ getBoundingRect(): BoundingBox
19
+
20
+ hasButtonRole(): boolean
21
+ }
@@ -0,0 +1,7 @@
1
+ import { Tag, View } from "./View"
2
+
3
+ export interface ViewRegistry {
4
+ getViewByTag(viewTag: Tag): View | undefined
5
+ save(view: View): void
6
+ deleteByTag(viewTag: Tag): void
7
+ }
@@ -0,0 +1,15 @@
1
+ export * from "./OutgoingEventDispatcher"
2
+ export * from "./OutgoingEvent"
3
+ export * from "./RNGHLogger"
4
+ export * from "./View"
5
+ export * from "./Vector2D"
6
+ export * from "./GestureHandler"
7
+ export * from "./IncomingEvent"
8
+ export * from "./GestureHandlerOrchestrator"
9
+ export * from "./InteractionManager"
10
+ export * from "./PointerTracker"
11
+ export * from "./RNGHError"
12
+ export * from "./State"
13
+ export * from "./GestureHandlerRegistry"
14
+ export * from "./ViewRegistry"
15
+ export * from './Multiset'
@@ -0,0 +1,169 @@
1
+ import { DEFAULT_TOUCH_SLOP, IncomingEvent, EventType, PointerTracker } from '../core';
2
+
3
+ export interface ScaleGestureListener {
4
+ onScaleBegin: (detector: ScaleGestureDetector) => boolean;
5
+ onScale: (detector: ScaleGestureDetector) => boolean;
6
+ onScaleEnd: (detector: ScaleGestureDetector) => void;
7
+ }
8
+
9
+ export default class ScaleGestureDetector implements ScaleGestureListener {
10
+ public onScaleBegin: (detector: ScaleGestureDetector) => boolean;
11
+ public onScale: (detector: ScaleGestureDetector) => boolean;
12
+ public onScaleEnd: (detector: ScaleGestureDetector) => void;
13
+
14
+ private focusX!: number;
15
+ private focusY!: number;
16
+
17
+ private currentSpan!: number;
18
+ private prevSpan!: number;
19
+ private initialSpan!: number;
20
+
21
+ private currentTime!: number;
22
+ private prevTime!: number;
23
+
24
+ private inProgress = false;
25
+
26
+ private spanSlop: number;
27
+ private minSpan: number;
28
+
29
+ public constructor(callbacks: ScaleGestureListener) {
30
+ this.onScaleBegin = callbacks.onScaleBegin;
31
+ this.onScale = callbacks.onScale;
32
+ this.onScaleEnd = callbacks.onScaleEnd;
33
+
34
+ this.spanSlop = DEFAULT_TOUCH_SLOP * 2;
35
+ this.minSpan = 0;
36
+ }
37
+
38
+ public onTouchEvent(event: IncomingEvent, tracker: PointerTracker): boolean {
39
+ this.currentTime = event.time;
40
+
41
+ const action: EventType = event.eventType;
42
+ const numOfPointers = tracker.getTrackedPointersCount();
43
+
44
+ const streamComplete: boolean =
45
+ action === EventType.UP ||
46
+ action === EventType.ADDITIONAL_POINTER_UP ||
47
+ action === EventType.CANCEL;
48
+
49
+ if (action === EventType.DOWN || streamComplete) {
50
+ if (this.inProgress) {
51
+ this.onScaleEnd(this);
52
+ this.inProgress = false;
53
+ this.initialSpan = 0;
54
+ }
55
+
56
+ if (streamComplete) {
57
+ return true;
58
+ }
59
+ }
60
+
61
+ const configChanged: boolean =
62
+ action === EventType.DOWN ||
63
+ action === EventType.ADDITIONAL_POINTER_UP ||
64
+ action === EventType.ADDITIONAL_POINTER_DOWN;
65
+
66
+ const pointerUp = action === EventType.ADDITIONAL_POINTER_UP;
67
+
68
+ const ignoredPointer: number | undefined = pointerUp
69
+ ? event.pointerId
70
+ : undefined;
71
+
72
+ //Determine focal point
73
+
74
+ const div: number = pointerUp ? numOfPointers - 1 : numOfPointers;
75
+
76
+ const sumX = tracker.getSumX(ignoredPointer);
77
+ const sumY = tracker.getSumY(ignoredPointer);
78
+
79
+ const focusX = sumX / div;
80
+ const focusY = sumY / div;
81
+
82
+ //Determine average deviation from focal point
83
+
84
+ let devSumX = 0;
85
+ let devSumY = 0;
86
+
87
+ tracker.getData().forEach((value, key) => {
88
+ if (key === ignoredPointer) {
89
+ return;
90
+ }
91
+
92
+ devSumX += Math.abs(value.lastX - focusX);
93
+ devSumY += Math.abs(value.lastY - focusY);
94
+ });
95
+
96
+ const devX: number = devSumX / div;
97
+ const devY: number = devSumY / div;
98
+
99
+ const spanX: number = devX * 2;
100
+ const spanY: number = devY * 2;
101
+
102
+ const span = Math.hypot(spanX, spanY);
103
+
104
+ //Begin/end events
105
+ const wasInProgress: boolean = this.inProgress;
106
+ this.focusX = focusX;
107
+ this.focusY = focusY;
108
+
109
+ if (this.inProgress && (span < this.minSpan || configChanged)) {
110
+ this.onScaleEnd(this);
111
+ this.inProgress = false;
112
+ this.initialSpan = span;
113
+ }
114
+
115
+ if (configChanged) {
116
+ this.initialSpan = this.prevSpan = this.currentSpan = span;
117
+ }
118
+
119
+ if (
120
+ !this.inProgress &&
121
+ span >= this.minSpan &&
122
+ (wasInProgress || Math.abs(span - this.initialSpan) > this.spanSlop)
123
+ ) {
124
+ this.prevSpan = this.currentSpan = span;
125
+ this.prevTime = this.currentTime;
126
+ this.inProgress = this.onScaleBegin(this);
127
+ }
128
+
129
+ //Handle motion
130
+ if (action !== EventType.MOVE) {
131
+ return true;
132
+ }
133
+
134
+ this.currentSpan = span;
135
+
136
+ if (this.inProgress && !this.onScale(this)) {
137
+ return true;
138
+ }
139
+
140
+ this.prevSpan = this.currentSpan;
141
+ this.prevTime = this.currentTime;
142
+
143
+ return true;
144
+ }
145
+
146
+ public getCurrentSpan(): number {
147
+ return this.currentSpan;
148
+ }
149
+
150
+ public getFocusX(): number {
151
+ return this.focusX;
152
+ }
153
+
154
+ public getFocusY(): number {
155
+ return this.focusY;
156
+ }
157
+
158
+ public getTimeDelta(): number {
159
+ return this.currentTime - this.prevTime;
160
+ }
161
+
162
+ public getScaleFactor(numOfPointers: number): number {
163
+ if (numOfPointers < 2) {
164
+ return 1;
165
+ }
166
+
167
+ return this.prevSpan > 0 ? this.currentSpan / this.prevSpan : 1;
168
+ }
169
+ }
@@ -0,0 +1,219 @@
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.cloneAndJoinPrefix("FlingGestureHandler") })
32
+ }
33
+
34
+ override getName(): string {
35
+ return "FlingGestureHandler"
36
+ }
37
+
38
+ override isGestureContinuous(): boolean {
39
+ return true
40
+ }
41
+
42
+ getDefaultConfig() {
43
+ return {}
44
+ }
45
+
46
+ private get direction(): Directions {
47
+ return this.config.direction ?? DEFAULT_DIRECTION
48
+ }
49
+
50
+ private get numberOfPointersRequired() {
51
+ return this.config.numberOfPointers ?? DEFAULT_NUMBER_OF_TOUCHES_REQUIRED
52
+ }
53
+
54
+ private get maxDurationMs() {
55
+ return this.config.maxDurationMs ?? DEFAULT_MAX_DURATION_MS
56
+ }
57
+
58
+ private get minVelocity() {
59
+ return this.config.minVelocity ?? DEFAULT_MIN_VELOCITY
60
+ }
61
+
62
+ private delayTimeout!: number;
63
+ private maxNumberOfPointersSimultaneously = 0;
64
+ private keyPointer = NaN;
65
+
66
+ private startFling(): void {
67
+ this.logger.info("startFling")
68
+ this.begin();
69
+
70
+ this.maxNumberOfPointersSimultaneously = 1;
71
+
72
+ this.delayTimeout = setTimeout(() => this.fail(), this.maxDurationMs);
73
+ }
74
+
75
+ private tryEndFling(): boolean {
76
+ const logger = this.logger.cloneAndJoinPrefix("tryEndFling")
77
+ const velocityVector = this.tracker.getVelocity(this.keyPointer);
78
+
79
+ const getAlignment = (
80
+ direction: Directions | DiagonalDirections,
81
+ minimalAlignmentCosine: number
82
+ ) => {
83
+ return (
84
+ (direction & this.direction) === direction &&
85
+ velocityVector.computeCosine(
86
+ Vector2D.fromDirection(direction),
87
+ ) > minimalAlignmentCosine
88
+ );
89
+ };
90
+
91
+ const axialDirectionsList = Object.values(Directions);
92
+ const diagonalDirectionsList = Object.values(DiagonalDirections);
93
+
94
+ // list of alignments to all activated directions
95
+ const axialAlignmentList = axialDirectionsList.map((direction) =>
96
+ getAlignment(direction, AXIAL_DEVIATION_COSINE)
97
+ );
98
+
99
+ const diagonalAlignmentList = diagonalDirectionsList.map((direction) =>
100
+ getAlignment(direction, DIAGONAL_DEVIATION_COSINE)
101
+ );
102
+
103
+ const isAligned =
104
+ axialAlignmentList.some(Boolean) || diagonalAlignmentList.some(Boolean);
105
+
106
+ const isFast = velocityVector.magnitude > this.minVelocity;
107
+
108
+ if (
109
+ this.maxNumberOfPointersSimultaneously ===
110
+ this.numberOfPointersRequired &&
111
+ isAligned &&
112
+ isFast
113
+ ) {
114
+ clearTimeout(this.delayTimeout);
115
+ this.activate();
116
+
117
+ return true;
118
+ }
119
+
120
+ return false;
121
+ }
122
+
123
+ private endFling() {
124
+ this.logger.info("endFling")
125
+ if (!this.tryEndFling()) {
126
+ this.fail();
127
+ }
128
+ }
129
+
130
+ public onPointerDown(event: IncomingEvent): void {
131
+ this.tracker.addToTracker(event);
132
+ this.keyPointer = event.pointerId;
133
+
134
+ super.onPointerDown(event);
135
+ this.newPointerAction();
136
+ }
137
+
138
+ public onAdditionalPointerAdd(event: IncomingEvent): void {
139
+ this.tracker.addToTracker(event);
140
+ super.onAdditionalPointerAdd(event);
141
+ this.newPointerAction();
142
+ }
143
+
144
+ private newPointerAction(): void {
145
+ if (this.currentState === State.UNDETERMINED) {
146
+ this.startFling();
147
+ }
148
+
149
+ if (this.currentState !== State.BEGAN) {
150
+ return;
151
+ }
152
+
153
+ this.tryEndFling();
154
+
155
+ if (
156
+ this.tracker.getTrackedPointersCount() >
157
+ this.maxNumberOfPointersSimultaneously
158
+ ) {
159
+ this.maxNumberOfPointersSimultaneously =
160
+ this.tracker.getTrackedPointersCount();
161
+ }
162
+ }
163
+
164
+ private pointerMoveAction(event: IncomingEvent): void {
165
+ this.logger.cloneAndJoinPrefix("pointerMoveAction").info(JSON.stringify(event))
166
+ this.tracker.track(event);
167
+
168
+ if (this.currentState !== State.BEGAN) {
169
+ return;
170
+ }
171
+
172
+ this.tryEndFling();
173
+ }
174
+
175
+ public onPointerMove(event: IncomingEvent): void {
176
+ this.pointerMoveAction(event);
177
+ super.onPointerMove(event);
178
+ }
179
+
180
+ public onPointerOutOfBounds(event: IncomingEvent): void {
181
+ this.pointerMoveAction(event);
182
+ super.onPointerOutOfBounds(event);
183
+ }
184
+
185
+ public onPointerUp(event: IncomingEvent): void {
186
+ super.onPointerUp(event);
187
+ this.onUp(event);
188
+
189
+ this.keyPointer = NaN;
190
+ }
191
+
192
+ public onAdditionalPointerRemove(event: IncomingEvent): void {
193
+ super.onAdditionalPointerRemove(event);
194
+ this.onUp(event);
195
+ }
196
+
197
+ private onUp(event: IncomingEvent): void {
198
+ const logger = this.logger.cloneAndJoinPrefix("onUp")
199
+ logger.info("start")
200
+ if (this.currentState === State.BEGAN) {
201
+ this.endFling();
202
+ }
203
+ logger.info(`removeFromTracker: pointerId=${event.pointerId}`)
204
+ this.tracker.removeFromTracker(event.pointerId);
205
+ }
206
+
207
+ public activate(): void {
208
+ super.activate();
209
+ this.end();
210
+ }
211
+ }
212
+
213
+ function coneToDeviation(degrees: number) {
214
+ return Math.cos(degToRad(degrees / 2));
215
+ }
216
+
217
+ function degToRad(degrees: number) {
218
+ return (degrees * Math.PI) / 180;
219
+ }
@@ -0,0 +1,67 @@
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,
26
+ private interactionManager: InteractionManager, private rnGestureResponder: RNGestureResponder) {
27
+ this.logger = cleanLogger.cloneAndJoinPrefix("GestureHandlerFactory")
28
+ this.orchestrator = new GestureHandlerOrchestrator(cleanLogger)
29
+ }
30
+
31
+ create(handlerName: string, handlerTag: number): GestureHandler {
32
+ this.logger.cloneAndJoinPrefix(`create`).debug(`(handlerName=${handlerName}, handlerTag=${handlerTag})`);
33
+
34
+ const deps: GestureHandlerDependencies = {
35
+ tracker: new PointerTracker(),
36
+ orchestrator: this.orchestrator,
37
+ handlerTag,
38
+ interactionManager: this.interactionManager,
39
+ logger: this.cleanLogger,
40
+ scrollLocker: this.scrollLocker,
41
+ rnGestureResponder: this.rnGestureResponder,
42
+ }
43
+ switch (handlerName) {
44
+ case "TapGestureHandler":
45
+ return new TapGestureHandler(deps)
46
+ case "PanGestureHandler":
47
+ return new PanGestureHandler(deps)
48
+ case "PinchGestureHandler":
49
+ return new PinchGestureHandler(deps)
50
+ case "NativeViewGestureHandler":
51
+ return new NativeViewGestureHandler(deps)
52
+ case "ManualGestureHandler":
53
+ return new ManualGestureHandler(deps)
54
+ case "LongPressGestureHandler":
55
+ return new LongPressGestureHandler(deps)
56
+ case "FlingGestureHandler":
57
+ return new FlingGestureHandler(deps)
58
+ case "RotationGestureHandler":
59
+ return new RotationGestureHandler(deps)
60
+ default:
61
+ const msg = `Unknown handler type: ${handlerName}`
62
+ this.logger.info(msg)
63
+ throw new RNGHError(msg)
64
+ }
65
+
66
+ }
67
+ }