@react-native-oh-tpl/react-native-gesture-handler 2.12.6-1 → 2.12.6-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/harmony/gesture_handler/LICENSE +21 -0
- package/harmony/gesture_handler/OAT.xml +44 -0
- package/harmony/gesture_handler/README.OpenSource +11 -0
- package/harmony/gesture_handler/README.md +1 -0
- package/harmony/gesture_handler/build-profile.json5 +7 -7
- package/harmony/gesture_handler/hvigorfile.ts +2 -2
- package/harmony/gesture_handler/index.ets +2 -2
- package/harmony/gesture_handler/oh-package.json5 +13 -11
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -8
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +33 -33
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +14 -14
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +60 -60
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +17 -17
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +11 -11
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +60 -60
- package/harmony/gesture_handler/src/main/ets/CircularBuffer.ts +42 -42
- package/harmony/gesture_handler/src/main/ets/Event.ts +67 -67
- package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +37 -37
- package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +663 -663
- package/harmony/gesture_handler/src/main/ets/GestureHandlerArkUIAdapter.ets +201 -201
- package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +44 -44
- package/harmony/gesture_handler/src/main/ets/GestureHandlerOrchestrator.ts +280 -280
- package/harmony/gesture_handler/src/main/ets/GestureHandlerPackage.ts +22 -22
- package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +27 -27
- package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +108 -108
- package/harmony/gesture_handler/src/main/ets/LeastSquareSolver.ts +182 -182
- package/harmony/gesture_handler/src/main/ets/NativeViewGestureHandler.ts +114 -114
- package/harmony/gesture_handler/src/main/ets/OutgoingEvent.ts +33 -33
- package/harmony/gesture_handler/src/main/ets/PanGestureHandler.ts +327 -327
- package/harmony/gesture_handler/src/main/ets/PointerTracker.ts +239 -239
- package/harmony/gesture_handler/src/main/ets/RNGHError.ts +4 -4
- package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +28 -28
- package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandler.ets +57 -57
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerButton.ets +36 -36
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +125 -125
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +56 -55
- package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +10 -10
- package/harmony/gesture_handler/src/main/ets/State.ts +46 -46
- package/harmony/gesture_handler/src/main/ets/TapGestureHandler.ts +205 -205
- package/harmony/gesture_handler/src/main/ets/Vector2D.ts +36 -36
- package/harmony/gesture_handler/src/main/ets/VelocityTracker.ts +98 -98
- package/harmony/gesture_handler/src/main/ets/View.ts +70 -70
- package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +42 -42
- package/harmony/gesture_handler/src/main/ets/pages/Index.ets +16 -16
- package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +41 -41
- package/harmony/gesture_handler/src/main/module.json5 +6 -6
- package/harmony/gesture_handler/src/main/resources/base/element/color.json +7 -7
- package/harmony/gesture_handler/src/main/resources/base/element/string.json +15 -15
- package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -5
- package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +15 -15
- package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +15 -15
- package/harmony/gesture_handler.har +0 -0
- package/lib/commonjs/components/touchables/GenericTouchable.js +9 -9
- package/lib/commonjs/components/touchables/TouchableOpacity.js +2 -2
- package/lib/commonjs/handlers/createNativeWrapper.js +6 -6
- package/lib/commonjs/handlers/gestures/GestureDetector.js +3 -3
- package/lib/module/components/touchables/GenericTouchable.js +9 -9
- package/lib/module/components/touchables/TouchableOpacity.js +2 -2
- package/lib/module/handlers/createNativeWrapper.js +6 -6
- package/lib/module/handlers/gestures/GestureDetector.js +3 -3
- package/package.json +70 -70
- package/src/RNGestureHandlerModule.ts +6 -6
- package/src/components/GestureButtons.tsx +334 -334
- package/src/components/GestureHandlerButton.tsx +5 -5
- package/src/components/GestureHandlerRootView.tsx +34 -34
- package/src/components/RNGestureHandlerButton.tsx +23 -23
- package/src/components/touchables/GenericTouchable.tsx +301 -301
- package/src/components/touchables/TouchableOpacity.tsx +76 -76
- package/src/components/touchables/TouchableWithoutFeedback.tsx +14 -14
- package/src/components/touchables/index.ts +7 -7
- package/src/handlers/NativeViewGestureHandler.ts +55 -55
- package/src/handlers/PanGestureHandler.ts +327 -327
- package/src/handlers/TapGestureHandler.ts +95 -95
- package/src/handlers/createHandler.tsx +535 -535
- package/src/handlers/createNativeWrapper.tsx +81 -81
- package/src/handlers/gestureHandlerCommon.ts +15 -15
- package/src/handlers/gestures/GestureDetector.tsx +823 -823
- package/src/index.ts +172 -172
- package/src/init.ts +18 -18
|
@@ -1,327 +1,327 @@
|
|
|
1
|
-
// RNGH: patching to replace `createHandler`
|
|
2
|
-
|
|
3
|
-
import createHandler from './createHandler'; // RNGH: using local create handler
|
|
4
|
-
import {
|
|
5
|
-
BaseGestureHandlerProps,
|
|
6
|
-
baseGestureHandlerProps,
|
|
7
|
-
} from 'react-native-gesture-handler/src/handlers/gestureHandlerCommon';
|
|
8
|
-
|
|
9
|
-
export const panGestureHandlerProps = [
|
|
10
|
-
'activeOffsetY',
|
|
11
|
-
'activeOffsetX',
|
|
12
|
-
'failOffsetY',
|
|
13
|
-
'failOffsetX',
|
|
14
|
-
'minDist',
|
|
15
|
-
'minVelocity',
|
|
16
|
-
'minVelocityX',
|
|
17
|
-
'minVelocityY',
|
|
18
|
-
'minPointers',
|
|
19
|
-
'maxPointers',
|
|
20
|
-
'avgTouches',
|
|
21
|
-
'enableTrackpadTwoFingerGesture',
|
|
22
|
-
'activateAfterLongPress',
|
|
23
|
-
] as const;
|
|
24
|
-
|
|
25
|
-
export const panGestureHandlerCustomNativeProps = [
|
|
26
|
-
'activeOffsetYStart',
|
|
27
|
-
'activeOffsetYEnd',
|
|
28
|
-
'activeOffsetXStart',
|
|
29
|
-
'activeOffsetXEnd',
|
|
30
|
-
'failOffsetYStart',
|
|
31
|
-
'failOffsetYEnd',
|
|
32
|
-
'failOffsetXStart',
|
|
33
|
-
'failOffsetXEnd',
|
|
34
|
-
] as const;
|
|
35
|
-
|
|
36
|
-
export type PanGestureHandlerEventPayload = {
|
|
37
|
-
/**
|
|
38
|
-
* X coordinate of the current position of the pointer (finger or a leading
|
|
39
|
-
* pointer when there are multiple fingers placed) relative to the view
|
|
40
|
-
* attached to the handler. Expressed in point units.
|
|
41
|
-
*/
|
|
42
|
-
x: number;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Y coordinate of the current position of the pointer (finger or a leading
|
|
46
|
-
* pointer when there are multiple fingers placed) relative to the view
|
|
47
|
-
* attached to the handler. Expressed in point units.
|
|
48
|
-
*/
|
|
49
|
-
y: number;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* X coordinate of the current position of the pointer (finger or a leading
|
|
53
|
-
* pointer when there are multiple fingers placed) relative to the window.
|
|
54
|
-
* The value is expressed in point units. It is recommended to use it instead
|
|
55
|
-
* of `x` in cases when the original view can be transformed as an effect of
|
|
56
|
-
* the gesture.
|
|
57
|
-
*/
|
|
58
|
-
absoluteX: number;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Y coordinate of the current position of the pointer (finger or a leading
|
|
62
|
-
* pointer when there are multiple fingers placed) relative to the window.
|
|
63
|
-
* The value is expressed in point units. It is recommended to use it instead
|
|
64
|
-
* of `y` in cases when the original view can be transformed as an
|
|
65
|
-
* effect of the gesture.
|
|
66
|
-
*/
|
|
67
|
-
absoluteY: number;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Translation of the pan gesture along X axis accumulated over the time of
|
|
71
|
-
* the gesture. The value is expressed in the point units.
|
|
72
|
-
*/
|
|
73
|
-
translationX: number;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Translation of the pan gesture along Y axis accumulated over the time of
|
|
77
|
-
* the gesture. The value is expressed in the point units.
|
|
78
|
-
*/
|
|
79
|
-
translationY: number;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Velocity of the pan gesture along the X axis in the current moment. The
|
|
83
|
-
* value is expressed in point units per second.
|
|
84
|
-
*/
|
|
85
|
-
velocityX: number;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Velocity of the pan gesture along the Y axis in the current moment. The
|
|
89
|
-
* value is expressed in point units per second.
|
|
90
|
-
*/
|
|
91
|
-
velocityY: number;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
interface CommonPanProperties {
|
|
95
|
-
/**
|
|
96
|
-
* Minimum distance the finger (or multiple finger) need to travel before the
|
|
97
|
-
* handler activates. Expressed in points.
|
|
98
|
-
*/
|
|
99
|
-
minDist?: number;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Android only.
|
|
103
|
-
*/
|
|
104
|
-
avgTouches?: boolean;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Enables two-finger gestures on supported devices, for example iPads with
|
|
108
|
-
* trackpads. If not enabled the gesture will require click + drag, with
|
|
109
|
-
* enableTrackpadTwoFingerGesture swiping with two fingers will also trigger
|
|
110
|
-
* the gesture.
|
|
111
|
-
*/
|
|
112
|
-
enableTrackpadTwoFingerGesture?: boolean;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* A number of fingers that is required to be placed before handler can
|
|
116
|
-
* activate. Should be a higher or equal to 0 integer.
|
|
117
|
-
*/
|
|
118
|
-
minPointers?: number;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* When the given number of fingers is placed on the screen and handler hasn't
|
|
122
|
-
* yet activated it will fail recognizing the gesture. Should be a higher or
|
|
123
|
-
* equal to 0 integer.
|
|
124
|
-
*/
|
|
125
|
-
maxPointers?: number;
|
|
126
|
-
|
|
127
|
-
minVelocity?: number;
|
|
128
|
-
minVelocityX?: number;
|
|
129
|
-
minVelocityY?: number;
|
|
130
|
-
activateAfterLongPress?: number;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export interface PanGestureConfig extends CommonPanProperties {
|
|
134
|
-
activeOffsetYStart?: number;
|
|
135
|
-
activeOffsetYEnd?: number;
|
|
136
|
-
activeOffsetXStart?: number;
|
|
137
|
-
activeOffsetXEnd?: number;
|
|
138
|
-
failOffsetYStart?: number;
|
|
139
|
-
failOffsetYEnd?: number;
|
|
140
|
-
failOffsetXStart?: number;
|
|
141
|
-
failOffsetXEnd?: number;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export interface PanGestureHandlerProps
|
|
145
|
-
extends BaseGestureHandlerProps<PanGestureHandlerEventPayload>,
|
|
146
|
-
CommonPanProperties {
|
|
147
|
-
/**
|
|
148
|
-
* Range along X axis (in points) where fingers travels without activation of
|
|
149
|
-
* handler. Moving outside of this range implies activation of handler. Range
|
|
150
|
-
* can be given as an array or a single number. If range is set as an array,
|
|
151
|
-
* first value must be lower or equal to 0, a the second one higher or equal
|
|
152
|
-
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
|
|
153
|
-
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
|
|
154
|
-
*/
|
|
155
|
-
activeOffsetY?: number | number[];
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Range along X axis (in points) where fingers travels without activation of
|
|
159
|
-
* handler. Moving outside of this range implies activation of handler. Range
|
|
160
|
-
* can be given as an array or a single number. If range is set as an array,
|
|
161
|
-
* first value must be lower or equal to 0, a the second one higher or equal
|
|
162
|
-
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
|
|
163
|
-
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
|
|
164
|
-
*/
|
|
165
|
-
activeOffsetX?: number | number[];
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* When the finger moves outside this range (in points) along Y axis and
|
|
169
|
-
* handler hasn't yet activated it will fail recognizing the gesture. Range
|
|
170
|
-
* can be given as an array or a single number. If range is set as an array,
|
|
171
|
-
* first value must be lower or equal to 0, a the second one higher or equal
|
|
172
|
-
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
|
|
173
|
-
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
|
|
174
|
-
*/
|
|
175
|
-
failOffsetY?: number | number[];
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* When the finger moves outside this range (in points) along X axis and
|
|
179
|
-
* handler hasn't yet activated it will fail recognizing the gesture. Range
|
|
180
|
-
* can be given as an array or a single number. If range is set as an array,
|
|
181
|
-
* first value must be lower or equal to 0, a the second one higher or equal
|
|
182
|
-
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
|
|
183
|
-
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
|
|
184
|
-
*/
|
|
185
|
-
failOffsetX?: number | number[];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export const panHandlerName = 'PanGestureHandler';
|
|
189
|
-
|
|
190
|
-
export type PanGestureHandler = typeof PanGestureHandler;
|
|
191
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; see description on the top of gestureHandlerCommon.ts file
|
|
192
|
-
export const PanGestureHandler = createHandler<
|
|
193
|
-
PanGestureHandlerProps,
|
|
194
|
-
PanGestureHandlerEventPayload
|
|
195
|
-
>({
|
|
196
|
-
name: panHandlerName,
|
|
197
|
-
allowedProps: [
|
|
198
|
-
...baseGestureHandlerProps,
|
|
199
|
-
...panGestureHandlerProps,
|
|
200
|
-
] as const,
|
|
201
|
-
config: {},
|
|
202
|
-
transformProps: managePanProps,
|
|
203
|
-
customNativeProps: panGestureHandlerCustomNativeProps,
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
function validatePanGestureHandlerProps(props: PanGestureHandlerProps) {
|
|
207
|
-
if (
|
|
208
|
-
Array.isArray(props.activeOffsetX) &&
|
|
209
|
-
(props.activeOffsetX[0] > 0 || props.activeOffsetX[1] < 0)
|
|
210
|
-
) {
|
|
211
|
-
throw new Error(
|
|
212
|
-
`First element of activeOffsetX should be negative, a the second one should be positive`
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
Array.isArray(props.activeOffsetY) &&
|
|
218
|
-
(props.activeOffsetY[0] > 0 || props.activeOffsetY[1] < 0)
|
|
219
|
-
) {
|
|
220
|
-
throw new Error(
|
|
221
|
-
`First element of activeOffsetY should be negative, a the second one should be positive`
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
-
Array.isArray(props.failOffsetX) &&
|
|
227
|
-
(props.failOffsetX[0] > 0 || props.failOffsetX[1] < 0)
|
|
228
|
-
) {
|
|
229
|
-
throw new Error(
|
|
230
|
-
`First element of failOffsetX should be negative, a the second one should be positive`
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (
|
|
235
|
-
Array.isArray(props.failOffsetY) &&
|
|
236
|
-
(props.failOffsetY[0] > 0 || props.failOffsetY[1] < 0)
|
|
237
|
-
) {
|
|
238
|
-
throw new Error(
|
|
239
|
-
`First element of failOffsetY should be negative, a the second one should be positive`
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (props.minDist && (props.failOffsetX || props.failOffsetY)) {
|
|
244
|
-
throw new Error(
|
|
245
|
-
`It is not supported to use minDist with failOffsetX or failOffsetY, use activeOffsetX and activeOffsetY instead`
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (props.minDist && (props.activeOffsetX || props.activeOffsetY)) {
|
|
250
|
-
throw new Error(
|
|
251
|
-
`It is not supported to use minDist with activeOffsetX or activeOffsetY`
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function transformPanGestureHandlerProps(props: PanGestureHandlerProps) {
|
|
257
|
-
type InternalPanGHKeys =
|
|
258
|
-
| 'activeOffsetXStart'
|
|
259
|
-
| 'activeOffsetXEnd'
|
|
260
|
-
| 'failOffsetXStart'
|
|
261
|
-
| 'failOffsetXEnd'
|
|
262
|
-
| 'activeOffsetYStart'
|
|
263
|
-
| 'activeOffsetYEnd'
|
|
264
|
-
| 'failOffsetYStart'
|
|
265
|
-
| 'failOffsetYEnd';
|
|
266
|
-
type PanGestureHandlerInternalProps = PanGestureHandlerProps &
|
|
267
|
-
Partial<Record<InternalPanGHKeys, number>>;
|
|
268
|
-
|
|
269
|
-
const res: PanGestureHandlerInternalProps = { ...props };
|
|
270
|
-
|
|
271
|
-
if (props.activeOffsetX !== undefined) {
|
|
272
|
-
delete res.activeOffsetX;
|
|
273
|
-
if (Array.isArray(props.activeOffsetX)) {
|
|
274
|
-
res.activeOffsetXStart = props.activeOffsetX[0];
|
|
275
|
-
res.activeOffsetXEnd = props.activeOffsetX[1];
|
|
276
|
-
} else if (props.activeOffsetX < 0) {
|
|
277
|
-
res.activeOffsetXStart = props.activeOffsetX;
|
|
278
|
-
} else {
|
|
279
|
-
res.activeOffsetXEnd = props.activeOffsetX;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (props.activeOffsetY !== undefined) {
|
|
284
|
-
delete res.activeOffsetY;
|
|
285
|
-
if (Array.isArray(props.activeOffsetY)) {
|
|
286
|
-
res.activeOffsetYStart = props.activeOffsetY[0];
|
|
287
|
-
res.activeOffsetYEnd = props.activeOffsetY[1];
|
|
288
|
-
} else if (props.activeOffsetY < 0) {
|
|
289
|
-
res.activeOffsetYStart = props.activeOffsetY;
|
|
290
|
-
} else {
|
|
291
|
-
res.activeOffsetYEnd = props.activeOffsetY;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (props.failOffsetX !== undefined) {
|
|
296
|
-
delete res.failOffsetX;
|
|
297
|
-
if (Array.isArray(props.failOffsetX)) {
|
|
298
|
-
res.failOffsetXStart = props.failOffsetX[0];
|
|
299
|
-
res.failOffsetXEnd = props.failOffsetX[1];
|
|
300
|
-
} else if (props.failOffsetX < 0) {
|
|
301
|
-
res.failOffsetXStart = props.failOffsetX;
|
|
302
|
-
} else {
|
|
303
|
-
res.failOffsetXEnd = props.failOffsetX;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (props.failOffsetY !== undefined) {
|
|
308
|
-
delete res.failOffsetY;
|
|
309
|
-
if (Array.isArray(props.failOffsetY)) {
|
|
310
|
-
res.failOffsetYStart = props.failOffsetY[0];
|
|
311
|
-
res.failOffsetYEnd = props.failOffsetY[1];
|
|
312
|
-
} else if (props.failOffsetY < 0) {
|
|
313
|
-
res.failOffsetYStart = props.failOffsetY;
|
|
314
|
-
} else {
|
|
315
|
-
res.failOffsetYEnd = props.failOffsetY;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return res;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
export function managePanProps(props: PanGestureHandlerProps) {
|
|
323
|
-
if (__DEV__) {
|
|
324
|
-
validatePanGestureHandlerProps(props);
|
|
325
|
-
}
|
|
326
|
-
return transformPanGestureHandlerProps(props);
|
|
327
|
-
}
|
|
1
|
+
// RNGH: patching to replace `createHandler`
|
|
2
|
+
|
|
3
|
+
import createHandler from './createHandler'; // RNGH: using local create handler
|
|
4
|
+
import {
|
|
5
|
+
BaseGestureHandlerProps,
|
|
6
|
+
baseGestureHandlerProps,
|
|
7
|
+
} from 'react-native-gesture-handler/src/handlers/gestureHandlerCommon';
|
|
8
|
+
|
|
9
|
+
export const panGestureHandlerProps = [
|
|
10
|
+
'activeOffsetY',
|
|
11
|
+
'activeOffsetX',
|
|
12
|
+
'failOffsetY',
|
|
13
|
+
'failOffsetX',
|
|
14
|
+
'minDist',
|
|
15
|
+
'minVelocity',
|
|
16
|
+
'minVelocityX',
|
|
17
|
+
'minVelocityY',
|
|
18
|
+
'minPointers',
|
|
19
|
+
'maxPointers',
|
|
20
|
+
'avgTouches',
|
|
21
|
+
'enableTrackpadTwoFingerGesture',
|
|
22
|
+
'activateAfterLongPress',
|
|
23
|
+
] as const;
|
|
24
|
+
|
|
25
|
+
export const panGestureHandlerCustomNativeProps = [
|
|
26
|
+
'activeOffsetYStart',
|
|
27
|
+
'activeOffsetYEnd',
|
|
28
|
+
'activeOffsetXStart',
|
|
29
|
+
'activeOffsetXEnd',
|
|
30
|
+
'failOffsetYStart',
|
|
31
|
+
'failOffsetYEnd',
|
|
32
|
+
'failOffsetXStart',
|
|
33
|
+
'failOffsetXEnd',
|
|
34
|
+
] as const;
|
|
35
|
+
|
|
36
|
+
export type PanGestureHandlerEventPayload = {
|
|
37
|
+
/**
|
|
38
|
+
* X coordinate of the current position of the pointer (finger or a leading
|
|
39
|
+
* pointer when there are multiple fingers placed) relative to the view
|
|
40
|
+
* attached to the handler. Expressed in point units.
|
|
41
|
+
*/
|
|
42
|
+
x: number;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Y coordinate of the current position of the pointer (finger or a leading
|
|
46
|
+
* pointer when there are multiple fingers placed) relative to the view
|
|
47
|
+
* attached to the handler. Expressed in point units.
|
|
48
|
+
*/
|
|
49
|
+
y: number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* X coordinate of the current position of the pointer (finger or a leading
|
|
53
|
+
* pointer when there are multiple fingers placed) relative to the window.
|
|
54
|
+
* The value is expressed in point units. It is recommended to use it instead
|
|
55
|
+
* of `x` in cases when the original view can be transformed as an effect of
|
|
56
|
+
* the gesture.
|
|
57
|
+
*/
|
|
58
|
+
absoluteX: number;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Y coordinate of the current position of the pointer (finger or a leading
|
|
62
|
+
* pointer when there are multiple fingers placed) relative to the window.
|
|
63
|
+
* The value is expressed in point units. It is recommended to use it instead
|
|
64
|
+
* of `y` in cases when the original view can be transformed as an
|
|
65
|
+
* effect of the gesture.
|
|
66
|
+
*/
|
|
67
|
+
absoluteY: number;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Translation of the pan gesture along X axis accumulated over the time of
|
|
71
|
+
* the gesture. The value is expressed in the point units.
|
|
72
|
+
*/
|
|
73
|
+
translationX: number;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Translation of the pan gesture along Y axis accumulated over the time of
|
|
77
|
+
* the gesture. The value is expressed in the point units.
|
|
78
|
+
*/
|
|
79
|
+
translationY: number;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Velocity of the pan gesture along the X axis in the current moment. The
|
|
83
|
+
* value is expressed in point units per second.
|
|
84
|
+
*/
|
|
85
|
+
velocityX: number;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Velocity of the pan gesture along the Y axis in the current moment. The
|
|
89
|
+
* value is expressed in point units per second.
|
|
90
|
+
*/
|
|
91
|
+
velocityY: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
interface CommonPanProperties {
|
|
95
|
+
/**
|
|
96
|
+
* Minimum distance the finger (or multiple finger) need to travel before the
|
|
97
|
+
* handler activates. Expressed in points.
|
|
98
|
+
*/
|
|
99
|
+
minDist?: number;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Android only.
|
|
103
|
+
*/
|
|
104
|
+
avgTouches?: boolean;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Enables two-finger gestures on supported devices, for example iPads with
|
|
108
|
+
* trackpads. If not enabled the gesture will require click + drag, with
|
|
109
|
+
* enableTrackpadTwoFingerGesture swiping with two fingers will also trigger
|
|
110
|
+
* the gesture.
|
|
111
|
+
*/
|
|
112
|
+
enableTrackpadTwoFingerGesture?: boolean;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* A number of fingers that is required to be placed before handler can
|
|
116
|
+
* activate. Should be a higher or equal to 0 integer.
|
|
117
|
+
*/
|
|
118
|
+
minPointers?: number;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* When the given number of fingers is placed on the screen and handler hasn't
|
|
122
|
+
* yet activated it will fail recognizing the gesture. Should be a higher or
|
|
123
|
+
* equal to 0 integer.
|
|
124
|
+
*/
|
|
125
|
+
maxPointers?: number;
|
|
126
|
+
|
|
127
|
+
minVelocity?: number;
|
|
128
|
+
minVelocityX?: number;
|
|
129
|
+
minVelocityY?: number;
|
|
130
|
+
activateAfterLongPress?: number;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface PanGestureConfig extends CommonPanProperties {
|
|
134
|
+
activeOffsetYStart?: number;
|
|
135
|
+
activeOffsetYEnd?: number;
|
|
136
|
+
activeOffsetXStart?: number;
|
|
137
|
+
activeOffsetXEnd?: number;
|
|
138
|
+
failOffsetYStart?: number;
|
|
139
|
+
failOffsetYEnd?: number;
|
|
140
|
+
failOffsetXStart?: number;
|
|
141
|
+
failOffsetXEnd?: number;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface PanGestureHandlerProps
|
|
145
|
+
extends BaseGestureHandlerProps<PanGestureHandlerEventPayload>,
|
|
146
|
+
CommonPanProperties {
|
|
147
|
+
/**
|
|
148
|
+
* Range along X axis (in points) where fingers travels without activation of
|
|
149
|
+
* handler. Moving outside of this range implies activation of handler. Range
|
|
150
|
+
* can be given as an array or a single number. If range is set as an array,
|
|
151
|
+
* first value must be lower or equal to 0, a the second one higher or equal
|
|
152
|
+
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
|
|
153
|
+
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
|
|
154
|
+
*/
|
|
155
|
+
activeOffsetY?: number | number[];
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Range along X axis (in points) where fingers travels without activation of
|
|
159
|
+
* handler. Moving outside of this range implies activation of handler. Range
|
|
160
|
+
* can be given as an array or a single number. If range is set as an array,
|
|
161
|
+
* first value must be lower or equal to 0, a the second one higher or equal
|
|
162
|
+
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
|
|
163
|
+
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
|
|
164
|
+
*/
|
|
165
|
+
activeOffsetX?: number | number[];
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* When the finger moves outside this range (in points) along Y axis and
|
|
169
|
+
* handler hasn't yet activated it will fail recognizing the gesture. Range
|
|
170
|
+
* can be given as an array or a single number. If range is set as an array,
|
|
171
|
+
* first value must be lower or equal to 0, a the second one higher or equal
|
|
172
|
+
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
|
|
173
|
+
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
|
|
174
|
+
*/
|
|
175
|
+
failOffsetY?: number | number[];
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* When the finger moves outside this range (in points) along X axis and
|
|
179
|
+
* handler hasn't yet activated it will fail recognizing the gesture. Range
|
|
180
|
+
* can be given as an array or a single number. If range is set as an array,
|
|
181
|
+
* first value must be lower or equal to 0, a the second one higher or equal
|
|
182
|
+
* to 0. If only one number `p` is given a range of `(-inf, p)` will be used
|
|
183
|
+
* if `p` is higher or equal to 0 and `(-p, inf)` otherwise.
|
|
184
|
+
*/
|
|
185
|
+
failOffsetX?: number | number[];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export const panHandlerName = 'PanGestureHandler';
|
|
189
|
+
|
|
190
|
+
export type PanGestureHandler = typeof PanGestureHandler;
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; see description on the top of gestureHandlerCommon.ts file
|
|
192
|
+
export const PanGestureHandler = createHandler<
|
|
193
|
+
PanGestureHandlerProps,
|
|
194
|
+
PanGestureHandlerEventPayload
|
|
195
|
+
>({
|
|
196
|
+
name: panHandlerName,
|
|
197
|
+
allowedProps: [
|
|
198
|
+
...baseGestureHandlerProps,
|
|
199
|
+
...panGestureHandlerProps,
|
|
200
|
+
] as const,
|
|
201
|
+
config: {},
|
|
202
|
+
transformProps: managePanProps,
|
|
203
|
+
customNativeProps: panGestureHandlerCustomNativeProps,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
function validatePanGestureHandlerProps(props: PanGestureHandlerProps) {
|
|
207
|
+
if (
|
|
208
|
+
Array.isArray(props.activeOffsetX) &&
|
|
209
|
+
(props.activeOffsetX[0] > 0 || props.activeOffsetX[1] < 0)
|
|
210
|
+
) {
|
|
211
|
+
throw new Error(
|
|
212
|
+
`First element of activeOffsetX should be negative, a the second one should be positive`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (
|
|
217
|
+
Array.isArray(props.activeOffsetY) &&
|
|
218
|
+
(props.activeOffsetY[0] > 0 || props.activeOffsetY[1] < 0)
|
|
219
|
+
) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`First element of activeOffsetY should be negative, a the second one should be positive`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (
|
|
226
|
+
Array.isArray(props.failOffsetX) &&
|
|
227
|
+
(props.failOffsetX[0] > 0 || props.failOffsetX[1] < 0)
|
|
228
|
+
) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`First element of failOffsetX should be negative, a the second one should be positive`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (
|
|
235
|
+
Array.isArray(props.failOffsetY) &&
|
|
236
|
+
(props.failOffsetY[0] > 0 || props.failOffsetY[1] < 0)
|
|
237
|
+
) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
`First element of failOffsetY should be negative, a the second one should be positive`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (props.minDist && (props.failOffsetX || props.failOffsetY)) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`It is not supported to use minDist with failOffsetX or failOffsetY, use activeOffsetX and activeOffsetY instead`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (props.minDist && (props.activeOffsetX || props.activeOffsetY)) {
|
|
250
|
+
throw new Error(
|
|
251
|
+
`It is not supported to use minDist with activeOffsetX or activeOffsetY`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function transformPanGestureHandlerProps(props: PanGestureHandlerProps) {
|
|
257
|
+
type InternalPanGHKeys =
|
|
258
|
+
| 'activeOffsetXStart'
|
|
259
|
+
| 'activeOffsetXEnd'
|
|
260
|
+
| 'failOffsetXStart'
|
|
261
|
+
| 'failOffsetXEnd'
|
|
262
|
+
| 'activeOffsetYStart'
|
|
263
|
+
| 'activeOffsetYEnd'
|
|
264
|
+
| 'failOffsetYStart'
|
|
265
|
+
| 'failOffsetYEnd';
|
|
266
|
+
type PanGestureHandlerInternalProps = PanGestureHandlerProps &
|
|
267
|
+
Partial<Record<InternalPanGHKeys, number>>;
|
|
268
|
+
|
|
269
|
+
const res: PanGestureHandlerInternalProps = { ...props };
|
|
270
|
+
|
|
271
|
+
if (props.activeOffsetX !== undefined) {
|
|
272
|
+
delete res.activeOffsetX;
|
|
273
|
+
if (Array.isArray(props.activeOffsetX)) {
|
|
274
|
+
res.activeOffsetXStart = props.activeOffsetX[0];
|
|
275
|
+
res.activeOffsetXEnd = props.activeOffsetX[1];
|
|
276
|
+
} else if (props.activeOffsetX < 0) {
|
|
277
|
+
res.activeOffsetXStart = props.activeOffsetX;
|
|
278
|
+
} else {
|
|
279
|
+
res.activeOffsetXEnd = props.activeOffsetX;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (props.activeOffsetY !== undefined) {
|
|
284
|
+
delete res.activeOffsetY;
|
|
285
|
+
if (Array.isArray(props.activeOffsetY)) {
|
|
286
|
+
res.activeOffsetYStart = props.activeOffsetY[0];
|
|
287
|
+
res.activeOffsetYEnd = props.activeOffsetY[1];
|
|
288
|
+
} else if (props.activeOffsetY < 0) {
|
|
289
|
+
res.activeOffsetYStart = props.activeOffsetY;
|
|
290
|
+
} else {
|
|
291
|
+
res.activeOffsetYEnd = props.activeOffsetY;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (props.failOffsetX !== undefined) {
|
|
296
|
+
delete res.failOffsetX;
|
|
297
|
+
if (Array.isArray(props.failOffsetX)) {
|
|
298
|
+
res.failOffsetXStart = props.failOffsetX[0];
|
|
299
|
+
res.failOffsetXEnd = props.failOffsetX[1];
|
|
300
|
+
} else if (props.failOffsetX < 0) {
|
|
301
|
+
res.failOffsetXStart = props.failOffsetX;
|
|
302
|
+
} else {
|
|
303
|
+
res.failOffsetXEnd = props.failOffsetX;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (props.failOffsetY !== undefined) {
|
|
308
|
+
delete res.failOffsetY;
|
|
309
|
+
if (Array.isArray(props.failOffsetY)) {
|
|
310
|
+
res.failOffsetYStart = props.failOffsetY[0];
|
|
311
|
+
res.failOffsetYEnd = props.failOffsetY[1];
|
|
312
|
+
} else if (props.failOffsetY < 0) {
|
|
313
|
+
res.failOffsetYStart = props.failOffsetY;
|
|
314
|
+
} else {
|
|
315
|
+
res.failOffsetYEnd = props.failOffsetY;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return res;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function managePanProps(props: PanGestureHandlerProps) {
|
|
323
|
+
if (__DEV__) {
|
|
324
|
+
validatePanGestureHandlerProps(props);
|
|
325
|
+
}
|
|
326
|
+
return transformPanGestureHandlerProps(props);
|
|
327
|
+
}
|