@react-native-oh-tpl/react-native-gesture-handler 2.12.6-1 → 2.12.9-1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. package/harmony/gesture_handler/BuildProfile.ets +6 -0
  2. package/harmony/gesture_handler/build-profile.json5 +18 -7
  3. package/harmony/gesture_handler/hvigorfile.ts +2 -2
  4. package/harmony/gesture_handler/index.ets +3 -3
  5. package/harmony/gesture_handler/oh-package-lock.json5 +18 -0
  6. package/harmony/gesture_handler/oh-package.json5 +12 -11
  7. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -8
  8. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +103 -34
  9. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +21 -15
  10. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +36 -60
  11. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentInstance.h +27 -0
  12. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +32 -0
  13. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +22 -17
  14. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +15 -12
  15. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +72 -0
  16. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +36 -60
  17. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +123 -0
  18. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +25 -0
  19. package/harmony/gesture_handler/src/main/ets/CircularBuffer.ts +42 -42
  20. package/harmony/gesture_handler/src/main/ets/Event.ts +67 -67
  21. package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +52 -37
  22. package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +663 -663
  23. package/harmony/gesture_handler/src/main/ets/{GestureHandlerArkUIAdapter.ets → GestureHandlerArkUIAdapter.ts} +202 -201
  24. package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +44 -44
  25. package/harmony/gesture_handler/src/main/ets/GestureHandlerOrchestrator.ts +280 -280
  26. package/harmony/gesture_handler/src/main/ets/GestureHandlerPackage.ts +22 -22
  27. package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +27 -27
  28. package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +108 -108
  29. package/harmony/gesture_handler/src/main/ets/LeastSquareSolver.ts +182 -182
  30. package/harmony/gesture_handler/src/main/ets/NativeViewGestureHandler.ts +114 -114
  31. package/harmony/gesture_handler/src/main/ets/OutgoingEvent.ts +33 -33
  32. package/harmony/gesture_handler/src/main/ets/PanGestureHandler.ts +327 -327
  33. package/harmony/gesture_handler/src/main/ets/PointerTracker.ts +239 -239
  34. package/harmony/gesture_handler/src/main/ets/RNGHError.ts +4 -4
  35. package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +47 -28
  36. package/harmony/gesture_handler/src/main/ets/{RNGHRootTouchHandler.ets → RNGHRootTouchHandlerArkTS.ts} +59 -57
  37. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +87 -0
  38. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerButton.ets +37 -36
  39. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +183 -125
  40. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +52 -55
  41. package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +23 -11
  42. package/harmony/gesture_handler/src/main/ets/State.ts +46 -46
  43. package/harmony/gesture_handler/src/main/ets/TapGestureHandler.ts +205 -205
  44. package/harmony/gesture_handler/src/main/ets/Vector2D.ts +36 -36
  45. package/harmony/gesture_handler/src/main/ets/VelocityTracker.ts +98 -98
  46. package/harmony/gesture_handler/src/main/ets/View.ts +70 -70
  47. package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +42 -42
  48. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerButton.ts +140 -0
  49. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +25 -0
  50. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerRootView.ts +101 -0
  51. package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +3 -0
  52. package/harmony/gesture_handler/src/main/ets/pages/Index.ets +16 -16
  53. package/harmony/gesture_handler/src/main/ets/types.ts +25 -0
  54. package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +41 -41
  55. package/harmony/gesture_handler/src/main/module.json5 +7 -7
  56. package/harmony/gesture_handler/src/main/resources/base/element/color.json +7 -7
  57. package/harmony/gesture_handler/src/main/resources/base/element/string.json +15 -15
  58. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -5
  59. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +15 -15
  60. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +15 -15
  61. package/harmony/gesture_handler/ts.ts +2 -1
  62. package/harmony/gesture_handler.har +0 -0
  63. package/lib/commonjs/RNGestureHandlerModule.js +6 -3
  64. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  65. package/lib/commonjs/components/GestureHandlerRootView.js +5 -13
  66. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  67. package/lib/commonjs/handlers/createHandler.js +31 -28
  68. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  69. package/lib/commonjs/index.js +42 -19
  70. package/lib/commonjs/index.js.map +1 -1
  71. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +10 -0
  72. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
  73. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +11 -0
  74. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
  75. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +11 -0
  76. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
  77. package/lib/module/RNGestureHandlerModule.js +3 -2
  78. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  79. package/lib/module/components/GestureHandlerRootView.js +3 -11
  80. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  81. package/lib/module/handlers/createHandler.js +20 -19
  82. package/lib/module/handlers/createHandler.js.map +1 -1
  83. package/lib/module/index.js +6 -14
  84. package/lib/module/index.js.map +1 -1
  85. package/lib/module/specs/NativeRNGestureHandlerModule.js +3 -0
  86. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -0
  87. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js +3 -0
  88. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
  89. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js +3 -0
  90. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
  91. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -6
  92. package/lib/typescript/RNGestureHandlerModule.d.ts.map +1 -1
  93. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  94. package/lib/typescript/components/GestureHandlerRootView.d.ts.map +1 -1
  95. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  96. package/lib/typescript/handlers/createHandler.d.ts.map +1 -1
  97. package/lib/typescript/index.d.ts +9 -8
  98. package/lib/typescript/index.d.ts.map +1 -1
  99. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +15 -0
  100. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts.map +1 -0
  101. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +15 -0
  102. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts.map +1 -0
  103. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +7 -0
  104. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -0
  105. package/package.json +66 -70
  106. package/src/RNGestureHandlerModule.ts +5 -6
  107. package/src/components/GestureHandlerRootView.tsx +23 -34
  108. package/src/handlers/createHandler.tsx +534 -535
  109. package/src/index.ts +172 -172
  110. package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
  111. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -0
  112. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -0
  113. package/README.md +0 -1
  114. package/lib/commonjs/components/GestureButtons.js +0 -186
  115. package/lib/commonjs/components/GestureButtons.js.map +0 -1
  116. package/lib/commonjs/components/GestureHandlerButton.js +0 -9
  117. package/lib/commonjs/components/GestureHandlerButton.js.map +0 -1
  118. package/lib/commonjs/components/RNGestureHandlerButton.js +0 -23
  119. package/lib/commonjs/components/RNGestureHandlerButton.js.map +0 -1
  120. package/lib/commonjs/components/touchables/GenericTouchable.js +0 -247
  121. package/lib/commonjs/components/touchables/GenericTouchable.js.map +0 -1
  122. package/lib/commonjs/components/touchables/TouchableOpacity.js +0 -58
  123. package/lib/commonjs/components/touchables/TouchableOpacity.js.map +0 -1
  124. package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js +0 -18
  125. package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js.map +0 -1
  126. package/lib/commonjs/components/touchables/index.js +0 -21
  127. package/lib/commonjs/components/touchables/index.js.map +0 -1
  128. package/lib/commonjs/handlers/NativeViewGestureHandler.js +0 -19
  129. package/lib/commonjs/handlers/NativeViewGestureHandler.js.map +0 -1
  130. package/lib/commonjs/handlers/PanGestureHandler.js +0 -103
  131. package/lib/commonjs/handlers/PanGestureHandler.js.map +0 -1
  132. package/lib/commonjs/handlers/TapGestureHandler.js +0 -22
  133. package/lib/commonjs/handlers/TapGestureHandler.js.map +0 -1
  134. package/lib/commonjs/handlers/createNativeWrapper.js +0 -64
  135. package/lib/commonjs/handlers/createNativeWrapper.js.map +0 -1
  136. package/lib/commonjs/handlers/gestureHandlerCommon.js +0 -22
  137. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +0 -1
  138. package/lib/commonjs/handlers/gestures/GestureDetector.js +0 -554
  139. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +0 -1
  140. package/lib/commonjs/init.js +0 -24
  141. package/lib/commonjs/init.js.map +0 -1
  142. package/lib/module/components/GestureButtons.js +0 -168
  143. package/lib/module/components/GestureButtons.js.map +0 -1
  144. package/lib/module/components/GestureHandlerButton.js +0 -3
  145. package/lib/module/components/GestureHandlerButton.js.map +0 -1
  146. package/lib/module/components/RNGestureHandlerButton.js +0 -17
  147. package/lib/module/components/RNGestureHandlerButton.js.map +0 -1
  148. package/lib/module/components/touchables/GenericTouchable.js +0 -238
  149. package/lib/module/components/touchables/GenericTouchable.js.map +0 -1
  150. package/lib/module/components/touchables/TouchableOpacity.js +0 -49
  151. package/lib/module/components/touchables/TouchableOpacity.js.map +0 -1
  152. package/lib/module/components/touchables/TouchableWithoutFeedback.js +0 -9
  153. package/lib/module/components/touchables/TouchableWithoutFeedback.js.map +0 -1
  154. package/lib/module/components/touchables/index.js +0 -8
  155. package/lib/module/components/touchables/index.js.map +0 -1
  156. package/lib/module/handlers/NativeViewGestureHandler.js +0 -12
  157. package/lib/module/handlers/NativeViewGestureHandler.js.map +0 -1
  158. package/lib/module/handlers/PanGestureHandler.js +0 -92
  159. package/lib/module/handlers/PanGestureHandler.js.map +0 -1
  160. package/lib/module/handlers/TapGestureHandler.js +0 -14
  161. package/lib/module/handlers/TapGestureHandler.js.map +0 -1
  162. package/lib/module/handlers/createNativeWrapper.js +0 -57
  163. package/lib/module/handlers/createNativeWrapper.js.map +0 -1
  164. package/lib/module/handlers/gestureHandlerCommon.js +0 -15
  165. package/lib/module/handlers/gestureHandlerCommon.js.map +0 -1
  166. package/lib/module/handlers/gestures/GestureDetector.js +0 -543
  167. package/lib/module/handlers/gestures/GestureDetector.js.map +0 -1
  168. package/lib/module/init.js +0 -17
  169. package/lib/module/init.js.map +0 -1
  170. package/lib/typescript/components/GestureButtons.d.ts +0 -122
  171. package/lib/typescript/components/GestureButtons.d.ts.map +0 -1
  172. package/lib/typescript/components/GestureHandlerButton.d.ts +0 -5
  173. package/lib/typescript/components/GestureHandlerButton.d.ts.map +0 -1
  174. package/lib/typescript/components/RNGestureHandlerButton.d.ts +0 -2
  175. package/lib/typescript/components/RNGestureHandlerButton.d.ts.map +0 -1
  176. package/lib/typescript/components/touchables/GenericTouchable.d.ts +0 -68
  177. package/lib/typescript/components/touchables/GenericTouchable.d.ts.map +0 -1
  178. package/lib/typescript/components/touchables/TouchableOpacity.d.ts +0 -26
  179. package/lib/typescript/components/touchables/TouchableOpacity.d.ts.map +0 -1
  180. package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts +0 -8
  181. package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts.map +0 -1
  182. package/lib/typescript/components/touchables/index.d.ts +0 -4
  183. package/lib/typescript/components/touchables/index.d.ts.map +0 -1
  184. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +0 -29
  185. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts.map +0 -1
  186. package/lib/typescript/handlers/PanGestureHandler.d.ts +0 -140
  187. package/lib/typescript/handlers/PanGestureHandler.d.ts.map +0 -1
  188. package/lib/typescript/handlers/TapGestureHandler.d.ts +0 -58
  189. package/lib/typescript/handlers/TapGestureHandler.d.ts.map +0 -1
  190. package/lib/typescript/handlers/createNativeWrapper.d.ts +0 -4
  191. package/lib/typescript/handlers/createNativeWrapper.d.ts.map +0 -1
  192. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +0 -2
  193. package/lib/typescript/handlers/gestureHandlerCommon.d.ts.map +0 -1
  194. package/lib/typescript/handlers/gestures/GestureDetector.d.ts +0 -24
  195. package/lib/typescript/handlers/gestures/GestureDetector.d.ts.map +0 -1
  196. package/lib/typescript/init.d.ts +0 -3
  197. package/lib/typescript/init.d.ts.map +0 -1
  198. package/src/components/GestureButtons.tsx +0 -334
  199. package/src/components/GestureHandlerButton.tsx +0 -5
  200. package/src/components/RNGestureHandlerButton.tsx +0 -23
  201. package/src/components/touchables/GenericTouchable.tsx +0 -301
  202. package/src/components/touchables/TouchableOpacity.tsx +0 -76
  203. package/src/components/touchables/TouchableWithoutFeedback.tsx +0 -14
  204. package/src/components/touchables/index.ts +0 -7
  205. package/src/handlers/NativeViewGestureHandler.ts +0 -55
  206. package/src/handlers/PanGestureHandler.ts +0 -327
  207. package/src/handlers/TapGestureHandler.ts +0 -95
  208. package/src/handlers/createNativeWrapper.tsx +0 -81
  209. package/src/handlers/gestureHandlerCommon.ts +0 -15
  210. package/src/handlers/gestures/GestureDetector.tsx +0 -823
  211. package/src/init.ts +0 -18
@@ -1,328 +1,328 @@
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
- }
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
328
  }