@react-native-oh-tpl/react-native-gesture-handler 2.12.9 → 2.14.1-2.14.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. package/DrawerLayout/index.ts +2 -0
  2. package/Swipeable/index.ts +2 -0
  3. package/harmony/gesture_handler/BuildProfile.ets +15 -3
  4. package/harmony/gesture_handler/hvigorfile.ts +1 -1
  5. package/harmony/gesture_handler/index.ets +2 -2
  6. package/harmony/gesture_handler/oh-package-lock.json5 +4 -3
  7. package/harmony/gesture_handler/oh-package.json5 +3 -3
  8. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +64 -18
  9. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +3 -3
  10. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +2 -2
  11. package/harmony/gesture_handler/src/main/cpp/{RNGestureHandlerButtonComponentInstance.h → componentInstances/RNGestureHandlerButtonComponentInstance.h} +2 -2
  12. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +242 -0
  13. package/harmony/gesture_handler/src/main/ets/{GestureHandler.ts → core/GestureHandler.ts} +54 -27
  14. package/harmony/gesture_handler/src/main/ets/{GestureHandlerOrchestrator.ts → core/GestureHandlerOrchestrator.ts} +122 -67
  15. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +63 -0
  16. package/harmony/gesture_handler/src/main/ets/{Event.ts → core/IncomingEvent.ts} +30 -20
  17. package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +144 -0
  18. package/harmony/gesture_handler/src/main/ets/{OutgoingEvent.ts → core/OutgoingEvent.ts} +1 -1
  19. package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +12 -0
  20. package/harmony/gesture_handler/src/main/ets/{PointerTracker.ts → core/PointerTracker.ts} +4 -4
  21. package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +12 -0
  22. package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +80 -0
  23. package/harmony/gesture_handler/src/main/ets/{VelocityTracker.ts → core/VelocityTracker.ts} +13 -5
  24. package/harmony/gesture_handler/src/main/ets/core/View.ts +21 -0
  25. package/harmony/gesture_handler/src/main/ets/core/ViewFinder.ts +11 -0
  26. package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +8 -0
  27. package/harmony/gesture_handler/src/main/ets/core/index.ts +15 -0
  28. package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +169 -0
  29. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +211 -0
  30. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +64 -0
  31. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +127 -0
  32. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +42 -0
  33. package/harmony/gesture_handler/src/main/ets/{NativeViewGestureHandler.ts → gesture-handlers/NativeViewGestureHandler.ts} +15 -15
  34. package/harmony/gesture_handler/src/main/ets/{PanGestureHandler.ts → gesture-handlers/PanGestureHandler.ts} +27 -13
  35. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +159 -0
  36. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +164 -0
  37. package/harmony/gesture_handler/src/main/ets/{TapGestureHandler.ts → gesture-handlers/TapGestureHandler.ts} +11 -11
  38. package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +167 -0
  39. package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +1 -0
  40. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +8 -9
  41. package/harmony/gesture_handler/src/main/ets/namespace/{RNGestureHandlerButton.ts → components/RNGestureHandlerButton.ts} +35 -36
  42. package/harmony/gesture_handler/src/main/ets/namespace/{RNGestureHandlerRootView.ts → components/RNGestureHandlerRootView.ts} +23 -23
  43. package/harmony/gesture_handler/src/main/ets/namespace/components/ts.ts +2 -0
  44. package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +2 -3
  45. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerArkUIAdapter.ts +240 -0
  46. package/harmony/gesture_handler/src/main/ets/{GestureHandlerPackage.ts → rnoh/GestureHandlerPackage.ts} +4 -4
  47. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +49 -0
  48. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +71 -0
  49. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +98 -0
  50. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +110 -0
  51. package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerButton.ets → rnoh/RNGestureHandlerButton.ets} +3 -3
  52. package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerModule.ts → rnoh/RNGestureHandlerModule.ts} +79 -29
  53. package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerRootView.ets → rnoh/RNGestureHandlerRootView.ets} +3 -3
  54. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +24 -0
  55. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +32 -0
  56. package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +134 -0
  57. package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +97 -0
  58. package/harmony/gesture_handler/src/main/module.json5 +8 -6
  59. package/harmony/gesture_handler/ts.ts +2 -2
  60. package/harmony/gesture_handler.har +0 -0
  61. package/lib/commonjs/index.js +126 -141
  62. package/lib/commonjs/index.js.map +1 -1
  63. package/lib/module/index.js +13 -146
  64. package/lib/module/index.js.map +1 -1
  65. package/lib/typescript/index.d.ts +39 -1
  66. package/lib/typescript/index.d.ts.map +1 -1
  67. package/package.json +13 -10
  68. package/src/index.ts +140 -140
  69. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +0 -72
  70. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +0 -78
  71. package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +0 -53
  72. package/harmony/gesture_handler/src/main/ets/GestureHandlerArkUIAdapter.ts +0 -203
  73. package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +0 -45
  74. package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +0 -28
  75. package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +0 -109
  76. package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +0 -48
  77. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerArkTS.ts +0 -60
  78. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +0 -87
  79. package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +0 -23
  80. package/harmony/gesture_handler/src/main/ets/Vector2D.ts +0 -36
  81. package/harmony/gesture_handler/src/main/ets/View.ts +0 -71
  82. package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +0 -43
  83. package/harmony/gesture_handler/src/main/ets/pages/Index.ets +0 -17
  84. package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +0 -41
  85. /package/harmony/gesture_handler/src/main/ets/{CircularBuffer.ts → core/CircularBuffer.ts} +0 -0
  86. /package/harmony/gesture_handler/src/main/ets/{LeastSquareSolver.ts → core/LeastSquareSolver.ts} +0 -0
  87. /package/harmony/gesture_handler/src/main/ets/{RNGHError.ts → core/RNGHError.ts} +0 -0
  88. /package/harmony/gesture_handler/src/main/ets/{State.ts → core/State.ts} +0 -0
  89. /package/harmony/gesture_handler/src/main/ets/{types.ts → rnoh/types.ts} +0 -0
@@ -0,0 +1,159 @@
1
+ import { GestureHandler, DEFAULT_TOUCH_SLOP, IncomingEvent, GestureConfig, State, GestureHandlerDependencies } from "../core"
2
+ import ScaleGestureDetector, { ScaleGestureListener } from "../detectors/ScaleGestureDetector";
3
+
4
+
5
+
6
+ export class PinchGestureHandler extends GestureHandler {
7
+ private scale = 1;
8
+ private velocity = 0;
9
+
10
+ private startingSpan = 0;
11
+ private spanSlop = DEFAULT_TOUCH_SLOP;
12
+
13
+ private scaleDetectorListener: ScaleGestureListener = {
14
+ onScaleBegin: (detector: ScaleGestureDetector): boolean => {
15
+ this.startingSpan = detector.getCurrentSpan();
16
+ return true;
17
+ },
18
+ onScale: (detector: ScaleGestureDetector): boolean => {
19
+ const prevScaleFactor: number = this.scale;
20
+ this.scale *= detector.getScaleFactor(
21
+ this.tracker.getTrackedPointersCount()
22
+ );
23
+
24
+ const delta = detector.getTimeDelta();
25
+ if (delta > 0) {
26
+ this.velocity = (this.scale - prevScaleFactor) / delta;
27
+ }
28
+
29
+ if (
30
+ Math.abs(this.startingSpan - detector.getCurrentSpan()) >=
31
+ this.spanSlop &&
32
+ this.currentState === State.BEGAN
33
+ ) {
34
+ this.activate();
35
+ }
36
+ return true;
37
+ },
38
+ onScaleEnd: (
39
+ _detector: ScaleGestureDetector
40
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
41
+ ): void => {},
42
+ };
43
+
44
+ private scaleGestureDetector: ScaleGestureDetector = new ScaleGestureDetector(
45
+ this.scaleDetectorListener
46
+ );
47
+
48
+
49
+ public constructor(deps: GestureHandlerDependencies) {
50
+ super({ ...deps, logger: deps.logger.cloneWithPrefix("PinchGestureHandler") })
51
+ this.setShouldCancelWhenOutside(false);
52
+ }
53
+
54
+ public getDefaultConfig() {
55
+ return {}
56
+ }
57
+
58
+ public updateGestureConfig({ enabled = true, ...props }: GestureConfig): void {
59
+ super.updateGestureConfig({ enabled: enabled, ...props });
60
+ }
61
+
62
+ protected transformNativeEvent() {
63
+ return {
64
+ focalX: this.scaleGestureDetector.getFocusX(),
65
+ focalY: this.scaleGestureDetector.getFocusY(),
66
+ velocity: this.velocity,
67
+ scale: this.scale,
68
+ };
69
+ }
70
+
71
+ public onPointerDown(event: IncomingEvent): void {
72
+ this.tracker.addToTracker(event);
73
+ super.onPointerDown(event);
74
+ }
75
+
76
+ public onAdditionalPointerAdd(event: IncomingEvent): void {
77
+ this.tracker.addToTracker(event);
78
+ super.onAdditionalPointerAdd(event);
79
+ this.tryBegin();
80
+ this.scaleGestureDetector.onTouchEvent(event, this.tracker);
81
+ }
82
+
83
+ public onPointerUp(event: IncomingEvent): void {
84
+ super.onPointerUp(event);
85
+ this.tracker.removeFromTracker(event.pointerId);
86
+ if (this.currentState !== State.ACTIVE) {
87
+ return;
88
+ }
89
+ this.scaleGestureDetector.onTouchEvent(event, this.tracker);
90
+
91
+ if (this.currentState === State.ACTIVE) {
92
+ this.end();
93
+ } else {
94
+ this.fail();
95
+ }
96
+ }
97
+
98
+ public onAdditionalPointerRemove(event: IncomingEvent): void {
99
+ super.onAdditionalPointerRemove(event);
100
+ this.scaleGestureDetector.onTouchEvent(event, this.tracker);
101
+ this.tracker.removeFromTracker(event.pointerId);
102
+
103
+ if (
104
+ this.currentState === State.ACTIVE &&
105
+ this.tracker.getTrackedPointersCount() < 2
106
+ ) {
107
+ this.end();
108
+ }
109
+ }
110
+
111
+ public onPointerMove(event: IncomingEvent): void {
112
+ if (this.tracker.getTrackedPointersCount() < 2) {
113
+ return;
114
+ }
115
+ this.tracker.track(event);
116
+
117
+ this.scaleGestureDetector.onTouchEvent(event, this.tracker);
118
+ super.onPointerMove(event);
119
+ }
120
+
121
+ public onPointerOutOfBounds(event: IncomingEvent): void {
122
+ if (this.tracker.getTrackedPointersCount() < 2) {
123
+ return;
124
+ }
125
+ this.tracker.track(event);
126
+
127
+ this.scaleGestureDetector.onTouchEvent(event, this.tracker);
128
+ super.onPointerOutOfBounds(event);
129
+ }
130
+
131
+ private tryBegin(): void {
132
+ if (this.currentState !== State.UNDETERMINED) {
133
+ return;
134
+ }
135
+
136
+ this.resetProgress();
137
+ this.begin();
138
+ }
139
+
140
+ public activate(force?: boolean): void {
141
+ if (this.currentState !== State.ACTIVE) {
142
+ this.resetProgress();
143
+ }
144
+
145
+ super.activate();
146
+ }
147
+
148
+ protected onReset(): void {
149
+ this.resetProgress();
150
+ }
151
+
152
+ protected resetProgress(): void {
153
+ if (this.currentState === State.ACTIVE) {
154
+ return;
155
+ }
156
+ this.velocity = 0;
157
+ this.scale = 1;
158
+ }
159
+ }
@@ -0,0 +1,164 @@
1
+ import { GestureHandler, State, IncomingEvent, GestureConfig, GestureHandlerDependencies } from '../core';
2
+ import RotationGestureDetector, { RotationGestureListener, } from './detectors/RotationGestureDetector';
3
+
4
+ const ROTATION_RECOGNITION_THRESHOLD = Math.PI / 36;
5
+
6
+ export class RotationGestureHandler extends GestureHandler {
7
+ private rotation = 0;
8
+ private velocity = 0;
9
+
10
+ private cachedAnchorX = 0;
11
+ private cachedAnchorY = 0;
12
+ private unlockScrolls: (() => void) | undefined
13
+
14
+ constructor(deps: GestureHandlerDependencies) {
15
+ super({ ...deps, logger: deps.logger.cloneWithPrefix("RotationGestureHandler") })
16
+ }
17
+
18
+ private rotationGestureListener: RotationGestureListener = {
19
+ onRotationBegin: (_detector: RotationGestureDetector): boolean => true,
20
+ onRotation: (detector: RotationGestureDetector): boolean => {
21
+ const previousRotation: number = this.rotation;
22
+ this.rotation += detector.getRotation();
23
+
24
+ const delta = detector.getTimeDelta();
25
+
26
+ if (delta > 0) {
27
+ this.velocity = (this.rotation - previousRotation) / delta;
28
+ }
29
+
30
+ if (
31
+ Math.abs(this.rotation) >= ROTATION_RECOGNITION_THRESHOLD &&
32
+ this.currentState === State.BEGAN
33
+ ) {
34
+ this.activate();
35
+ }
36
+
37
+ return true;
38
+ },
39
+ onRotationEnd: (_detector: RotationGestureDetector): void => {
40
+ this.end();
41
+ },
42
+ };
43
+
44
+ private rotationGestureDetector: RotationGestureDetector =
45
+ new RotationGestureDetector(this.rotationGestureListener);
46
+
47
+ getDefaultConfig(): GestureConfig {
48
+ return { shouldCancelWhenOutside: false }
49
+ }
50
+
51
+ protected transformNativeEvent() {
52
+ return {
53
+ rotation: this.rotation ? this.rotation : 0,
54
+ anchorX: this.getAnchorX(),
55
+ anchorY: this.getAnchorY(),
56
+ velocity: this.velocity ? this.velocity : 0,
57
+ };
58
+ }
59
+
60
+ public getAnchorX(): number {
61
+ const anchorX = this.rotationGestureDetector.getAnchorX();
62
+
63
+ return anchorX ? anchorX : this.cachedAnchorX;
64
+ }
65
+
66
+ public getAnchorY(): number {
67
+ const anchorY = this.rotationGestureDetector.getAnchorY();
68
+
69
+ return anchorY ? anchorY : this.cachedAnchorY;
70
+ }
71
+
72
+ public onPointerDown(event: IncomingEvent): void {
73
+ this.tracker.addToTracker(event);
74
+ super.onPointerDown(event);
75
+ }
76
+
77
+ public onAdditionalPointerAdd(event: IncomingEvent): void {
78
+ this.tracker.addToTracker(event);
79
+ super.onAdditionalPointerAdd(event);
80
+ this.tryBegin();
81
+ this.rotationGestureDetector.onTouchEvent(event, this.tracker);
82
+ }
83
+
84
+ public onPointerMove(event: IncomingEvent): void {
85
+ if (this.tracker.getTrackedPointersCount() < 2) {
86
+ return;
87
+ }
88
+ if (this.getAnchorX()) {
89
+ this.cachedAnchorX = this.getAnchorX();
90
+ }
91
+ if (this.getAnchorY()) {
92
+ this.cachedAnchorY = this.getAnchorY();
93
+ }
94
+ this.tracker.track(event);
95
+ this.rotationGestureDetector.onTouchEvent(event, this.tracker);
96
+ super.onPointerMove(event);
97
+ }
98
+
99
+ public onPointerOutOfBounds(event: IncomingEvent): void {
100
+ if (this.tracker.getTrackedPointersCount() < 2) {
101
+ return;
102
+ }
103
+ if (this.getAnchorX()) {
104
+ this.cachedAnchorX = this.getAnchorX();
105
+ }
106
+ if (this.getAnchorY()) {
107
+ this.cachedAnchorY = this.getAnchorY();
108
+ }
109
+ this.tracker.track(event);
110
+ this.rotationGestureDetector.onTouchEvent(event, this.tracker);
111
+ super.onPointerOutOfBounds(event);
112
+ }
113
+
114
+ public onPointerUp(event: IncomingEvent): void {
115
+ super.onPointerUp(event);
116
+ this.tracker.removeFromTracker(event.pointerId);
117
+ this.rotationGestureDetector.onTouchEvent(event, this.tracker);
118
+ if (this.currentState !== State.ACTIVE) {
119
+ return;
120
+ }
121
+ if (this.currentState === State.ACTIVE) {
122
+ this.end();
123
+ } else {
124
+ this.fail();
125
+ }
126
+ }
127
+
128
+ public onAdditionalPointerRemove(event: IncomingEvent): void {
129
+ super.onAdditionalPointerRemove(event);
130
+ this.rotationGestureDetector.onTouchEvent(event, this.tracker);
131
+ this.tracker.removeFromTracker(event.pointerId);
132
+ }
133
+
134
+ protected tryBegin(): void {
135
+ if (this.currentState !== State.UNDETERMINED) {
136
+ return;
137
+ }
138
+
139
+ this.begin();
140
+ }
141
+
142
+ public activate(): void {
143
+ super.activate();
144
+ }
145
+
146
+ protected onReset(): void {
147
+ if (this.currentState === State.ACTIVE) {
148
+ return;
149
+ }
150
+
151
+ this.rotation = 0;
152
+ this.velocity = 0;
153
+ this.rotationGestureDetector.reset();
154
+ }
155
+
156
+ protected onStateChange(newState: State, oldState: State) {
157
+ super.onStateChange(newState, oldState)
158
+ if (newState === State.BEGAN) {
159
+ this.unlockScrolls = this.scrollLocker.lockScrollContainingViewTag(this.view?.getTag())
160
+ } else if (newState !== State.ACTIVE) {
161
+ this.unlockScrolls?.()
162
+ }
163
+ }
164
+ }
@@ -1,6 +1,4 @@
1
- import { GestureHandler, GestureHandlerDependencies } from "./GestureHandler"
2
- import { AdaptedEvent, EventType } from "./Event"
3
- import { State, getStateName } from "./State"
1
+ import { GestureHandler, GestureHandlerDependencies, IncomingEvent, EventType, State, getStateName } from "../core"
4
2
 
5
3
  const DEFAULT_MAX_DURATION_MS = 500;
6
4
  const DEFAULT_NUMBER_OF_TAPS = 1;
@@ -19,7 +17,7 @@ export class TapGestureHandler extends GestureHandler {
19
17
  private delayTimeout: number | undefined;
20
18
 
21
19
  constructor(deps: GestureHandlerDependencies) {
22
- super({...deps, logger: deps.logger.cloneWithPrefix("TapGestureHandler")})
20
+ super({...deps, logger: deps.logger.cloneWithPrefix(`TapGestureHandler${deps.handlerTag}`)})
23
21
  }
24
22
 
25
23
  onPointerDown(event) {
@@ -31,7 +29,7 @@ export class TapGestureHandler extends GestureHandler {
31
29
  this.updateState(event);
32
30
  }
33
31
 
34
- onAdditionalPointerAdd(event: AdaptedEvent): void {
32
+ onAdditionalPointerAdd(event: IncomingEvent): void {
35
33
  super.onAdditionalPointerAdd(event);
36
34
  this.tracker.addToTracker(event);
37
35
  this.trySettingPosition(event);
@@ -48,7 +46,7 @@ export class TapGestureHandler extends GestureHandler {
48
46
  this.updateState(event);
49
47
  }
50
48
 
51
- onPointerUp(event: AdaptedEvent): void {
49
+ onPointerUp(event: IncomingEvent): void {
52
50
  super.onPointerUp(event);
53
51
  this.lastX = this.tracker.getLastAvgX();
54
52
  this.lastY = this.tracker.getLastAvgY();
@@ -58,7 +56,7 @@ export class TapGestureHandler extends GestureHandler {
58
56
  this.updateState(event);
59
57
  }
60
58
 
61
- onAdditionalPointerRemove(event: AdaptedEvent): void {
59
+ onAdditionalPointerRemove(event: IncomingEvent): void {
62
60
  super.onAdditionalPointerRemove(event);
63
61
  this.tracker.removeFromTracker(event.pointerId);
64
62
 
@@ -74,7 +72,7 @@ export class TapGestureHandler extends GestureHandler {
74
72
  this.updateState(event);
75
73
  }
76
74
 
77
- onPointerMove(event: AdaptedEvent): void {
75
+ onPointerMove(event: IncomingEvent): void {
78
76
  this.trySettingPosition(event);
79
77
  this.tracker.track(event);
80
78
 
@@ -86,7 +84,7 @@ export class TapGestureHandler extends GestureHandler {
86
84
  super.onPointerMove(event);
87
85
  }
88
86
 
89
- onPointerOutOfBounds(event: AdaptedEvent): void {
87
+ onPointerOutOfBounds(event: IncomingEvent): void {
90
88
  this.trySettingPosition(event);
91
89
  this.tracker.track(event);
92
90
 
@@ -102,7 +100,7 @@ export class TapGestureHandler extends GestureHandler {
102
100
  return {}
103
101
  }
104
102
 
105
- private trySettingPosition(event: AdaptedEvent): void {
103
+ private trySettingPosition(event: IncomingEvent): void {
106
104
  if (this.currentState !== State.UNDETERMINED) return;
107
105
  this.offsetX = 0;
108
106
  this.offsetY = 0;
@@ -110,7 +108,7 @@ export class TapGestureHandler extends GestureHandler {
110
108
  this.startY = event.y;
111
109
  }
112
110
 
113
- private updateState(event: AdaptedEvent): void {
111
+ private updateState(event: IncomingEvent): void {
114
112
  const logger = this.logger.cloneWithPrefix("updateState")
115
113
  if (this.maxNumberOfPointersSoFar < this.tracker.getTrackedPointersCount()) {
116
114
  this.maxNumberOfPointersSoFar = this.tracker.getTrackedPointersCount()
@@ -177,11 +175,13 @@ export class TapGestureHandler extends GestureHandler {
177
175
  }
178
176
 
179
177
  private endTap() {
178
+ const logger = this.logger.cloneWithPrefix("endTap")
180
179
  this.clearTimeouts();
181
180
  if (
182
181
  ++this.numberOfTapsSoFar === (this.config.numberOfTaps ?? DEFAULT_NUMBER_OF_TAPS) &&
183
182
  this.maxNumberOfPointersSoFar >= (this.config.minNumberOfPointers ?? 0)
184
183
  ) {
184
+ logger.info(JSON.stringify({numberOfTapsSoFar: this.numberOfTapsSoFar}))
185
185
  this.activate();
186
186
  } else {
187
187
  this.delayTimeout = setTimeout(() => this.fail(), this.config.maxDelayMs ?? DEFAULT_MAX_DELAY_MS);
@@ -0,0 +1,167 @@
1
+ import { PointerTracker, IncomingEvent, EventType } from '../../core';
2
+
3
+ export interface RotationGestureListener {
4
+ onRotationBegin: (detector: RotationGestureDetector) => boolean;
5
+ onRotation: (detector: RotationGestureDetector) => boolean;
6
+ onRotationEnd: (detector: RotationGestureDetector) => void;
7
+ }
8
+
9
+ export default class RotationGestureDetector
10
+ implements RotationGestureListener
11
+ {
12
+ onRotationBegin: (detector: RotationGestureDetector) => boolean;
13
+ onRotation: (detector: RotationGestureDetector) => boolean;
14
+ onRotationEnd: (detector: RotationGestureDetector) => void;
15
+
16
+ private currentTime = 0;
17
+ private previousTime = 0;
18
+
19
+ private previousAngle = 0;
20
+ private rotation = 0;
21
+
22
+ private anchorX = 0;
23
+ private anchorY = 0;
24
+
25
+ private isInProgress = false;
26
+
27
+ private keyPointers: number[] = [NaN, NaN];
28
+
29
+ constructor(callbacks: RotationGestureListener) {
30
+ this.onRotationBegin = callbacks.onRotationBegin;
31
+ this.onRotation = callbacks.onRotation;
32
+ this.onRotationEnd = callbacks.onRotationEnd;
33
+ }
34
+
35
+ private updateCurrent(event: IncomingEvent, tracker: PointerTracker): void {
36
+ this.previousTime = this.currentTime;
37
+ this.currentTime = event.time;
38
+
39
+ const [firstPointerID, secondPointerID] = this.keyPointers;
40
+
41
+ const firstPointerX: number = tracker.getLastX(firstPointerID);
42
+ const firstPointerY: number = tracker.getLastY(firstPointerID);
43
+ const secondPointerX: number = tracker.getLastX(secondPointerID);
44
+ const secondPointerY: number = tracker.getLastY(secondPointerID);
45
+
46
+ const vectorX: number = secondPointerX - firstPointerX;
47
+ const vectorY: number = secondPointerY - firstPointerY;
48
+
49
+ this.anchorX = (firstPointerX + secondPointerX) / 2;
50
+ this.anchorY = (firstPointerY + secondPointerY) / 2;
51
+
52
+ //Angle diff should be positive when rotating in clockwise direction
53
+ const angle: number = -Math.atan2(vectorY, vectorX);
54
+
55
+ this.rotation = Number.isNaN(this.previousAngle)
56
+ ? 0
57
+ : this.previousAngle - angle;
58
+
59
+ this.previousAngle = angle;
60
+
61
+ if (this.rotation > Math.PI) {
62
+ this.rotation -= Math.PI;
63
+ } else if (this.rotation < -Math.PI) {
64
+ this.rotation += Math.PI;
65
+ }
66
+
67
+ if (this.rotation > Math.PI / 2) {
68
+ this.rotation -= Math.PI;
69
+ } else if (this.rotation < -Math.PI / 2) {
70
+ this.rotation += Math.PI;
71
+ }
72
+ }
73
+
74
+ private finish(): void {
75
+ if (!this.isInProgress) {
76
+ return;
77
+ }
78
+
79
+ this.isInProgress = false;
80
+ this.keyPointers = [NaN, NaN];
81
+ this.onRotationEnd(this);
82
+ }
83
+
84
+ private setKeyPointers(tracker: PointerTracker): void {
85
+ if (this.keyPointers[0] && this.keyPointers[1]) {
86
+ return;
87
+ }
88
+
89
+ const pointerIDs: IterableIterator<number> = tracker.getData().keys();
90
+
91
+ this.keyPointers[0] = pointerIDs.next().value as number;
92
+ this.keyPointers[1] = pointerIDs.next().value as number;
93
+ }
94
+
95
+ public onTouchEvent(event: IncomingEvent, tracker: PointerTracker): boolean {
96
+ switch (event.eventType) {
97
+ case EventType.DOWN:
98
+ this.isInProgress = false;
99
+ break;
100
+
101
+ case EventType.ADDITIONAL_POINTER_DOWN:
102
+ if (this.isInProgress) {
103
+ break;
104
+ }
105
+ this.isInProgress = true;
106
+
107
+ this.previousTime = event.time;
108
+ this.previousAngle = NaN;
109
+
110
+ this.setKeyPointers(tracker);
111
+
112
+ this.updateCurrent(event, tracker);
113
+ this.onRotationBegin(this);
114
+ break;
115
+
116
+ case EventType.MOVE:
117
+ if (!this.isInProgress) {
118
+ break;
119
+ }
120
+
121
+ this.updateCurrent(event, tracker);
122
+ this.onRotation(this);
123
+
124
+ break;
125
+
126
+ case EventType.ADDITIONAL_POINTER_UP:
127
+ if (!this.isInProgress) {
128
+ break;
129
+ }
130
+
131
+ if (this.keyPointers.indexOf(event.pointerId) >= 0) {
132
+ this.finish();
133
+ }
134
+
135
+ break;
136
+
137
+ case EventType.UP:
138
+ if (this.isInProgress) {
139
+ this.finish();
140
+ }
141
+ break;
142
+ }
143
+
144
+ return true;
145
+ }
146
+
147
+ public getTimeDelta(): number {
148
+ return this.currentTime + this.previousTime;
149
+ }
150
+
151
+ public getAnchorX(): number {
152
+ return this.anchorX;
153
+ }
154
+
155
+ public getAnchorY(): number {
156
+ return this.anchorY;
157
+ }
158
+
159
+ public getRotation(): number {
160
+ return this.rotation;
161
+ }
162
+
163
+ public reset(): void {
164
+ this.keyPointers = [NaN, NaN];
165
+ this.isInProgress = false;
166
+ }
167
+ }
@@ -0,0 +1 @@
1
+ export * from "./GestureHandlerFactory"
@@ -1,25 +1,24 @@
1
1
  // This file was generated.
2
- import { Tag } from "../../ts"
3
2
 
4
3
  export namespace RNGestureHandlerModule {
5
4
  export const NAME = 'RNGestureHandlerModule' as const
6
5
 
7
6
  export interface Spec {
8
7
  handleSetJSResponder(tag: number, blockNativeResponder: boolean): void;
9
-
8
+
10
9
  handleClearJSResponder(): void;
11
-
10
+
12
11
  createGestureHandler(handlerName: string, handlerTag: number, config: Object): void;
13
-
12
+
14
13
  attachGestureHandler(handlerTag: number, newView: number, actionType: number): void;
15
-
14
+
16
15
  updateGestureHandler(handlerTag: number, newConfig: Object): void;
17
-
16
+
18
17
  dropGestureHandler(handlerTag: number): void;
19
-
18
+
20
19
  install(): boolean;
21
-
20
+
22
21
  flushOperations(): void;
23
-
22
+
24
23
  }
25
24
  }