@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 CHANGED
@@ -244,3 +244,4 @@ npm run test:coverage # Run with coverage report
244
244
  ## 📄 License
245
245
 
246
246
  MIT © [zeey4d](https://github.com/zeey4d)
247
+ # react-native-gesture-engine
package/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ComposedGesture } from 'react-native-gesture-handler';
2
+
1
3
  /** Classification of input sources feeding into the pipeline */
2
4
  declare enum InputType {
3
5
  Touch = "touch",
@@ -422,6 +424,11 @@ declare class EventBus implements IEventBus {
422
424
  declare class TouchInputProvider implements IInputProvider {
423
425
  private eventBus;
424
426
  private _isActive;
427
+ /**
428
+ * Extracted composed RNGH Gesture.
429
+ * Consumers should wrap their app/screen in <GestureDetector gesture={gesture}>
430
+ */
431
+ readonly gesture: ComposedGesture;
425
432
  constructor(eventBus: IEventBus);
426
433
  get isActive(): boolean;
427
434
  start(): void;
@@ -469,6 +476,10 @@ declare class TouchInputProvider implements IInputProvider {
469
476
  }): void;
470
477
  /** Emit a normalized InputEvent onto the EventBus */
471
478
  private emitInput;
479
+ /**
480
+ * Build the composed gesture.
481
+ */
482
+ private buildGesture;
472
483
  }
473
484
 
474
485
  /**
@@ -1331,6 +1342,11 @@ interface UseGestureEngineResult {
1331
1342
  engine: GestureEngine | null;
1332
1343
  /** Whether the engine is initialized and running */
1333
1344
  isReady: boolean;
1345
+ /**
1346
+ * RNGH Composed Gesture.
1347
+ * Pass this to `<GestureDetector gesture={gestures}>` to enable touch inputs.
1348
+ */
1349
+ gestures?: ComposedGesture;
1334
1350
  }
1335
1351
  /**
1336
1352
  * React hook that creates, configures, and manages a GestureEngine lifecycle.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ComposedGesture } from 'react-native-gesture-handler';
2
+
1
3
  /** Classification of input sources feeding into the pipeline */
2
4
  declare enum InputType {
3
5
  Touch = "touch",
@@ -422,6 +424,11 @@ declare class EventBus implements IEventBus {
422
424
  declare class TouchInputProvider implements IInputProvider {
423
425
  private eventBus;
424
426
  private _isActive;
427
+ /**
428
+ * Extracted composed RNGH Gesture.
429
+ * Consumers should wrap their app/screen in <GestureDetector gesture={gesture}>
430
+ */
431
+ readonly gesture: ComposedGesture;
425
432
  constructor(eventBus: IEventBus);
426
433
  get isActive(): boolean;
427
434
  start(): void;
@@ -469,6 +476,10 @@ declare class TouchInputProvider implements IInputProvider {
469
476
  }): void;
470
477
  /** Emit a normalized InputEvent onto the EventBus */
471
478
  private emitInput;
479
+ /**
480
+ * Build the composed gesture.
481
+ */
482
+ private buildGesture;
472
483
  }
473
484
 
474
485
  /**
@@ -1331,6 +1342,11 @@ interface UseGestureEngineResult {
1331
1342
  engine: GestureEngine | null;
1332
1343
  /** Whether the engine is initialized and running */
1333
1344
  isReady: boolean;
1345
+ /**
1346
+ * RNGH Composed Gesture.
1347
+ * Pass this to `<GestureDetector gesture={gestures}>` to enable touch inputs.
1348
+ */
1349
+ gestures?: ComposedGesture;
1334
1350
  }
1335
1351
  /**
1336
1352
  * React hook that creates, configures, and manages a GestureEngine lifecycle.
package/dist/index.js CHANGED
@@ -1,13 +1,30 @@
1
1
  'use strict';
2
2
 
3
+ var reactNativeGestureHandler = require('react-native-gesture-handler');
4
+ var expoSensors = require('expo-sensors');
5
+ var reactNative = require('react-native');
6
+ var Haptics = require('expo-haptics');
3
7
  var react = require('react');
4
8
 
5
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
6
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
7
- }) : x)(function(x) {
8
- if (typeof require !== "undefined") return require.apply(this, arguments);
9
- throw Error('Dynamic require of "' + x + '" is not supported');
10
- });
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var Haptics__namespace = /*#__PURE__*/_interopNamespace(Haptics);
11
28
 
12
29
  // src/core/EventBus.ts
13
30
  var EventBus = class {
@@ -120,12 +137,11 @@ var EventChannel = /* @__PURE__ */ ((EventChannel2) => {
120
137
  function generateId() {
121
138
  return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
122
139
  }
123
-
124
- // src/input/TouchInputProvider.ts
125
140
  var TouchInputProvider = class {
126
141
  constructor(eventBus) {
127
142
  this.eventBus = eventBus;
128
143
  this._isActive = false;
144
+ this.gesture = this.buildGesture();
129
145
  }
130
146
  get isActive() {
131
147
  return this._isActive;
@@ -223,22 +239,80 @@ var TouchInputProvider = class {
223
239
  };
224
240
  this.eventBus.emit("input:raw" /* InputRaw */, event);
225
241
  }
226
- };
227
-
228
- // src/input/SensorInputProvider.ts
229
- var Accelerometer;
230
- var Gyroscope;
231
- function loadSensorModules() {
232
- try {
233
- const sensors = __require("expo-sensors");
234
- Accelerometer = sensors.Accelerometer;
235
- Gyroscope = sensors.Gyroscope;
236
- } catch {
237
- console.warn(
238
- "[GestureEngine] expo-sensors not found. SensorInputProvider will not function."
242
+ /**
243
+ * Build the composed gesture.
244
+ */
245
+ buildGesture() {
246
+ const panGesture = reactNativeGestureHandler.Gesture.Pan().onUpdate((e) => {
247
+ this.onPan({
248
+ x: e.x,
249
+ y: e.y,
250
+ translationX: e.translationX,
251
+ translationY: e.translationY,
252
+ velocityX: e.velocityX,
253
+ velocityY: e.velocityY,
254
+ numberOfPointers: e.numberOfPointers
255
+ });
256
+ }).onEnd((e) => {
257
+ this.onPan({
258
+ x: e.x,
259
+ y: e.y,
260
+ translationX: e.translationX,
261
+ translationY: e.translationY,
262
+ velocityX: e.velocityX,
263
+ velocityY: e.velocityY,
264
+ numberOfPointers: e.numberOfPointers
265
+ });
266
+ });
267
+ const tapGesture = reactNativeGestureHandler.Gesture.Tap().onEnd((e) => {
268
+ this.onTap({
269
+ x: e.x,
270
+ y: e.y,
271
+ numberOfPointers: e.numberOfPointers
272
+ });
273
+ });
274
+ const pinchGesture = reactNativeGestureHandler.Gesture.Pinch().onUpdate((e) => {
275
+ this.onPinch({
276
+ scale: e.scale,
277
+ focalX: e.focalX,
278
+ focalY: e.focalY,
279
+ velocity: e.velocity,
280
+ numberOfPointers: e.numberOfPointers
281
+ });
282
+ }).onEnd((e) => {
283
+ this.onPinch({
284
+ scale: e.scale,
285
+ focalX: e.focalX,
286
+ focalY: e.focalY,
287
+ velocity: e.velocity,
288
+ numberOfPointers: e.numberOfPointers
289
+ });
290
+ });
291
+ const rotationGesture = reactNativeGestureHandler.Gesture.Rotation().onUpdate((e) => {
292
+ this.onRotation({
293
+ rotation: e.rotation,
294
+ anchorX: e.anchorX,
295
+ anchorY: e.anchorY,
296
+ velocity: e.velocity,
297
+ numberOfPointers: e.numberOfPointers
298
+ });
299
+ }).onEnd((e) => {
300
+ this.onRotation({
301
+ rotation: e.rotation,
302
+ anchorX: e.anchorX,
303
+ anchorY: e.anchorY,
304
+ velocity: e.velocity,
305
+ numberOfPointers: e.numberOfPointers
306
+ });
307
+ });
308
+ return reactNativeGestureHandler.Gesture.Simultaneous(
309
+ panGesture,
310
+ tapGesture,
311
+ pinchGesture,
312
+ rotationGesture
239
313
  );
240
314
  }
241
- }
315
+ };
242
316
  var SensorInputProvider = class {
243
317
  constructor(eventBus, updateIntervalMs = 100) {
244
318
  this.eventBus = eventBus;
@@ -246,7 +320,6 @@ var SensorInputProvider = class {
246
320
  this.accelSubscription = null;
247
321
  this.gyroSubscription = null;
248
322
  this.updateIntervalMs = Math.max(16, updateIntervalMs);
249
- loadSensorModules();
250
323
  }
251
324
  get isActive() {
252
325
  return this._isActive;
@@ -254,13 +327,13 @@ var SensorInputProvider = class {
254
327
  start() {
255
328
  if (this._isActive) return;
256
329
  this._isActive = true;
257
- if (!Accelerometer || !Gyroscope) {
330
+ if (!expoSensors.Accelerometer || !expoSensors.Gyroscope) {
258
331
  console.warn("[GestureEngine] Sensors unavailable. Skipping sensor subscriptions.");
259
332
  return;
260
333
  }
261
- Accelerometer.setUpdateInterval(this.updateIntervalMs);
262
- Gyroscope.setUpdateInterval(this.updateIntervalMs);
263
- this.accelSubscription = Accelerometer.addListener(
334
+ expoSensors.Accelerometer.setUpdateInterval(this.updateIntervalMs);
335
+ expoSensors.Gyroscope.setUpdateInterval(this.updateIntervalMs);
336
+ this.accelSubscription = expoSensors.Accelerometer.addListener(
264
337
  (data) => {
265
338
  if (!this._isActive) return;
266
339
  const sensorData = {
@@ -278,7 +351,7 @@ var SensorInputProvider = class {
278
351
  this.eventBus.emit("input:raw" /* InputRaw */, event);
279
352
  }
280
353
  );
281
- this.gyroSubscription = Gyroscope.addListener(
354
+ this.gyroSubscription = expoSensors.Gyroscope.addListener(
282
355
  (data) => {
283
356
  if (!this._isActive) return;
284
357
  const sensorData = {
@@ -309,23 +382,12 @@ var SensorInputProvider = class {
309
382
  }
310
383
  }
311
384
  };
312
-
313
- // src/input/HardwareInputProvider.ts
314
- var DeviceEventEmitter;
315
- function loadEmitter() {
316
- try {
317
- const rn = __require("react-native");
318
- DeviceEventEmitter = rn.DeviceEventEmitter;
319
- } catch {
320
- }
321
- }
322
385
  var HardwareInputProvider = class {
323
386
  constructor(eventBus, eventName = "onHardwareKey") {
324
387
  this.eventBus = eventBus;
325
388
  this._isActive = false;
326
389
  this.subscription = null;
327
390
  this.eventName = eventName;
328
- loadEmitter();
329
391
  }
330
392
  get isActive() {
331
393
  return this._isActive;
@@ -333,10 +395,10 @@ var HardwareInputProvider = class {
333
395
  start() {
334
396
  if (this._isActive) return;
335
397
  this._isActive = true;
336
- if (!DeviceEventEmitter) {
398
+ if (!reactNative.DeviceEventEmitter) {
337
399
  return;
338
400
  }
339
- this.subscription = DeviceEventEmitter.addListener(
401
+ this.subscription = reactNative.DeviceEventEmitter.addListener(
340
402
  this.eventName,
341
403
  (data) => {
342
404
  if (!this._isActive) return;
@@ -1946,30 +2008,14 @@ var CustomAction = class {
1946
2008
  this.callback(event);
1947
2009
  }
1948
2010
  };
1949
-
1950
- // src/feedback/HapticFeedback.ts
1951
- var Haptics;
1952
- var Vibration;
1953
- function loadModules() {
1954
- try {
1955
- Haptics = __require("expo-haptics");
1956
- } catch {
1957
- }
1958
- try {
1959
- const rn = __require("react-native");
1960
- Vibration = rn.Vibration;
1961
- } catch {
1962
- }
1963
- }
1964
2011
  var HapticFeedback = class {
1965
2012
  constructor(enabled = true) {
1966
2013
  this._isSupported = false;
1967
2014
  this.useVibrationFallback = false;
1968
2015
  this.enabled = enabled;
1969
- loadModules();
1970
- if (Haptics) {
2016
+ if (Haptics__namespace) {
1971
2017
  this._isSupported = true;
1972
- } else if (Vibration) {
2018
+ } else if (reactNative.Vibration) {
1973
2019
  this._isSupported = true;
1974
2020
  this.useVibrationFallback = true;
1975
2021
  }
@@ -1983,18 +2029,18 @@ var HapticFeedback = class {
1983
2029
  return;
1984
2030
  }
1985
2031
  if (this.useVibrationFallback) {
1986
- Vibration?.vibrate(50);
2032
+ reactNative.Vibration?.vibrate(50);
1987
2033
  return;
1988
2034
  }
1989
2035
  const gestureName = event.name;
1990
2036
  if (gestureName.startsWith("sequence:") || gestureName === "shake") {
1991
- Haptics?.notificationAsync?.(Haptics.NotificationFeedbackType?.Success);
2037
+ Haptics__namespace?.notificationAsync?.(Haptics__namespace.NotificationFeedbackType?.Success);
1992
2038
  } else if (gestureName === "tap" || gestureName === "double-tap") {
1993
- Haptics?.impactAsync?.(Haptics.ImpactFeedbackStyle?.Light);
2039
+ Haptics__namespace?.impactAsync?.(Haptics__namespace.ImpactFeedbackStyle?.Light);
1994
2040
  } else if (gestureName.startsWith("edge-swipe") || gestureName.startsWith("corner")) {
1995
- Haptics?.impactAsync?.(Haptics.ImpactFeedbackStyle?.Medium);
2041
+ Haptics__namespace?.impactAsync?.(Haptics__namespace.ImpactFeedbackStyle?.Medium);
1996
2042
  } else {
1997
- Haptics?.selectionAsync?.();
2043
+ Haptics__namespace?.selectionAsync?.();
1998
2044
  }
1999
2045
  }
2000
2046
  setEnabled(enabled) {
@@ -2022,22 +2068,11 @@ var VisualFeedback = class {
2022
2068
  this.callback = callback;
2023
2069
  }
2024
2070
  };
2025
-
2026
- // src/feedback/AccessibilityFeedback.ts
2027
- var AccessibilityInfo;
2028
- function loadAccessibility() {
2029
- try {
2030
- const rn = __require("react-native");
2031
- AccessibilityInfo = rn.AccessibilityInfo;
2032
- } catch {
2033
- }
2034
- }
2035
2071
  var AccessibilityFeedback = class {
2036
2072
  constructor() {
2037
2073
  this._isSupported = false;
2038
2074
  this.announcementBuilder = null;
2039
- loadAccessibility();
2040
- this._isSupported = !!AccessibilityInfo?.announceForAccessibility;
2075
+ this._isSupported = !!reactNative.AccessibilityInfo?.announceForAccessibility;
2041
2076
  }
2042
2077
  get isSupported() {
2043
2078
  return this._isSupported;
@@ -2046,7 +2081,7 @@ var AccessibilityFeedback = class {
2046
2081
  if (!this._isSupported) return;
2047
2082
  if (event.state !== "ended" /* Ended */) return;
2048
2083
  const announcement = this.announcementBuilder ? this.announcementBuilder(event) : this.defaultAnnouncement(event);
2049
- AccessibilityInfo.announceForAccessibility(announcement);
2084
+ reactNative.AccessibilityInfo.announceForAccessibility(announcement);
2050
2085
  }
2051
2086
  /**
2052
2087
  * Set a custom function to build announcement strings.
@@ -2301,7 +2336,8 @@ function useGestureEngine(config = {}) {
2301
2336
  }, []);
2302
2337
  return {
2303
2338
  engine: engineRef.current,
2304
- isReady
2339
+ isReady,
2340
+ gestures: engineRef.current?.touchInput.gesture
2305
2341
  };
2306
2342
  }
2307
2343
  function useShakeGesture(config) {