@react-native-oh-tpl/react-native-gesture-handler 2.12.6-1 → 2.12.9
Sign up to get free protection for your applications and to get access to all the features.
- package/harmony/gesture_handler/BuildProfile.ets +5 -0
- package/harmony/gesture_handler/build-profile.json5 +18 -7
- package/harmony/gesture_handler/hvigorfile.ts +2 -2
- package/harmony/gesture_handler/index.ets +3 -3
- package/harmony/gesture_handler/oh-package-lock.json5 +17 -0
- package/harmony/gesture_handler/oh-package.json5 +12 -11
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -8
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +103 -34
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +21 -15
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +36 -60
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentInstance.h +27 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +32 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +22 -17
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +15 -12
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +72 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +36 -60
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +78 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +25 -0
- 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 +52 -37
- package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +663 -663
- package/harmony/gesture_handler/src/main/ets/{GestureHandlerArkUIAdapter.ets → GestureHandlerArkUIAdapter.ts} +202 -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 +47 -28
- package/harmony/gesture_handler/src/main/ets/{RNGHRootTouchHandler.ets → RNGHRootTouchHandlerArkTS.ts} +59 -57
- package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +87 -0
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerButton.ets +37 -36
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +183 -125
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +52 -55
- package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +23 -11
- 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/namespace/RNGestureHandlerButton.ts +140 -0
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +25 -0
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerRootView.ts +101 -0
- package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +3 -0
- package/harmony/gesture_handler/src/main/ets/pages/Index.ets +16 -16
- package/harmony/gesture_handler/src/main/ets/types.ts +25 -0
- package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +41 -41
- package/harmony/gesture_handler/src/main/module.json5 +7 -7
- 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/ts.ts +2 -1
- package/harmony/gesture_handler.har +0 -0
- package/lib/commonjs/RNGestureHandlerModule.js +6 -3
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js +5 -13
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +31 -28
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/index.js +42 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +10 -0
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +11 -0
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +11 -0
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
- package/lib/module/RNGestureHandlerModule.js +3 -2
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.js +3 -11
- package/lib/module/components/GestureHandlerRootView.js.map +1 -1
- package/lib/module/handlers/createHandler.js +20 -19
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/index.js +6 -14
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeRNGestureHandlerModule.js +3 -0
- package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -0
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js +3 -0
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js +3 -0
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
- package/lib/typescript/RNGestureHandlerModule.d.ts +2 -6
- package/lib/typescript/RNGestureHandlerModule.d.ts.map +1 -1
- package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
- package/lib/typescript/components/GestureHandlerRootView.d.ts.map +1 -1
- package/lib/typescript/handlers/createHandler.d.ts +11 -11
- package/lib/typescript/handlers/createHandler.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +9 -8
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +15 -0
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts.map +1 -0
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +15 -0
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts.map +1 -0
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +7 -0
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -0
- package/package.json +66 -70
- package/src/RNGestureHandlerModule.ts +5 -6
- package/src/components/GestureHandlerRootView.tsx +23 -34
- package/src/handlers/createHandler.tsx +534 -535
- package/src/index.ts +172 -172
- package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
- package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -0
- package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -0
- package/README.md +0 -1
- package/lib/commonjs/components/GestureButtons.js +0 -186
- package/lib/commonjs/components/GestureButtons.js.map +0 -1
- package/lib/commonjs/components/GestureHandlerButton.js +0 -9
- package/lib/commonjs/components/GestureHandlerButton.js.map +0 -1
- package/lib/commonjs/components/RNGestureHandlerButton.js +0 -23
- package/lib/commonjs/components/RNGestureHandlerButton.js.map +0 -1
- package/lib/commonjs/components/touchables/GenericTouchable.js +0 -247
- package/lib/commonjs/components/touchables/GenericTouchable.js.map +0 -1
- package/lib/commonjs/components/touchables/TouchableOpacity.js +0 -58
- package/lib/commonjs/components/touchables/TouchableOpacity.js.map +0 -1
- package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js +0 -18
- package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js.map +0 -1
- package/lib/commonjs/components/touchables/index.js +0 -21
- package/lib/commonjs/components/touchables/index.js.map +0 -1
- package/lib/commonjs/handlers/NativeViewGestureHandler.js +0 -19
- package/lib/commonjs/handlers/NativeViewGestureHandler.js.map +0 -1
- package/lib/commonjs/handlers/PanGestureHandler.js +0 -103
- package/lib/commonjs/handlers/PanGestureHandler.js.map +0 -1
- package/lib/commonjs/handlers/TapGestureHandler.js +0 -22
- package/lib/commonjs/handlers/TapGestureHandler.js.map +0 -1
- package/lib/commonjs/handlers/createNativeWrapper.js +0 -64
- package/lib/commonjs/handlers/createNativeWrapper.js.map +0 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js +0 -22
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +0 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +0 -554
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +0 -1
- package/lib/commonjs/init.js +0 -24
- package/lib/commonjs/init.js.map +0 -1
- package/lib/module/components/GestureButtons.js +0 -168
- package/lib/module/components/GestureButtons.js.map +0 -1
- package/lib/module/components/GestureHandlerButton.js +0 -3
- package/lib/module/components/GestureHandlerButton.js.map +0 -1
- package/lib/module/components/RNGestureHandlerButton.js +0 -17
- package/lib/module/components/RNGestureHandlerButton.js.map +0 -1
- package/lib/module/components/touchables/GenericTouchable.js +0 -238
- package/lib/module/components/touchables/GenericTouchable.js.map +0 -1
- package/lib/module/components/touchables/TouchableOpacity.js +0 -49
- package/lib/module/components/touchables/TouchableOpacity.js.map +0 -1
- package/lib/module/components/touchables/TouchableWithoutFeedback.js +0 -9
- package/lib/module/components/touchables/TouchableWithoutFeedback.js.map +0 -1
- package/lib/module/components/touchables/index.js +0 -8
- package/lib/module/components/touchables/index.js.map +0 -1
- package/lib/module/handlers/NativeViewGestureHandler.js +0 -12
- package/lib/module/handlers/NativeViewGestureHandler.js.map +0 -1
- package/lib/module/handlers/PanGestureHandler.js +0 -92
- package/lib/module/handlers/PanGestureHandler.js.map +0 -1
- package/lib/module/handlers/TapGestureHandler.js +0 -14
- package/lib/module/handlers/TapGestureHandler.js.map +0 -1
- package/lib/module/handlers/createNativeWrapper.js +0 -57
- package/lib/module/handlers/createNativeWrapper.js.map +0 -1
- package/lib/module/handlers/gestureHandlerCommon.js +0 -15
- package/lib/module/handlers/gestureHandlerCommon.js.map +0 -1
- package/lib/module/handlers/gestures/GestureDetector.js +0 -543
- package/lib/module/handlers/gestures/GestureDetector.js.map +0 -1
- package/lib/module/init.js +0 -17
- package/lib/module/init.js.map +0 -1
- package/lib/typescript/components/GestureButtons.d.ts +0 -122
- package/lib/typescript/components/GestureButtons.d.ts.map +0 -1
- package/lib/typescript/components/GestureHandlerButton.d.ts +0 -5
- package/lib/typescript/components/GestureHandlerButton.d.ts.map +0 -1
- package/lib/typescript/components/RNGestureHandlerButton.d.ts +0 -2
- package/lib/typescript/components/RNGestureHandlerButton.d.ts.map +0 -1
- package/lib/typescript/components/touchables/GenericTouchable.d.ts +0 -68
- package/lib/typescript/components/touchables/GenericTouchable.d.ts.map +0 -1
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts +0 -26
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts.map +0 -1
- package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts +0 -8
- package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts.map +0 -1
- package/lib/typescript/components/touchables/index.d.ts +0 -4
- package/lib/typescript/components/touchables/index.d.ts.map +0 -1
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +0 -29
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts.map +0 -1
- package/lib/typescript/handlers/PanGestureHandler.d.ts +0 -140
- package/lib/typescript/handlers/PanGestureHandler.d.ts.map +0 -1
- package/lib/typescript/handlers/TapGestureHandler.d.ts +0 -58
- package/lib/typescript/handlers/TapGestureHandler.d.ts.map +0 -1
- package/lib/typescript/handlers/createNativeWrapper.d.ts +0 -4
- package/lib/typescript/handlers/createNativeWrapper.d.ts.map +0 -1
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +0 -2
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts.map +0 -1
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts +0 -24
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts.map +0 -1
- package/lib/typescript/init.d.ts +0 -3
- package/lib/typescript/init.d.ts.map +0 -1
- package/src/components/GestureButtons.tsx +0 -334
- package/src/components/GestureHandlerButton.tsx +0 -5
- package/src/components/RNGestureHandlerButton.tsx +0 -23
- package/src/components/touchables/GenericTouchable.tsx +0 -301
- package/src/components/touchables/TouchableOpacity.tsx +0 -76
- package/src/components/touchables/TouchableWithoutFeedback.tsx +0 -14
- package/src/components/touchables/index.ts +0 -7
- package/src/handlers/NativeViewGestureHandler.ts +0 -55
- package/src/handlers/PanGestureHandler.ts +0 -327
- package/src/handlers/TapGestureHandler.ts +0 -95
- package/src/handlers/createNativeWrapper.tsx +0 -81
- package/src/handlers/gestureHandlerCommon.ts +0 -15
- package/src/handlers/gestures/GestureDetector.tsx +0 -823
- package/src/init.ts +0 -18
@@ -1,202 +1,203 @@
|
|
1
|
-
import { Point } from "rnoh"
|
2
|
-
import { GestureHandler } from "./GestureHandler"
|
3
|
-
import { AdaptedEvent, EventType, PointerType, TouchEventType, Touch } from "./Event"
|
4
|
-
import { View } from "./View"
|
5
|
-
import { RNGHLogger } from "./RNGHLogger"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
private
|
10
|
-
private
|
11
|
-
private
|
12
|
-
private
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
this.
|
18
|
-
this.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
const
|
26
|
-
this.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
const
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
this.
|
75
|
-
this.
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
changedTouch.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
const
|
129
|
-
const
|
130
|
-
const
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
1
|
+
import { Point } from "@rnoh/react-native-openharmony/ts"
|
2
|
+
import { GestureHandler } from "./GestureHandler"
|
3
|
+
import { AdaptedEvent, EventType, PointerType, TouchEventType, Touch } from "./Event"
|
4
|
+
import { View } from "./View"
|
5
|
+
import { RNGHLogger } from "./RNGHLogger"
|
6
|
+
import { TouchEvent, TouchType, TouchObject } from "./types"
|
7
|
+
|
8
|
+
export class GestureHandlerArkUIAdapter {
|
9
|
+
private activePointerIds = new Set<number>()
|
10
|
+
private pointersIdInBounds = new Set<number>()
|
11
|
+
private gestureHandler: GestureHandler
|
12
|
+
private view: View
|
13
|
+
private logger: RNGHLogger
|
14
|
+
|
15
|
+
constructor(gestureHandler: GestureHandler, view: View, logger: RNGHLogger) {
|
16
|
+
logger.info("constructor")
|
17
|
+
this.gestureHandler = gestureHandler
|
18
|
+
this.view = view
|
19
|
+
this.logger = logger
|
20
|
+
}
|
21
|
+
|
22
|
+
handleTouch(e: TouchEvent) {
|
23
|
+
for (const changedTouch of e.changedTouches) {
|
24
|
+
if (this.shouldSkipTouch(changedTouch)) continue;
|
25
|
+
const wasInBounds = this.pointersIdInBounds.has(changedTouch.id)
|
26
|
+
const isInBounds = this.isInBounds({ x: changedTouch.windowX, y: changedTouch.windowY })
|
27
|
+
this.logger.info(`handleTouch: ${JSON.stringify({ type: changedTouch.type, wasInBounds, isInBounds })}`)
|
28
|
+
const adaptedEvent = this.adaptTouchEvent(e, changedTouch)
|
29
|
+
switch (adaptedEvent.eventType) {
|
30
|
+
case EventType.DOWN:
|
31
|
+
this.gestureHandler.onPointerDown(adaptedEvent)
|
32
|
+
break;
|
33
|
+
case EventType.ADDITIONAL_POINTER_DOWN:
|
34
|
+
this.gestureHandler.onAdditionalPointerAdd(adaptedEvent)
|
35
|
+
break;
|
36
|
+
case EventType.UP:
|
37
|
+
this.gestureHandler.onPointerUp(adaptedEvent)
|
38
|
+
break;
|
39
|
+
case EventType.ADDITIONAL_POINTER_UP:
|
40
|
+
this.gestureHandler.onAdditionalPointerRemove(adaptedEvent)
|
41
|
+
break;
|
42
|
+
case EventType.MOVE:
|
43
|
+
if (!wasInBounds && !isInBounds)
|
44
|
+
this.gestureHandler.onPointerOutOfBounds(adaptedEvent)
|
45
|
+
else
|
46
|
+
this.gestureHandler.onPointerMove(adaptedEvent)
|
47
|
+
break;
|
48
|
+
case EventType.ENTER:
|
49
|
+
this.gestureHandler.onPointerEnter(adaptedEvent)
|
50
|
+
break;
|
51
|
+
case EventType.OUT:
|
52
|
+
this.gestureHandler.onPointerOut(adaptedEvent)
|
53
|
+
break;
|
54
|
+
case EventType.CANCEL:
|
55
|
+
this.gestureHandler.onPointerCancel(adaptedEvent)
|
56
|
+
break;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
private shouldSkipTouch(changedTouch: TouchObject): boolean {
|
62
|
+
return changedTouch.type === TouchType.Down && !this.isInBounds({
|
63
|
+
x: changedTouch.windowX,
|
64
|
+
y: changedTouch.windowY
|
65
|
+
})
|
66
|
+
}
|
67
|
+
|
68
|
+
private adaptTouchEvent(e: TouchEvent, changedTouch: TouchObject): AdaptedEvent {
|
69
|
+
const xAbsolute = changedTouch.windowX
|
70
|
+
const yAbsolute = changedTouch.windowY
|
71
|
+
|
72
|
+
const eventType = this.mapTouchTypeToEventType(
|
73
|
+
changedTouch.type,
|
74
|
+
this.activePointerIds.size,
|
75
|
+
this.isInBounds({ x: xAbsolute, y: yAbsolute }),
|
76
|
+
this.pointersIdInBounds.has(changedTouch.id)
|
77
|
+
)
|
78
|
+
this.updateIsInBoundsByPointerId(
|
79
|
+
changedTouch.type,
|
80
|
+
changedTouch.id,
|
81
|
+
xAbsolute,
|
82
|
+
yAbsolute
|
83
|
+
)
|
84
|
+
this.updateActivePointers(changedTouch.type, changedTouch.id)
|
85
|
+
return {
|
86
|
+
x: xAbsolute,
|
87
|
+
y: yAbsolute,
|
88
|
+
offsetX: xAbsolute - this.view.getBoundingRect().x,
|
89
|
+
offsetY: yAbsolute - this.view.getBoundingRect().y,
|
90
|
+
pointerId: changedTouch.id,
|
91
|
+
eventType: eventType,
|
92
|
+
pointerType: PointerType.TOUCH,
|
93
|
+
buttons: 0,
|
94
|
+
time: e.timestamp,
|
95
|
+
allTouches: e.touches.map((touch) => this.mapTouchObjectToTouch(touch)),
|
96
|
+
changedTouches: e.changedTouches.map((touch) => this.mapTouchObjectToTouch(touch)),
|
97
|
+
touchEventType: this.mapTouchTypeToTouchEventType(changedTouch.type)
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
private updateIsInBoundsByPointerId(
|
102
|
+
touchType: TouchType,
|
103
|
+
pointerId: number,
|
104
|
+
x: number,
|
105
|
+
y: number
|
106
|
+
) {
|
107
|
+
switch (touchType) {
|
108
|
+
case TouchType.Down:
|
109
|
+
if (this.isInBounds({ x, y }))
|
110
|
+
this.pointersIdInBounds.add(pointerId)
|
111
|
+
break;
|
112
|
+
case TouchType.Move:
|
113
|
+
if (this.isInBounds({ x, y }))
|
114
|
+
this.pointersIdInBounds.add(pointerId)
|
115
|
+
else
|
116
|
+
this.pointersIdInBounds.delete(pointerId)
|
117
|
+
break;
|
118
|
+
case TouchType.Up:
|
119
|
+
this.pointersIdInBounds.delete(pointerId)
|
120
|
+
break;
|
121
|
+
case TouchType.Cancel:
|
122
|
+
this.pointersIdInBounds.delete(pointerId)
|
123
|
+
break;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
private isInBounds(point: Point): boolean {
|
128
|
+
const x = point.x
|
129
|
+
const y = point.y
|
130
|
+
const rect = this.view.getBoundingRect()
|
131
|
+
const result = x >= rect.x && x <= (rect.x + rect.width) && y >= rect.y && y <= (rect.y + rect.height)
|
132
|
+
return result;
|
133
|
+
}
|
134
|
+
|
135
|
+
private updateActivePointers(touchType: TouchType, pointerId: number): void {
|
136
|
+
switch (touchType) {
|
137
|
+
case TouchType.Down:
|
138
|
+
this.activePointerIds.add(pointerId)
|
139
|
+
case TouchType.Up:
|
140
|
+
this.activePointerIds.delete(pointerId)
|
141
|
+
case TouchType.Cancel:
|
142
|
+
this.activePointerIds.clear()
|
143
|
+
default:
|
144
|
+
return
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
private mapTouchObjectToTouch(touchObject: TouchObject): Touch {
|
149
|
+
return {
|
150
|
+
id: touchObject.id,
|
151
|
+
x: touchObject.x,
|
152
|
+
y: touchObject.y,
|
153
|
+
absoluteX: touchObject.windowX,
|
154
|
+
absoluteY: touchObject.windowY
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
private mapTouchTypeToEventType(
|
159
|
+
touchType: TouchType,
|
160
|
+
activePointersCounter: number,
|
161
|
+
isCurrentlyInBounds: boolean,
|
162
|
+
wasInBounds: boolean
|
163
|
+
): EventType {
|
164
|
+
switch (touchType) {
|
165
|
+
case TouchType.Down:
|
166
|
+
if (activePointersCounter > 0)
|
167
|
+
return EventType.ADDITIONAL_POINTER_DOWN
|
168
|
+
else
|
169
|
+
return EventType.DOWN
|
170
|
+
case TouchType.Up:
|
171
|
+
if (activePointersCounter > 1)
|
172
|
+
return EventType.ADDITIONAL_POINTER_UP
|
173
|
+
else
|
174
|
+
return EventType.UP
|
175
|
+
case TouchType.Move:
|
176
|
+
if (isCurrentlyInBounds) {
|
177
|
+
return wasInBounds ? EventType.MOVE : EventType.ENTER
|
178
|
+
} else {
|
179
|
+
return wasInBounds ? EventType.OUT : EventType.MOVE
|
180
|
+
}
|
181
|
+
case TouchType.Cancel:
|
182
|
+
return EventType.CANCEL
|
183
|
+
default:
|
184
|
+
console.error("RNGH", "Unknown touchType:", touchType)
|
185
|
+
throw new Error("Unknown touchType")
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
private mapTouchTypeToTouchEventType(touchType: TouchType): TouchEventType {
|
190
|
+
switch (touchType) {
|
191
|
+
case TouchType.Down:
|
192
|
+
return TouchEventType.DOWN
|
193
|
+
case TouchType.Up:
|
194
|
+
return TouchEventType.UP
|
195
|
+
case TouchType.Move:
|
196
|
+
return TouchEventType.MOVE
|
197
|
+
case TouchType.Cancel:
|
198
|
+
return TouchEventType.CANCELLED
|
199
|
+
default:
|
200
|
+
return TouchEventType.UNDETERMINED
|
201
|
+
}
|
202
|
+
}
|
202
203
|
}
|
@@ -1,45 +1,45 @@
|
|
1
|
-
import { GestureHandlerOrchestrator } from './GestureHandlerOrchestrator';
|
2
|
-
import { GestureHandler, GestureHandlerDependencies, ScrollLocker } from "./GestureHandler"
|
3
|
-
import { PointerTracker } from './PointerTracker';
|
4
|
-
import { RNGHError } from "./RNGHError"
|
5
|
-
import { InteractionManager } from './InteractionManager';
|
6
|
-
import { RNGHLogger } from './RNGHLogger';
|
7
|
-
import { TapGestureHandler } from './TapGestureHandler';
|
8
|
-
import { PanGestureHandler } from "./PanGestureHandler"
|
9
|
-
import { NativeViewGestureHandler } from "./NativeViewGestureHandler"
|
10
|
-
|
11
|
-
|
12
|
-
export class GestureHandlerFactory {
|
13
|
-
private orchestrator: GestureHandlerOrchestrator
|
14
|
-
private interactionManager = new InteractionManager()
|
15
|
-
private factoryLogger: RNGHLogger
|
16
|
-
|
17
|
-
constructor(private logger: RNGHLogger, private scrollLocker: ScrollLocker) {
|
18
|
-
this.factoryLogger = logger.cloneWithPrefix("Factory")
|
19
|
-
this.orchestrator = new GestureHandlerOrchestrator(logger.cloneWithPrefix("Orchestrator"))
|
20
|
-
}
|
21
|
-
|
22
|
-
create(handlerName: string, handlerTag: number): GestureHandler {
|
23
|
-
this.factoryLogger.info(`create ${handlerName} with handlerTag: ${handlerTag}`)
|
24
|
-
const deps: GestureHandlerDependencies = {
|
25
|
-
tracker: new PointerTracker(),
|
26
|
-
orchestrator: this.orchestrator,
|
27
|
-
handlerTag,
|
28
|
-
interactionManager: this.interactionManager,
|
29
|
-
logger: this.logger.cloneWithPrefix("GestureHandler"),
|
30
|
-
scrollLocker: this.scrollLocker,
|
31
|
-
}
|
32
|
-
switch (handlerName) {
|
33
|
-
case "TapGestureHandler":
|
34
|
-
return new TapGestureHandler(deps)
|
35
|
-
case "PanGestureHandler":
|
36
|
-
return new PanGestureHandler(deps)
|
37
|
-
case "NativeViewGestureHandler":
|
38
|
-
return new NativeViewGestureHandler(deps)
|
39
|
-
default:
|
40
|
-
const msg = `Unknown handler type: ${handlerName}`
|
41
|
-
this.factoryLogger.info(msg)
|
42
|
-
throw new RNGHError(msg)
|
43
|
-
}
|
44
|
-
}
|
1
|
+
import { GestureHandlerOrchestrator } from './GestureHandlerOrchestrator';
|
2
|
+
import { GestureHandler, GestureHandlerDependencies, ScrollLocker } from "./GestureHandler"
|
3
|
+
import { PointerTracker } from './PointerTracker';
|
4
|
+
import { RNGHError } from "./RNGHError"
|
5
|
+
import { InteractionManager } from './InteractionManager';
|
6
|
+
import { RNGHLogger } from './RNGHLogger';
|
7
|
+
import { TapGestureHandler } from './TapGestureHandler';
|
8
|
+
import { PanGestureHandler } from "./PanGestureHandler"
|
9
|
+
import { NativeViewGestureHandler } from "./NativeViewGestureHandler"
|
10
|
+
|
11
|
+
|
12
|
+
export class GestureHandlerFactory {
|
13
|
+
private orchestrator: GestureHandlerOrchestrator
|
14
|
+
private interactionManager = new InteractionManager()
|
15
|
+
private factoryLogger: RNGHLogger
|
16
|
+
|
17
|
+
constructor(private logger: RNGHLogger, private scrollLocker: ScrollLocker) {
|
18
|
+
this.factoryLogger = logger.cloneWithPrefix("Factory")
|
19
|
+
this.orchestrator = new GestureHandlerOrchestrator(logger.cloneWithPrefix("Orchestrator"))
|
20
|
+
}
|
21
|
+
|
22
|
+
create(handlerName: string, handlerTag: number): GestureHandler {
|
23
|
+
this.factoryLogger.info(`create ${handlerName} with handlerTag: ${handlerTag}`)
|
24
|
+
const deps: GestureHandlerDependencies = {
|
25
|
+
tracker: new PointerTracker(),
|
26
|
+
orchestrator: this.orchestrator,
|
27
|
+
handlerTag,
|
28
|
+
interactionManager: this.interactionManager,
|
29
|
+
logger: this.logger.cloneWithPrefix("GestureHandler"),
|
30
|
+
scrollLocker: this.scrollLocker,
|
31
|
+
}
|
32
|
+
switch (handlerName) {
|
33
|
+
case "TapGestureHandler":
|
34
|
+
return new TapGestureHandler(deps)
|
35
|
+
case "PanGestureHandler":
|
36
|
+
return new PanGestureHandler(deps)
|
37
|
+
case "NativeViewGestureHandler":
|
38
|
+
return new NativeViewGestureHandler(deps)
|
39
|
+
default:
|
40
|
+
const msg = `Unknown handler type: ${handlerName}`
|
41
|
+
this.factoryLogger.info(msg)
|
42
|
+
throw new RNGHError(msg)
|
43
|
+
}
|
44
|
+
}
|
45
45
|
}
|