@zeey4d/react-native-gesture-engine 1.0.0 → 1.0.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/README.md +1 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +114 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -63
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -10
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
+
import { Gesture } from 'react-native-gesture-handler';
|
|
2
|
+
import { Accelerometer, Gyroscope } from 'expo-sensors';
|
|
3
|
+
import { DeviceEventEmitter, Vibration, AccessibilityInfo } from 'react-native';
|
|
4
|
+
import * as Haptics from 'expo-haptics';
|
|
1
5
|
import { useRef, useState, useEffect } from 'react';
|
|
2
6
|
|
|
3
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
-
}) : x)(function(x) {
|
|
6
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
-
});
|
|
9
|
-
|
|
10
7
|
// src/core/EventBus.ts
|
|
11
8
|
var EventBus = class {
|
|
12
9
|
constructor() {
|
|
@@ -118,12 +115,11 @@ var EventChannel = /* @__PURE__ */ ((EventChannel2) => {
|
|
|
118
115
|
function generateId() {
|
|
119
116
|
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
120
117
|
}
|
|
121
|
-
|
|
122
|
-
// src/input/TouchInputProvider.ts
|
|
123
118
|
var TouchInputProvider = class {
|
|
124
119
|
constructor(eventBus) {
|
|
125
120
|
this.eventBus = eventBus;
|
|
126
121
|
this._isActive = false;
|
|
122
|
+
this.gesture = this.buildGesture();
|
|
127
123
|
}
|
|
128
124
|
get isActive() {
|
|
129
125
|
return this._isActive;
|
|
@@ -221,22 +217,80 @@ var TouchInputProvider = class {
|
|
|
221
217
|
};
|
|
222
218
|
this.eventBus.emit("input:raw" /* InputRaw */, event);
|
|
223
219
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
220
|
+
/**
|
|
221
|
+
* Build the composed gesture.
|
|
222
|
+
*/
|
|
223
|
+
buildGesture() {
|
|
224
|
+
const panGesture = Gesture.Pan().onUpdate((e) => {
|
|
225
|
+
this.onPan({
|
|
226
|
+
x: e.x,
|
|
227
|
+
y: e.y,
|
|
228
|
+
translationX: e.translationX,
|
|
229
|
+
translationY: e.translationY,
|
|
230
|
+
velocityX: e.velocityX,
|
|
231
|
+
velocityY: e.velocityY,
|
|
232
|
+
numberOfPointers: e.numberOfPointers
|
|
233
|
+
});
|
|
234
|
+
}).onEnd((e) => {
|
|
235
|
+
this.onPan({
|
|
236
|
+
x: e.x,
|
|
237
|
+
y: e.y,
|
|
238
|
+
translationX: e.translationX,
|
|
239
|
+
translationY: e.translationY,
|
|
240
|
+
velocityX: e.velocityX,
|
|
241
|
+
velocityY: e.velocityY,
|
|
242
|
+
numberOfPointers: e.numberOfPointers
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
const tapGesture = Gesture.Tap().onEnd((e) => {
|
|
246
|
+
this.onTap({
|
|
247
|
+
x: e.x,
|
|
248
|
+
y: e.y,
|
|
249
|
+
numberOfPointers: e.numberOfPointers
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
const pinchGesture = Gesture.Pinch().onUpdate((e) => {
|
|
253
|
+
this.onPinch({
|
|
254
|
+
scale: e.scale,
|
|
255
|
+
focalX: e.focalX,
|
|
256
|
+
focalY: e.focalY,
|
|
257
|
+
velocity: e.velocity,
|
|
258
|
+
numberOfPointers: e.numberOfPointers
|
|
259
|
+
});
|
|
260
|
+
}).onEnd((e) => {
|
|
261
|
+
this.onPinch({
|
|
262
|
+
scale: e.scale,
|
|
263
|
+
focalX: e.focalX,
|
|
264
|
+
focalY: e.focalY,
|
|
265
|
+
velocity: e.velocity,
|
|
266
|
+
numberOfPointers: e.numberOfPointers
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
const rotationGesture = Gesture.Rotation().onUpdate((e) => {
|
|
270
|
+
this.onRotation({
|
|
271
|
+
rotation: e.rotation,
|
|
272
|
+
anchorX: e.anchorX,
|
|
273
|
+
anchorY: e.anchorY,
|
|
274
|
+
velocity: e.velocity,
|
|
275
|
+
numberOfPointers: e.numberOfPointers
|
|
276
|
+
});
|
|
277
|
+
}).onEnd((e) => {
|
|
278
|
+
this.onRotation({
|
|
279
|
+
rotation: e.rotation,
|
|
280
|
+
anchorX: e.anchorX,
|
|
281
|
+
anchorY: e.anchorY,
|
|
282
|
+
velocity: e.velocity,
|
|
283
|
+
numberOfPointers: e.numberOfPointers
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
return Gesture.Simultaneous(
|
|
287
|
+
panGesture,
|
|
288
|
+
tapGesture,
|
|
289
|
+
pinchGesture,
|
|
290
|
+
rotationGesture
|
|
237
291
|
);
|
|
238
292
|
}
|
|
239
|
-
}
|
|
293
|
+
};
|
|
240
294
|
var SensorInputProvider = class {
|
|
241
295
|
constructor(eventBus, updateIntervalMs = 100) {
|
|
242
296
|
this.eventBus = eventBus;
|
|
@@ -244,7 +298,6 @@ var SensorInputProvider = class {
|
|
|
244
298
|
this.accelSubscription = null;
|
|
245
299
|
this.gyroSubscription = null;
|
|
246
300
|
this.updateIntervalMs = Math.max(16, updateIntervalMs);
|
|
247
|
-
loadSensorModules();
|
|
248
301
|
}
|
|
249
302
|
get isActive() {
|
|
250
303
|
return this._isActive;
|
|
@@ -307,23 +360,12 @@ var SensorInputProvider = class {
|
|
|
307
360
|
}
|
|
308
361
|
}
|
|
309
362
|
};
|
|
310
|
-
|
|
311
|
-
// src/input/HardwareInputProvider.ts
|
|
312
|
-
var DeviceEventEmitter;
|
|
313
|
-
function loadEmitter() {
|
|
314
|
-
try {
|
|
315
|
-
const rn = __require("react-native");
|
|
316
|
-
DeviceEventEmitter = rn.DeviceEventEmitter;
|
|
317
|
-
} catch {
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
363
|
var HardwareInputProvider = class {
|
|
321
364
|
constructor(eventBus, eventName = "onHardwareKey") {
|
|
322
365
|
this.eventBus = eventBus;
|
|
323
366
|
this._isActive = false;
|
|
324
367
|
this.subscription = null;
|
|
325
368
|
this.eventName = eventName;
|
|
326
|
-
loadEmitter();
|
|
327
369
|
}
|
|
328
370
|
get isActive() {
|
|
329
371
|
return this._isActive;
|
|
@@ -1944,27 +1986,11 @@ var CustomAction = class {
|
|
|
1944
1986
|
this.callback(event);
|
|
1945
1987
|
}
|
|
1946
1988
|
};
|
|
1947
|
-
|
|
1948
|
-
// src/feedback/HapticFeedback.ts
|
|
1949
|
-
var Haptics;
|
|
1950
|
-
var Vibration;
|
|
1951
|
-
function loadModules() {
|
|
1952
|
-
try {
|
|
1953
|
-
Haptics = __require("expo-haptics");
|
|
1954
|
-
} catch {
|
|
1955
|
-
}
|
|
1956
|
-
try {
|
|
1957
|
-
const rn = __require("react-native");
|
|
1958
|
-
Vibration = rn.Vibration;
|
|
1959
|
-
} catch {
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
1989
|
var HapticFeedback = class {
|
|
1963
1990
|
constructor(enabled = true) {
|
|
1964
1991
|
this._isSupported = false;
|
|
1965
1992
|
this.useVibrationFallback = false;
|
|
1966
1993
|
this.enabled = enabled;
|
|
1967
|
-
loadModules();
|
|
1968
1994
|
if (Haptics) {
|
|
1969
1995
|
this._isSupported = true;
|
|
1970
1996
|
} else if (Vibration) {
|
|
@@ -2020,21 +2046,10 @@ var VisualFeedback = class {
|
|
|
2020
2046
|
this.callback = callback;
|
|
2021
2047
|
}
|
|
2022
2048
|
};
|
|
2023
|
-
|
|
2024
|
-
// src/feedback/AccessibilityFeedback.ts
|
|
2025
|
-
var AccessibilityInfo;
|
|
2026
|
-
function loadAccessibility() {
|
|
2027
|
-
try {
|
|
2028
|
-
const rn = __require("react-native");
|
|
2029
|
-
AccessibilityInfo = rn.AccessibilityInfo;
|
|
2030
|
-
} catch {
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
2049
|
var AccessibilityFeedback = class {
|
|
2034
2050
|
constructor() {
|
|
2035
2051
|
this._isSupported = false;
|
|
2036
2052
|
this.announcementBuilder = null;
|
|
2037
|
-
loadAccessibility();
|
|
2038
2053
|
this._isSupported = !!AccessibilityInfo?.announceForAccessibility;
|
|
2039
2054
|
}
|
|
2040
2055
|
get isSupported() {
|
|
@@ -2299,7 +2314,8 @@ function useGestureEngine(config = {}) {
|
|
|
2299
2314
|
}, []);
|
|
2300
2315
|
return {
|
|
2301
2316
|
engine: engineRef.current,
|
|
2302
|
-
isReady
|
|
2317
|
+
isReady,
|
|
2318
|
+
gestures: engineRef.current?.touchInput.gesture
|
|
2303
2319
|
};
|
|
2304
2320
|
}
|
|
2305
2321
|
function useShakeGesture(config) {
|