@react-native-oh-tpl/react-native-gesture-handler 2.14.1-2.14.8 → 2.14.1-2.14.9

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