@react-native-oh-tpl/react-native-gesture-handler 2.12.6-1 → 2.12.6-2
Sign up to get free protection for your applications and to get access to all the features.
- 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,202 +1,202 @@
|
|
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
|
-
export class GestureHandlerArkUIAdapter {
|
8
|
-
private activePointerIds = new Set<number>()
|
9
|
-
private pointersIdInBounds = new Set<number>()
|
10
|
-
private gestureHandler: GestureHandler
|
11
|
-
private view: View
|
12
|
-
private logger: RNGHLogger
|
13
|
-
|
14
|
-
constructor(gestureHandler: GestureHandler, view: View, logger: RNGHLogger) {
|
15
|
-
logger.info("constructor")
|
16
|
-
this.gestureHandler = gestureHandler
|
17
|
-
this.view = view
|
18
|
-
this.logger = logger
|
19
|
-
}
|
20
|
-
|
21
|
-
handleTouch(e: TouchEvent) {
|
22
|
-
for (const changedTouch of e.changedTouches) {
|
23
|
-
if (this.shouldSkipTouch(changedTouch)) continue;
|
24
|
-
const wasInBounds = this.pointersIdInBounds.has(changedTouch.id)
|
25
|
-
const isInBounds = this.isInBounds({ x: changedTouch.windowX, y: changedTouch.windowY })
|
26
|
-
this.logger.info(`handleTouch: ${JSON.stringify({ type: changedTouch.type, wasInBounds, isInBounds })}`)
|
27
|
-
const adaptedEvent = this.adaptTouchEvent(e, changedTouch)
|
28
|
-
switch (adaptedEvent.eventType) {
|
29
|
-
case EventType.DOWN:
|
30
|
-
this.gestureHandler.onPointerDown(adaptedEvent)
|
31
|
-
break;
|
32
|
-
case EventType.ADDITIONAL_POINTER_DOWN:
|
33
|
-
this.gestureHandler.onAdditionalPointerAdd(adaptedEvent)
|
34
|
-
break;
|
35
|
-
case EventType.UP:
|
36
|
-
this.gestureHandler.onPointerUp(adaptedEvent)
|
37
|
-
break;
|
38
|
-
case EventType.ADDITIONAL_POINTER_UP:
|
39
|
-
this.gestureHandler.onAdditionalPointerRemove(adaptedEvent)
|
40
|
-
break;
|
41
|
-
case EventType.MOVE:
|
42
|
-
if (!wasInBounds && !isInBounds)
|
43
|
-
this.gestureHandler.onPointerOutOfBounds(adaptedEvent)
|
44
|
-
else
|
45
|
-
this.gestureHandler.onPointerMove(adaptedEvent)
|
46
|
-
break;
|
47
|
-
case EventType.ENTER:
|
48
|
-
this.gestureHandler.onPointerEnter(adaptedEvent)
|
49
|
-
break;
|
50
|
-
case EventType.OUT:
|
51
|
-
this.gestureHandler.onPointerOut(adaptedEvent)
|
52
|
-
break;
|
53
|
-
case EventType.CANCEL:
|
54
|
-
this.gestureHandler.onPointerCancel(adaptedEvent)
|
55
|
-
break;
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
private shouldSkipTouch(changedTouch: TouchObject): boolean {
|
61
|
-
return changedTouch.type === TouchType.Down && !this.isInBounds({
|
62
|
-
x: changedTouch.windowX,
|
63
|
-
y: changedTouch.windowY
|
64
|
-
})
|
65
|
-
}
|
66
|
-
|
67
|
-
private adaptTouchEvent(e: TouchEvent, changedTouch: TouchObject): AdaptedEvent {
|
68
|
-
const xAbsolute = changedTouch.windowX
|
69
|
-
const yAbsolute = changedTouch.windowY
|
70
|
-
|
71
|
-
const eventType = this.mapTouchTypeToEventType(
|
72
|
-
changedTouch.type,
|
73
|
-
this.activePointerIds.size,
|
74
|
-
this.isInBounds({ x: xAbsolute, y: yAbsolute }),
|
75
|
-
this.pointersIdInBounds.has(changedTouch.id)
|
76
|
-
)
|
77
|
-
this.updateIsInBoundsByPointerId(
|
78
|
-
changedTouch.type,
|
79
|
-
changedTouch.id,
|
80
|
-
xAbsolute,
|
81
|
-
yAbsolute
|
82
|
-
)
|
83
|
-
this.updateActivePointers(changedTouch.type, changedTouch.id)
|
84
|
-
return {
|
85
|
-
x: xAbsolute,
|
86
|
-
y: yAbsolute,
|
87
|
-
offsetX: xAbsolute - this.view.getBoundingRect().x,
|
88
|
-
offsetY: yAbsolute - this.view.getBoundingRect().y,
|
89
|
-
pointerId: changedTouch.id,
|
90
|
-
eventType: eventType,
|
91
|
-
pointerType: PointerType.TOUCH,
|
92
|
-
buttons: 0,
|
93
|
-
time: e.timestamp,
|
94
|
-
allTouches: e.touches.map((touch) => this.mapTouchObjectToTouch(touch)),
|
95
|
-
changedTouches: e.changedTouches.map((touch) => this.mapTouchObjectToTouch(touch)),
|
96
|
-
touchEventType: this.mapTouchTypeToTouchEventType(changedTouch.type)
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
private updateIsInBoundsByPointerId(
|
101
|
-
touchType: TouchType,
|
102
|
-
pointerId: number,
|
103
|
-
x: number,
|
104
|
-
y: number
|
105
|
-
) {
|
106
|
-
switch (touchType) {
|
107
|
-
case TouchType.Down:
|
108
|
-
if (this.isInBounds({ x, y }))
|
109
|
-
this.pointersIdInBounds.add(pointerId)
|
110
|
-
break;
|
111
|
-
case TouchType.Move:
|
112
|
-
if (this.isInBounds({ x, y }))
|
113
|
-
this.pointersIdInBounds.add(pointerId)
|
114
|
-
else
|
115
|
-
this.pointersIdInBounds.delete(pointerId)
|
116
|
-
break;
|
117
|
-
case TouchType.Up:
|
118
|
-
this.pointersIdInBounds.delete(pointerId)
|
119
|
-
break;
|
120
|
-
case TouchType.Cancel:
|
121
|
-
this.pointersIdInBounds.delete(pointerId)
|
122
|
-
break;
|
123
|
-
}
|
124
|
-
}
|
125
|
-
|
126
|
-
private isInBounds(point: Point): boolean {
|
127
|
-
const x = point.x
|
128
|
-
const y = point.y
|
129
|
-
const rect = this.view.getBoundingRect()
|
130
|
-
const result = x >= rect.x && x <= (rect.x + rect.width) && y >= rect.y && y <= (rect.y + rect.height)
|
131
|
-
return result;
|
132
|
-
}
|
133
|
-
|
134
|
-
private updateActivePointers(touchType: TouchType, pointerId: number): void {
|
135
|
-
switch (touchType) {
|
136
|
-
case TouchType.Down:
|
137
|
-
this.activePointerIds.add(pointerId)
|
138
|
-
case TouchType.Up:
|
139
|
-
this.activePointerIds.delete(pointerId)
|
140
|
-
case TouchType.Cancel:
|
141
|
-
this.activePointerIds.clear()
|
142
|
-
default:
|
143
|
-
return
|
144
|
-
}
|
145
|
-
}
|
146
|
-
|
147
|
-
private mapTouchObjectToTouch(touchObject: TouchObject): Touch {
|
148
|
-
return {
|
149
|
-
id: touchObject.id,
|
150
|
-
x: touchObject.x,
|
151
|
-
y: touchObject.y,
|
152
|
-
absoluteX: touchObject.windowX,
|
153
|
-
absoluteY: touchObject.windowY
|
154
|
-
}
|
155
|
-
}
|
156
|
-
|
157
|
-
private mapTouchTypeToEventType(
|
158
|
-
touchType: TouchType,
|
159
|
-
activePointersCounter: number,
|
160
|
-
isCurrentlyInBounds: boolean,
|
161
|
-
wasInBounds: boolean
|
162
|
-
): EventType {
|
163
|
-
switch (touchType) {
|
164
|
-
case TouchType.Down:
|
165
|
-
if (activePointersCounter > 0)
|
166
|
-
return EventType.ADDITIONAL_POINTER_DOWN
|
167
|
-
else
|
168
|
-
return EventType.DOWN
|
169
|
-
case TouchType.Up:
|
170
|
-
if (activePointersCounter > 1)
|
171
|
-
return EventType.ADDITIONAL_POINTER_UP
|
172
|
-
else
|
173
|
-
return EventType.UP
|
174
|
-
case TouchType.Move:
|
175
|
-
if (isCurrentlyInBounds) {
|
176
|
-
return wasInBounds ? EventType.MOVE : EventType.ENTER
|
177
|
-
} else {
|
178
|
-
return wasInBounds ? EventType.OUT : EventType.MOVE
|
179
|
-
}
|
180
|
-
case TouchType.Cancel:
|
181
|
-
return EventType.CANCEL
|
182
|
-
default:
|
183
|
-
console.error("RNGH", "Unknown touchType:", touchType)
|
184
|
-
throw new Error("Unknown touchType")
|
185
|
-
}
|
186
|
-
}
|
187
|
-
|
188
|
-
private mapTouchTypeToTouchEventType(touchType: TouchType): TouchEventType {
|
189
|
-
switch (touchType) {
|
190
|
-
case TouchType.Down:
|
191
|
-
return TouchEventType.DOWN
|
192
|
-
case TouchType.Up:
|
193
|
-
return TouchEventType.UP
|
194
|
-
case TouchType.Move:
|
195
|
-
return TouchEventType.MOVE
|
196
|
-
case TouchType.Cancel:
|
197
|
-
return TouchEventType.CANCELLED
|
198
|
-
default:
|
199
|
-
return TouchEventType.UNDETERMINED
|
200
|
-
}
|
201
|
-
}
|
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
|
+
export class GestureHandlerArkUIAdapter {
|
8
|
+
private activePointerIds = new Set<number>()
|
9
|
+
private pointersIdInBounds = new Set<number>()
|
10
|
+
private gestureHandler: GestureHandler
|
11
|
+
private view: View
|
12
|
+
private logger: RNGHLogger
|
13
|
+
|
14
|
+
constructor(gestureHandler: GestureHandler, view: View, logger: RNGHLogger) {
|
15
|
+
logger.info("constructor")
|
16
|
+
this.gestureHandler = gestureHandler
|
17
|
+
this.view = view
|
18
|
+
this.logger = logger
|
19
|
+
}
|
20
|
+
|
21
|
+
handleTouch(e: TouchEvent) {
|
22
|
+
for (const changedTouch of e.changedTouches) {
|
23
|
+
if (this.shouldSkipTouch(changedTouch)) continue;
|
24
|
+
const wasInBounds = this.pointersIdInBounds.has(changedTouch.id)
|
25
|
+
const isInBounds = this.isInBounds({ x: changedTouch.windowX, y: changedTouch.windowY })
|
26
|
+
this.logger.info(`handleTouch: ${JSON.stringify({ type: changedTouch.type, wasInBounds, isInBounds })}`)
|
27
|
+
const adaptedEvent = this.adaptTouchEvent(e, changedTouch)
|
28
|
+
switch (adaptedEvent.eventType) {
|
29
|
+
case EventType.DOWN:
|
30
|
+
this.gestureHandler.onPointerDown(adaptedEvent)
|
31
|
+
break;
|
32
|
+
case EventType.ADDITIONAL_POINTER_DOWN:
|
33
|
+
this.gestureHandler.onAdditionalPointerAdd(adaptedEvent)
|
34
|
+
break;
|
35
|
+
case EventType.UP:
|
36
|
+
this.gestureHandler.onPointerUp(adaptedEvent)
|
37
|
+
break;
|
38
|
+
case EventType.ADDITIONAL_POINTER_UP:
|
39
|
+
this.gestureHandler.onAdditionalPointerRemove(adaptedEvent)
|
40
|
+
break;
|
41
|
+
case EventType.MOVE:
|
42
|
+
if (!wasInBounds && !isInBounds)
|
43
|
+
this.gestureHandler.onPointerOutOfBounds(adaptedEvent)
|
44
|
+
else
|
45
|
+
this.gestureHandler.onPointerMove(adaptedEvent)
|
46
|
+
break;
|
47
|
+
case EventType.ENTER:
|
48
|
+
this.gestureHandler.onPointerEnter(adaptedEvent)
|
49
|
+
break;
|
50
|
+
case EventType.OUT:
|
51
|
+
this.gestureHandler.onPointerOut(adaptedEvent)
|
52
|
+
break;
|
53
|
+
case EventType.CANCEL:
|
54
|
+
this.gestureHandler.onPointerCancel(adaptedEvent)
|
55
|
+
break;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
private shouldSkipTouch(changedTouch: TouchObject): boolean {
|
61
|
+
return changedTouch.type === TouchType.Down && !this.isInBounds({
|
62
|
+
x: changedTouch.windowX,
|
63
|
+
y: changedTouch.windowY
|
64
|
+
})
|
65
|
+
}
|
66
|
+
|
67
|
+
private adaptTouchEvent(e: TouchEvent, changedTouch: TouchObject): AdaptedEvent {
|
68
|
+
const xAbsolute = changedTouch.windowX
|
69
|
+
const yAbsolute = changedTouch.windowY
|
70
|
+
|
71
|
+
const eventType = this.mapTouchTypeToEventType(
|
72
|
+
changedTouch.type,
|
73
|
+
this.activePointerIds.size,
|
74
|
+
this.isInBounds({ x: xAbsolute, y: yAbsolute }),
|
75
|
+
this.pointersIdInBounds.has(changedTouch.id)
|
76
|
+
)
|
77
|
+
this.updateIsInBoundsByPointerId(
|
78
|
+
changedTouch.type,
|
79
|
+
changedTouch.id,
|
80
|
+
xAbsolute,
|
81
|
+
yAbsolute
|
82
|
+
)
|
83
|
+
this.updateActivePointers(changedTouch.type, changedTouch.id)
|
84
|
+
return {
|
85
|
+
x: xAbsolute,
|
86
|
+
y: yAbsolute,
|
87
|
+
offsetX: xAbsolute - this.view.getBoundingRect().x,
|
88
|
+
offsetY: yAbsolute - this.view.getBoundingRect().y,
|
89
|
+
pointerId: changedTouch.id,
|
90
|
+
eventType: eventType,
|
91
|
+
pointerType: PointerType.TOUCH,
|
92
|
+
buttons: 0,
|
93
|
+
time: e.timestamp,
|
94
|
+
allTouches: e.touches.map((touch) => this.mapTouchObjectToTouch(touch)),
|
95
|
+
changedTouches: e.changedTouches.map((touch) => this.mapTouchObjectToTouch(touch)),
|
96
|
+
touchEventType: this.mapTouchTypeToTouchEventType(changedTouch.type)
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
private updateIsInBoundsByPointerId(
|
101
|
+
touchType: TouchType,
|
102
|
+
pointerId: number,
|
103
|
+
x: number,
|
104
|
+
y: number
|
105
|
+
) {
|
106
|
+
switch (touchType) {
|
107
|
+
case TouchType.Down:
|
108
|
+
if (this.isInBounds({ x, y }))
|
109
|
+
this.pointersIdInBounds.add(pointerId)
|
110
|
+
break;
|
111
|
+
case TouchType.Move:
|
112
|
+
if (this.isInBounds({ x, y }))
|
113
|
+
this.pointersIdInBounds.add(pointerId)
|
114
|
+
else
|
115
|
+
this.pointersIdInBounds.delete(pointerId)
|
116
|
+
break;
|
117
|
+
case TouchType.Up:
|
118
|
+
this.pointersIdInBounds.delete(pointerId)
|
119
|
+
break;
|
120
|
+
case TouchType.Cancel:
|
121
|
+
this.pointersIdInBounds.delete(pointerId)
|
122
|
+
break;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
private isInBounds(point: Point): boolean {
|
127
|
+
const x = point.x
|
128
|
+
const y = point.y
|
129
|
+
const rect = this.view.getBoundingRect()
|
130
|
+
const result = x >= rect.x && x <= (rect.x + rect.width) && y >= rect.y && y <= (rect.y + rect.height)
|
131
|
+
return result;
|
132
|
+
}
|
133
|
+
|
134
|
+
private updateActivePointers(touchType: TouchType, pointerId: number): void {
|
135
|
+
switch (touchType) {
|
136
|
+
case TouchType.Down:
|
137
|
+
this.activePointerIds.add(pointerId)
|
138
|
+
case TouchType.Up:
|
139
|
+
this.activePointerIds.delete(pointerId)
|
140
|
+
case TouchType.Cancel:
|
141
|
+
this.activePointerIds.clear()
|
142
|
+
default:
|
143
|
+
return
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
private mapTouchObjectToTouch(touchObject: TouchObject): Touch {
|
148
|
+
return {
|
149
|
+
id: touchObject.id,
|
150
|
+
x: touchObject.x,
|
151
|
+
y: touchObject.y,
|
152
|
+
absoluteX: touchObject.windowX,
|
153
|
+
absoluteY: touchObject.windowY
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
private mapTouchTypeToEventType(
|
158
|
+
touchType: TouchType,
|
159
|
+
activePointersCounter: number,
|
160
|
+
isCurrentlyInBounds: boolean,
|
161
|
+
wasInBounds: boolean
|
162
|
+
): EventType {
|
163
|
+
switch (touchType) {
|
164
|
+
case TouchType.Down:
|
165
|
+
if (activePointersCounter > 0)
|
166
|
+
return EventType.ADDITIONAL_POINTER_DOWN
|
167
|
+
else
|
168
|
+
return EventType.DOWN
|
169
|
+
case TouchType.Up:
|
170
|
+
if (activePointersCounter > 1)
|
171
|
+
return EventType.ADDITIONAL_POINTER_UP
|
172
|
+
else
|
173
|
+
return EventType.UP
|
174
|
+
case TouchType.Move:
|
175
|
+
if (isCurrentlyInBounds) {
|
176
|
+
return wasInBounds ? EventType.MOVE : EventType.ENTER
|
177
|
+
} else {
|
178
|
+
return wasInBounds ? EventType.OUT : EventType.MOVE
|
179
|
+
}
|
180
|
+
case TouchType.Cancel:
|
181
|
+
return EventType.CANCEL
|
182
|
+
default:
|
183
|
+
console.error("RNGH", "Unknown touchType:", touchType)
|
184
|
+
throw new Error("Unknown touchType")
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
private mapTouchTypeToTouchEventType(touchType: TouchType): TouchEventType {
|
189
|
+
switch (touchType) {
|
190
|
+
case TouchType.Down:
|
191
|
+
return TouchEventType.DOWN
|
192
|
+
case TouchType.Up:
|
193
|
+
return TouchEventType.UP
|
194
|
+
case TouchType.Move:
|
195
|
+
return TouchEventType.MOVE
|
196
|
+
case TouchType.Cancel:
|
197
|
+
return TouchEventType.CANCELLED
|
198
|
+
default:
|
199
|
+
return TouchEventType.UNDETERMINED
|
200
|
+
}
|
201
|
+
}
|
202
202
|
}
|
@@ -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
|
}
|