@react-native-oh-tpl/react-native-gesture-handler 2.14.15 → 2.14.17-rc.0
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/DrawerLayout/index.ts +2 -2
- package/Swipeable/index.ts +2 -2
- package/harmony/gesture_handler.har +0 -0
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.js.map +1 -1
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
- package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
- package/lib/typescript/handlers/createHandler.d.ts +11 -11
- package/lib/typescript/index.d.ts +47 -47
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
- package/package.json +83 -78
- package/src/RNGestureHandlerModule.ts +4 -4
- package/src/components/GestureHandlerRootView.tsx +23 -23
- package/src/handlers/createHandler.tsx +534 -534
- package/src/index.ts +172 -172
- package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
- package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
- package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
- package/harmony/gesture_handler/BuildProfile.ets +0 -17
- package/harmony/gesture_handler/build-profile.json5 +0 -12
- package/harmony/gesture_handler/hvigorfile.ts +0 -2
- package/harmony/gesture_handler/index.ets +0 -2
- package/harmony/gesture_handler/oh-package-lock.json5 +0 -18
- package/harmony/gesture_handler/oh-package.json5 +0 -12
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +0 -8
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +0 -12
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +0 -36
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +0 -32
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +0 -22
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +0 -15
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +0 -36
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +0 -25
- package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp +0 -157
- package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +0 -21
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +0 -27
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +0 -245
- package/harmony/gesture_handler/src/main/ets/RNOHPackage.ets +0 -17
- package/harmony/gesture_handler/src/main/ets/core/CircularBuffer.ts +0 -42
- package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +0 -739
- package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +0 -344
- package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +0 -63
- package/harmony/gesture_handler/src/main/ets/core/IncomingEvent.ts +0 -78
- package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +0 -144
- package/harmony/gesture_handler/src/main/ets/core/LeastSquareSolver.ts +0 -182
- package/harmony/gesture_handler/src/main/ets/core/Multiset.ts +0 -26
- package/harmony/gesture_handler/src/main/ets/core/OutgoingEvent.ts +0 -34
- package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +0 -12
- package/harmony/gesture_handler/src/main/ets/core/PointerTracker.ts +0 -239
- package/harmony/gesture_handler/src/main/ets/core/RNGHError.ts +0 -5
- package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +0 -16
- package/harmony/gesture_handler/src/main/ets/core/State.ts +0 -47
- package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +0 -80
- package/harmony/gesture_handler/src/main/ets/core/VelocityTracker.ts +0 -106
- package/harmony/gesture_handler/src/main/ets/core/View.ts +0 -21
- package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +0 -7
- package/harmony/gesture_handler/src/main/ets/core/index.ts +0 -15
- package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +0 -169
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +0 -219
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +0 -67
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +0 -139
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +0 -50
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +0 -124
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +0 -375
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +0 -174
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +0 -172
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +0 -216
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +0 -167
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +0 -1
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +0 -24
- package/harmony/gesture_handler/src/main/ets/namespace/components/RNGestureHandlerButton.ts +0 -139
- package/harmony/gesture_handler/src/main/ets/namespace/components/RNGestureHandlerRootView.ts +0 -101
- package/harmony/gesture_handler/src/main/ets/namespace/components/ts.ts +0 -2
- package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +0 -2
- package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +0 -25
- package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +0 -107
- package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +0 -94
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootViewController.ts +0 -196
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHView.ts +0 -85
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewController.ts +0 -255
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewRegistry.ts +0 -19
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +0 -267
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +0 -15
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +0 -25
- package/harmony/gesture_handler/src/main/ets/rnoh/types.ts +0 -25
- package/harmony/gesture_handler/src/main/module.json5 +0 -9
- package/harmony/gesture_handler/src/main/resources/base/element/color.json +0 -8
- package/harmony/gesture_handler/src/main/resources/base/element/string.json +0 -16
- package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
- package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +0 -5
- package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +0 -16
- package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +0 -16
- package/harmony/gesture_handler/ts.ts +0 -2
@@ -1,196 +0,0 @@
|
|
1
|
-
import { TouchEvent as TouchEventArkTS, TouchType, TouchObject } from './types';
|
2
|
-
import { RNGHLogger, View, Multiset, GestureHandlerRegistry } from '../core';
|
3
|
-
import { RawTouchableView, RNGHView } from "./RNGHView"
|
4
|
-
import { RNGHViewController } from './RNGHViewController';
|
5
|
-
|
6
|
-
type RawTouchPoint = {
|
7
|
-
pointerId: number;
|
8
|
-
windowX: number;
|
9
|
-
windowY: number;
|
10
|
-
};
|
11
|
-
|
12
|
-
export type RawTouchEvent = {
|
13
|
-
action: number;
|
14
|
-
actionTouch: RawTouchPoint;
|
15
|
-
touchPoints: RawTouchPoint[];
|
16
|
-
sourceType: number;
|
17
|
-
timestamp: number;
|
18
|
-
/** TouchableViews is a list of views from the root to the leaf which contain within their boundaries the touch point specified by `actionTouch`. */
|
19
|
-
touchableViews: RawTouchableView[]
|
20
|
-
};
|
21
|
-
|
22
|
-
|
23
|
-
const areRawTouchPointsEqual = (a: RawTouchPoint, b: RawTouchPoint) =>
|
24
|
-
a.pointerId === b.pointerId &&
|
25
|
-
a.windowX === b.windowX &&
|
26
|
-
a.windowY === b.windowY;
|
27
|
-
|
28
|
-
|
29
|
-
export class RNGHRootViewController {
|
30
|
-
private logger: RNGHLogger;
|
31
|
-
// This multiset keeps track of touchable views that were detected
|
32
|
-
// at the beginning of the gesture to ensure they aren't overridden
|
33
|
-
// during move touch events, which could prevent the gesture handler
|
34
|
-
// from updating its state correctly.
|
35
|
-
private touchableViewsMultiset: Multiset<View> = new Multiset();
|
36
|
-
private viewControllerByViewTag: Map<number, RNGHViewController> =
|
37
|
-
new Map(); // TODO: remove entry when view is removed
|
38
|
-
/**
|
39
|
-
* A view is ACTIVE, if it recently received POINTER_DOWN event
|
40
|
-
*/
|
41
|
-
private activeViewTags = new Set<number>();
|
42
|
-
|
43
|
-
constructor(
|
44
|
-
logger: RNGHLogger,
|
45
|
-
private gestureHandlerRegistry: GestureHandlerRegistry
|
46
|
-
) {
|
47
|
-
this.logger = logger.cloneAndJoinPrefix('RNGHRootTouchHandlerCAPI');
|
48
|
-
}
|
49
|
-
|
50
|
-
handleTouch(rawTouchEvent: RawTouchEvent, touchableViews: View[]) {
|
51
|
-
/**
|
52
|
-
* NOTE: TouchEventArkTS was used in ArkTS RNOH architecture. Currently only C-API architecture is supported.
|
53
|
-
*/
|
54
|
-
const touchEvent = rawTouchEventToTouchEventArkTS(rawTouchEvent);
|
55
|
-
if (touchEvent.type === TouchType.Down) {
|
56
|
-
touchableViews.forEach(view => this.touchableViewsMultiset.add(view));
|
57
|
-
}
|
58
|
-
const e = touchEvent;
|
59
|
-
if (e.type === TouchType.Down) {
|
60
|
-
this.activeViewTags.clear();
|
61
|
-
}
|
62
|
-
const views = touchableViews as RNGHView[]
|
63
|
-
for (let i = 0; i < views.length; i++) {
|
64
|
-
const view = views[i];
|
65
|
-
for (const handler of this.gestureHandlerRegistry.getGestureHandlersByViewTag(
|
66
|
-
view.getTag(),
|
67
|
-
)) {
|
68
|
-
this.logger.info(
|
69
|
-
`Found GestureHandler ${handler.getTag()} for view ${view.getTag()}`,
|
70
|
-
);
|
71
|
-
|
72
|
-
// create view touch handler if necessary
|
73
|
-
if (!this.viewControllerByViewTag.has(view.getTag())) {
|
74
|
-
this.viewControllerByViewTag.set(
|
75
|
-
view.getTag(),
|
76
|
-
new RNGHViewController(
|
77
|
-
view,
|
78
|
-
this.logger,
|
79
|
-
),
|
80
|
-
);
|
81
|
-
}
|
82
|
-
|
83
|
-
// attach handler (there might be multiple handlers per view)
|
84
|
-
this.viewControllerByViewTag.get(view.getTag())!.attachGestureHandler(handler) // TODO: detachGestureHandler
|
85
|
-
|
86
|
-
// register active view tag
|
87
|
-
if (e.type === TouchType.Down) {
|
88
|
-
this.activeViewTags.add(view.getTag());
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
// If the pointer is inside the view but it overflows its parent, handlers attached to the parent
|
93
|
-
// might not have been called correctly (wrong bounding box). Extending the parent bounding box
|
94
|
-
// with the child bounding box ensures that the parent handlers are called correctly.
|
95
|
-
// This approach is slightly different from Android RNGH implementation (extracting parent gesture handlers),
|
96
|
-
// however, the outcome is the same.
|
97
|
-
for (let j = i; j > 1; j--) {
|
98
|
-
const currentView = views[j];
|
99
|
-
const parentView = views[j-1];
|
100
|
-
if (parentView.intersectsWith(currentView)) {
|
101
|
-
parentView.attachChildrenBoundingRects(currentView);
|
102
|
-
}
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
// send touch to gesture handlers, prioritize handling touch events for child components
|
107
|
-
if (this.activeViewTags.size > 0) {
|
108
|
-
const tags = Array.from(this.activeViewTags);
|
109
|
-
for (let i = tags.length - 1; i >= 0; i--) {
|
110
|
-
const tag = tags[i];
|
111
|
-
const viewController = this.viewControllerByViewTag.get(tag);
|
112
|
-
if (viewController) {
|
113
|
-
viewController.handleTouch(e);
|
114
|
-
}
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
|
119
|
-
if (touchEvent.type === TouchType.Up || touchEvent.type === TouchType.Cancel) {
|
120
|
-
touchableViews.forEach(view => this.touchableViewsMultiset.remove(view));
|
121
|
-
}
|
122
|
-
}
|
123
|
-
|
124
|
-
cancelTouches() {
|
125
|
-
for (const activeViewTag of this.activeViewTags) {
|
126
|
-
this.gestureHandlerRegistry.getGestureHandlersByViewTag(activeViewTag).forEach(gh => {
|
127
|
-
gh.cancel()
|
128
|
-
gh.reset()
|
129
|
-
})
|
130
|
-
}
|
131
|
-
}
|
132
|
-
}
|
133
|
-
|
134
|
-
|
135
|
-
const CACHED_RAW_TOUCH_POINT_BY_POINTER_ID = new Map<number, RawTouchPoint>();
|
136
|
-
let LAST_CHANGED_POINTER_ID: number | null = null;
|
137
|
-
const MAX_CACHE_SIZE = 10;
|
138
|
-
|
139
|
-
function rawTouchEventToTouchEventArkTS(raw: RawTouchEvent): TouchEventArkTS {
|
140
|
-
const touchType = touchTypeFromAction(raw.action);
|
141
|
-
const actionTouch = raw.actionTouch;
|
142
|
-
|
143
|
-
let lastChangedTouch: RawTouchPoint = actionTouch;
|
144
|
-
if (CACHED_RAW_TOUCH_POINT_BY_POINTER_ID.has(actionTouch.pointerId)) {
|
145
|
-
if (!areRawTouchPointsEqual(actionTouch,
|
146
|
-
CACHED_RAW_TOUCH_POINT_BY_POINTER_ID.get(actionTouch.pointerId) as RawTouchPoint)) {
|
147
|
-
LAST_CHANGED_POINTER_ID = actionTouch.pointerId;
|
148
|
-
CACHED_RAW_TOUCH_POINT_BY_POINTER_ID.set(actionTouch.pointerId, actionTouch);
|
149
|
-
}
|
150
|
-
} else {
|
151
|
-
// remove first element if the cache is full
|
152
|
-
if (CACHED_RAW_TOUCH_POINT_BY_POINTER_ID.size >= MAX_CACHE_SIZE) {
|
153
|
-
CACHED_RAW_TOUCH_POINT_BY_POINTER_ID.delete(CACHED_RAW_TOUCH_POINT_BY_POINTER_ID.keys().next().value);
|
154
|
-
}
|
155
|
-
LAST_CHANGED_POINTER_ID = actionTouch.pointerId;
|
156
|
-
CACHED_RAW_TOUCH_POINT_BY_POINTER_ID.set(actionTouch.pointerId, actionTouch);
|
157
|
-
}
|
158
|
-
lastChangedTouch = CACHED_RAW_TOUCH_POINT_BY_POINTER_ID.get(LAST_CHANGED_POINTER_ID as number) as RawTouchPoint
|
159
|
-
return {
|
160
|
-
type: touchTypeFromAction(raw.action),
|
161
|
-
touches: raw.touchPoints.map(tp =>
|
162
|
-
touchObjectFromTouchPoint(tp, touchType),
|
163
|
-
),
|
164
|
-
changedTouches: [
|
165
|
-
touchObjectFromTouchPoint(lastChangedTouch, touchType),
|
166
|
-
],
|
167
|
-
timestamp: raw.timestamp / Math.pow(10, 6),
|
168
|
-
};
|
169
|
-
}
|
170
|
-
|
171
|
-
function touchTypeFromAction(action: number): TouchType {
|
172
|
-
switch (action) {
|
173
|
-
case 1:
|
174
|
-
return TouchType.Down;
|
175
|
-
case 2:
|
176
|
-
return TouchType.Move;
|
177
|
-
case 3:
|
178
|
-
return TouchType.Up;
|
179
|
-
default:
|
180
|
-
return TouchType.Cancel;
|
181
|
-
}
|
182
|
-
}
|
183
|
-
|
184
|
-
function touchObjectFromTouchPoint(
|
185
|
-
touchPoint: RawTouchPoint,
|
186
|
-
touchType: TouchType,
|
187
|
-
): TouchObject {
|
188
|
-
return {
|
189
|
-
id: touchPoint.pointerId,
|
190
|
-
windowX: touchPoint.windowX,
|
191
|
-
windowY: touchPoint.windowY,
|
192
|
-
x: touchPoint.windowX,
|
193
|
-
y: touchPoint.windowY,
|
194
|
-
type: touchType,
|
195
|
-
};
|
196
|
-
}
|
@@ -1,85 +0,0 @@
|
|
1
|
-
import { View, BoundingBox } from "../core"
|
2
|
-
|
3
|
-
|
4
|
-
export type RawTouchableView = {
|
5
|
-
tag: number,
|
6
|
-
/**
|
7
|
-
* Relative to application window.
|
8
|
-
*/
|
9
|
-
x: number,
|
10
|
-
/**
|
11
|
-
* Relative to application window.
|
12
|
-
*/
|
13
|
-
y: number,
|
14
|
-
width: number,
|
15
|
-
height: number,
|
16
|
-
buttonRole: boolean,
|
17
|
-
}
|
18
|
-
|
19
|
-
export class RNGHView implements View {
|
20
|
-
private tag: number
|
21
|
-
private buttonRole: boolean
|
22
|
-
private boundingBox: BoundingBox
|
23
|
-
private childrenBoundingBoxes: Set<BoundingBox> = new Set()
|
24
|
-
|
25
|
-
constructor({ tag, buttonRole, ...boundingBox }: RawTouchableView) {
|
26
|
-
this.tag = tag
|
27
|
-
this.buttonRole = buttonRole
|
28
|
-
this.boundingBox = boundingBox
|
29
|
-
}
|
30
|
-
|
31
|
-
getTag(): number {
|
32
|
-
return this.tag
|
33
|
-
}
|
34
|
-
|
35
|
-
getBoundingRect(): BoundingBox {
|
36
|
-
return { ...this.boundingBox }
|
37
|
-
}
|
38
|
-
|
39
|
-
getChildrenBoundingRects(): BoundingBox[] {
|
40
|
-
return Array.from(this.childrenBoundingBoxes)
|
41
|
-
}
|
42
|
-
|
43
|
-
isPositionInBounds({ x, y }: {
|
44
|
-
x: number;
|
45
|
-
y: number
|
46
|
-
}): boolean {
|
47
|
-
const rects = [this.boundingBox, ...this.childrenBoundingBoxes]
|
48
|
-
return rects.some(rect => (
|
49
|
-
x >= rect.x &&
|
50
|
-
x <= rect.x + rect.width &&
|
51
|
-
y >= rect.y &&
|
52
|
-
y <= rect.y + rect.height
|
53
|
-
))
|
54
|
-
}
|
55
|
-
|
56
|
-
updateBoundingBox(boundingBox: BoundingBox) {
|
57
|
-
this.boundingBox = boundingBox
|
58
|
-
}
|
59
|
-
|
60
|
-
attachChildrenBoundingRects(view: RNGHView) {
|
61
|
-
this.childrenBoundingBoxes.add(view.getBoundingRect())
|
62
|
-
for (const childBoundingBox of view.getChildrenBoundingRects()) {
|
63
|
-
this.childrenBoundingBoxes.add(childBoundingBox)
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
intersectsWith(view: RNGHView): boolean {
|
68
|
-
const rect1 = this.getBoundingRect()
|
69
|
-
const rect2 = view.getBoundingRect()
|
70
|
-
return (
|
71
|
-
rect1.x < rect2.x + rect2.width &&
|
72
|
-
rect1.x + rect1.width > rect2.x &&
|
73
|
-
rect1.y < rect2.y + rect2.height &&
|
74
|
-
rect1.y + rect1.height > rect2.y
|
75
|
-
)
|
76
|
-
}
|
77
|
-
|
78
|
-
setButtonRole(buttonRole: boolean) {
|
79
|
-
this.buttonRole = buttonRole
|
80
|
-
}
|
81
|
-
|
82
|
-
hasButtonRole(): boolean {
|
83
|
-
return this.buttonRole
|
84
|
-
}
|
85
|
-
}
|
@@ -1,255 +0,0 @@
|
|
1
|
-
import { Point } from '@rnoh/react-native-openharmony/ts';
|
2
|
-
import {
|
3
|
-
GestureHandler,
|
4
|
-
IncomingEvent,
|
5
|
-
EventType,
|
6
|
-
PointerType,
|
7
|
-
TouchEventType,
|
8
|
-
Touch,
|
9
|
-
RNGHLogger,
|
10
|
-
View
|
11
|
-
} from '../core';
|
12
|
-
import { TouchEvent, TouchType, TouchObject } from './types';
|
13
|
-
|
14
|
-
|
15
|
-
export class RNGHViewController {
|
16
|
-
private activePointerIds = new Set<number>();
|
17
|
-
private pointerIdsInBounds = new Set<number>();
|
18
|
-
private gestureHandlers = new Set<GestureHandler>();
|
19
|
-
private view: View;
|
20
|
-
private logger: RNGHLogger;
|
21
|
-
|
22
|
-
constructor(view: View, logger: RNGHLogger) {
|
23
|
-
this.logger = logger.cloneAndJoinPrefix(`RNGHViewTouchHandler`)
|
24
|
-
this.view = view;
|
25
|
-
}
|
26
|
-
|
27
|
-
attachGestureHandler(gestureHandler: GestureHandler) {
|
28
|
-
this.gestureHandlers.add(gestureHandler)
|
29
|
-
}
|
30
|
-
|
31
|
-
handleTouch(e: TouchEvent) {
|
32
|
-
const logger = this.logger.cloneAndJoinPrefix("handleTouch")
|
33
|
-
for (const changedTouch of e.changedTouches) {
|
34
|
-
if (this.shouldSkipTouch(changedTouch)) {
|
35
|
-
continue;
|
36
|
-
}
|
37
|
-
const wasInBounds = this.pointerIdsInBounds.has(changedTouch.id);
|
38
|
-
const isInBounds = this.isInBounds({
|
39
|
-
x: changedTouch.windowX,
|
40
|
-
y: changedTouch.windowY,
|
41
|
-
});
|
42
|
-
logger.debug(
|
43
|
-
{
|
44
|
-
viewTag: this.view.getTag(),
|
45
|
-
type: changedTouch.type,
|
46
|
-
wasInBounds,
|
47
|
-
isInBounds,
|
48
|
-
},
|
49
|
-
);
|
50
|
-
const adaptedEvent = this.adaptTouchEvent(e, changedTouch);
|
51
|
-
this.gestureHandlers.forEach(gh => {
|
52
|
-
switch (adaptedEvent.eventType) {
|
53
|
-
case EventType.DOWN:
|
54
|
-
gh.onPointerDown(adaptedEvent);
|
55
|
-
break;
|
56
|
-
case EventType.ADDITIONAL_POINTER_DOWN:
|
57
|
-
gh.onAdditionalPointerAdd(adaptedEvent);
|
58
|
-
break;
|
59
|
-
case EventType.UP:
|
60
|
-
gh.onPointerUp(adaptedEvent);
|
61
|
-
break;
|
62
|
-
case EventType.ADDITIONAL_POINTER_UP:
|
63
|
-
gh.onAdditionalPointerRemove(adaptedEvent);
|
64
|
-
break;
|
65
|
-
case EventType.MOVE:
|
66
|
-
if (!wasInBounds && !isInBounds) {
|
67
|
-
gh.onPointerOutOfBounds(adaptedEvent);
|
68
|
-
} else {
|
69
|
-
gh.onPointerMove(adaptedEvent);
|
70
|
-
}
|
71
|
-
break;
|
72
|
-
case EventType.ENTER:
|
73
|
-
gh.onPointerEnter(adaptedEvent);
|
74
|
-
break;
|
75
|
-
case EventType.OUT:
|
76
|
-
gh.onPointerOut(adaptedEvent);
|
77
|
-
break;
|
78
|
-
case EventType.CANCEL:
|
79
|
-
gh.onPointerCancel(adaptedEvent);
|
80
|
-
break;
|
81
|
-
}
|
82
|
-
})
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
private shouldSkipTouch(changedTouch: TouchObject): boolean {
|
87
|
-
return (
|
88
|
-
changedTouch.type === TouchType.Down &&
|
89
|
-
!this.isInBounds({
|
90
|
-
x: changedTouch.windowX,
|
91
|
-
y: changedTouch.windowY,
|
92
|
-
})
|
93
|
-
);
|
94
|
-
}
|
95
|
-
|
96
|
-
private adaptTouchEvent(
|
97
|
-
e: TouchEvent,
|
98
|
-
changedTouch: TouchObject,
|
99
|
-
): IncomingEvent {
|
100
|
-
const xAbsolute = changedTouch.windowX;
|
101
|
-
const yAbsolute = changedTouch.windowY;
|
102
|
-
|
103
|
-
const eventType = this.mapTouchTypeToEventType(
|
104
|
-
changedTouch.type,
|
105
|
-
this.isInBounds({ x: xAbsolute, y: yAbsolute }),
|
106
|
-
changedTouch.id,
|
107
|
-
this.pointerIdsInBounds.has(changedTouch.id),
|
108
|
-
);
|
109
|
-
this.logger.cloneAndJoinPrefix("adaptTouchEvent")
|
110
|
-
.debug({ eventType, activePointersCount: this.activePointerIds.size })
|
111
|
-
this.updateIsInBoundsByPointerId(
|
112
|
-
changedTouch.type,
|
113
|
-
changedTouch.id,
|
114
|
-
xAbsolute,
|
115
|
-
yAbsolute,
|
116
|
-
);
|
117
|
-
this.updateActivePointers(changedTouch.type, changedTouch.id);
|
118
|
-
return {
|
119
|
-
x: xAbsolute,
|
120
|
-
y: yAbsolute,
|
121
|
-
offsetX: xAbsolute - this.view.getBoundingRect().x,
|
122
|
-
offsetY: yAbsolute - this.view.getBoundingRect().y,
|
123
|
-
pointerId: changedTouch.id,
|
124
|
-
eventType: eventType,
|
125
|
-
pointerType: PointerType.TOUCH,
|
126
|
-
buttons: 0,
|
127
|
-
time: e.timestamp,
|
128
|
-
allTouches: e.touches.map(touch => this.mapTouchObjectToTouch(touch)),
|
129
|
-
changedTouches: e.changedTouches.map(touch =>
|
130
|
-
this.mapTouchObjectToTouch(touch),
|
131
|
-
),
|
132
|
-
touchEventType: this.mapTouchTypeToTouchEventType(changedTouch.type),
|
133
|
-
};
|
134
|
-
}
|
135
|
-
|
136
|
-
private updateIsInBoundsByPointerId(
|
137
|
-
touchType: TouchType,
|
138
|
-
pointerId: number,
|
139
|
-
x: number,
|
140
|
-
y: number,
|
141
|
-
) {
|
142
|
-
switch (touchType) {
|
143
|
-
case TouchType.Down:
|
144
|
-
if (this.isInBounds({ x, y })) {
|
145
|
-
this.pointerIdsInBounds.add(pointerId);
|
146
|
-
}
|
147
|
-
break;
|
148
|
-
case TouchType.Move:
|
149
|
-
if (this.isInBounds({
|
150
|
-
x,
|
151
|
-
y
|
152
|
-
})) {
|
153
|
-
this.pointerIdsInBounds.add(pointerId);
|
154
|
-
} else {
|
155
|
-
this.pointerIdsInBounds.delete(pointerId);
|
156
|
-
}
|
157
|
-
break;
|
158
|
-
case TouchType.Up:
|
159
|
-
this.pointerIdsInBounds.delete(pointerId);
|
160
|
-
break;
|
161
|
-
case TouchType.Cancel:
|
162
|
-
this.pointerIdsInBounds.delete(pointerId);
|
163
|
-
break;
|
164
|
-
}
|
165
|
-
}
|
166
|
-
|
167
|
-
private isInBounds(point: Point): boolean {
|
168
|
-
const rect = this.view.getBoundingRect();
|
169
|
-
this.logger.cloneAndJoinPrefix("isInBounds").debug({ rect })
|
170
|
-
return this.view.isPositionInBounds(point);
|
171
|
-
}
|
172
|
-
|
173
|
-
private updateActivePointers(touchType: TouchType, pointerId: number): void {
|
174
|
-
switch (touchType) {
|
175
|
-
case TouchType.Down:
|
176
|
-
this.activePointerIds.add(pointerId);
|
177
|
-
break;
|
178
|
-
case TouchType.Up:
|
179
|
-
this.activePointerIds.delete(pointerId);
|
180
|
-
break;
|
181
|
-
case TouchType.Cancel:
|
182
|
-
this.activePointerIds.clear();
|
183
|
-
break;
|
184
|
-
default:
|
185
|
-
return;
|
186
|
-
}
|
187
|
-
}
|
188
|
-
|
189
|
-
private mapTouchObjectToTouch(touchObject: TouchObject): Touch {
|
190
|
-
return {
|
191
|
-
id: touchObject.id,
|
192
|
-
x: touchObject.x,
|
193
|
-
y: touchObject.y,
|
194
|
-
absoluteX: touchObject.windowX,
|
195
|
-
absoluteY: touchObject.windowY,
|
196
|
-
};
|
197
|
-
}
|
198
|
-
|
199
|
-
private mapTouchTypeToEventType(
|
200
|
-
touchType: TouchType,
|
201
|
-
isCurrentlyInBounds: boolean,
|
202
|
-
pointerId: number,
|
203
|
-
wasInBounds: boolean,
|
204
|
-
): EventType {
|
205
|
-
/**
|
206
|
-
* If user manages to drag finger out of GestureHandlerRootView,
|
207
|
-
* we don't receive UP event.
|
208
|
-
*/
|
209
|
-
let activePointersCount = this.activePointerIds.size
|
210
|
-
if (this.activePointerIds.has(pointerId)) {
|
211
|
-
activePointersCount--;
|
212
|
-
}
|
213
|
-
|
214
|
-
switch (touchType) {
|
215
|
-
case TouchType.Down:
|
216
|
-
if (activePointersCount > 0) {
|
217
|
-
return EventType.ADDITIONAL_POINTER_DOWN;
|
218
|
-
} else {
|
219
|
-
return EventType.DOWN;
|
220
|
-
}
|
221
|
-
case TouchType.Up:
|
222
|
-
if (activePointersCount > 1) {
|
223
|
-
return EventType.ADDITIONAL_POINTER_UP;
|
224
|
-
} else {
|
225
|
-
return EventType.UP;
|
226
|
-
}
|
227
|
-
case TouchType.Move:
|
228
|
-
if (isCurrentlyInBounds) {
|
229
|
-
return wasInBounds ? EventType.MOVE : EventType.ENTER;
|
230
|
-
} else {
|
231
|
-
return wasInBounds ? EventType.OUT : EventType.MOVE;
|
232
|
-
}
|
233
|
-
case TouchType.Cancel:
|
234
|
-
return EventType.CANCEL;
|
235
|
-
default:
|
236
|
-
console.error('RNGH', 'Unknown touchType:', touchType);
|
237
|
-
throw new Error('Unknown touchType');
|
238
|
-
}
|
239
|
-
}
|
240
|
-
|
241
|
-
private mapTouchTypeToTouchEventType(touchType: TouchType): TouchEventType {
|
242
|
-
switch (touchType) {
|
243
|
-
case TouchType.Down:
|
244
|
-
return TouchEventType.DOWN;
|
245
|
-
case TouchType.Up:
|
246
|
-
return TouchEventType.UP;
|
247
|
-
case TouchType.Move:
|
248
|
-
return TouchEventType.MOVE;
|
249
|
-
case TouchType.Cancel:
|
250
|
-
return TouchEventType.CANCELLED;
|
251
|
-
default:
|
252
|
-
return TouchEventType.UNDETERMINED;
|
253
|
-
}
|
254
|
-
}
|
255
|
-
}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import { Tag, } from '@rnoh/react-native-openharmony/ts';
|
2
|
-
import { View, ViewRegistry } from '../core';
|
3
|
-
|
4
|
-
|
5
|
-
export class RNGHViewRegistry implements ViewRegistry {
|
6
|
-
private viewByTag = new Map<Tag, View>()
|
7
|
-
|
8
|
-
save(view: View) {
|
9
|
-
this.viewByTag.set(view.getTag(), view)
|
10
|
-
}
|
11
|
-
|
12
|
-
deleteByTag(viewTag: Tag) {
|
13
|
-
this.viewByTag.delete(viewTag)
|
14
|
-
}
|
15
|
-
|
16
|
-
getViewByTag(viewTag: Tag) {
|
17
|
-
return this.viewByTag.get(viewTag);
|
18
|
-
}
|
19
|
-
}
|