@react-native-oh-tpl/react-native-gesture-handler 2.14.1-2.14.13 → 2.14.1-2.14.14
Sign up to get free protection for your applications and to get access to all the features.
- package/harmony/gesture_handler/BuildProfile.ets +1 -1
- package/harmony/gesture_handler/index.ets +1 -2
- package/harmony/gesture_handler/oh-package-lock.json5 +1 -1
- package/harmony/gesture_handler/oh-package.json5 +1 -1
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +1 -1
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +9 -18
- package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp +157 -0
- package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +21 -0
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +16 -16
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +202 -199
- package/harmony/gesture_handler/src/main/ets/RNOHPackage.ets +17 -0
- package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +84 -35
- package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +20 -11
- package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +2 -2
- package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +4 -4
- package/harmony/gesture_handler/src/main/ets/core/Multiset.ts +26 -0
- package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +7 -3
- package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +1 -2
- package/harmony/gesture_handler/src/main/ets/core/index.ts +2 -2
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +12 -4
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +8 -5
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +14 -2
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +9 -1
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +13 -4
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +31 -12
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +145 -130
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +9 -1
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +15 -5
- package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +7 -4
- package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +74 -16
- package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +35 -12
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootViewController.ts +182 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHView.ts +62 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/{GestureHandlerArkUIAdapter.ts → RNGHViewController.ts} +44 -22
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewRegistry.ts +19 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +127 -93
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +0 -9
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +1 -8
- package/harmony/gesture_handler.har +0 -0
- package/package.json +7 -3
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +0 -149
- package/harmony/gesture_handler/src/main/ets/core/ViewFinder.ts +0 -11
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +0 -98
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +0 -110
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerButton.ets +0 -38
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerRootView.ets +0 -53
- package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +0 -134
- package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +0 -97
@@ -1,15 +1,21 @@
|
|
1
1
|
import { TurboModule, TurboModuleContext, Tag } from "@rnoh/react-native-openharmony/ts";
|
2
2
|
import { TM } from "../namespace/ts"
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
GestureHandlerRegistry,
|
5
|
+
State,
|
6
|
+
OutgoingEventDispatcher,
|
7
|
+
RNGHLogger,
|
8
|
+
InteractionManager,
|
9
|
+
ViewRegistry
|
10
|
+
} from '../core';
|
4
11
|
import { GestureHandlerFactory } from "../gesture-handlers"
|
5
|
-
import {
|
6
|
-
import {
|
12
|
+
import { RNGHViewRegistry } from './RNGHViewRegistry';
|
13
|
+
import { DevelopmentRNGHLogger, ProductionRNGHLogger } from './Logger';
|
7
14
|
import { JSEventDispatcher, AnimatedEventDispatcher, ReanimatedEventDispatcher } from './OutgoingEventDispatchers'
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
import {
|
12
|
-
import { FakeRNGestureResponder, RNOHGestureResponder } from "./RNOHGestureResponder"
|
15
|
+
import { RNOHScrollLockerCAPI } from "./RNOHScrollLocker"
|
16
|
+
import { RNGHRootViewController, RawTouchEvent } from "./RNGHRootViewController"
|
17
|
+
import { RNGHView } from "./RNGHView"
|
18
|
+
import { RNOHGestureResponder } from "./RNOHGestureResponder"
|
13
19
|
|
14
20
|
export enum ActionType {
|
15
21
|
REANIMATED_WORKLET = 1,
|
@@ -20,22 +26,26 @@ export enum ActionType {
|
|
20
26
|
|
21
27
|
|
22
28
|
export class RNGestureHandlerModule extends TurboModule implements TM.RNGestureHandlerModule.Spec {
|
23
|
-
static NAME = "RNGestureHandlerModule"
|
29
|
+
static readonly NAME = "RNGestureHandlerModule"
|
24
30
|
|
25
31
|
private gestureHandlerRegistry: GestureHandlerRegistry
|
26
32
|
private gestureHandlerFactory: GestureHandlerFactory | undefined = undefined
|
27
33
|
private viewRegistry: ViewRegistry | undefined = undefined
|
28
34
|
private logger: RNGHLogger
|
29
|
-
private
|
35
|
+
private cleanLogger: RNGHLogger
|
36
|
+
private rootViewControllerByRootTag = new Map<Tag, RNGHRootViewController>()
|
30
37
|
private interactionManager: InteractionManager
|
31
38
|
|
32
|
-
constructor(ctx: TurboModuleContext) {
|
39
|
+
constructor(ctx: TurboModuleContext, isDevModeEnabled: boolean = false) {
|
33
40
|
super(ctx)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
this.
|
38
|
-
|
41
|
+
this.cleanLogger =
|
42
|
+
isDevModeEnabled && ctx.isDebugModeEnabled ? new DevelopmentRNGHLogger(ctx.logger, "RNGH") :
|
43
|
+
new ProductionRNGHLogger(ctx.logger, "RNGH")
|
44
|
+
this.logger = this.cleanLogger.cloneAndJoinPrefix("RNGestureHandlerModule")
|
45
|
+
const logger = this.logger.cloneAndJoinPrefix("constructor")
|
46
|
+
const stopTracing = logger.startTracing()
|
47
|
+
this.interactionManager = new InteractionManager(this.cleanLogger)
|
48
|
+
this.gestureHandlerRegistry = new GestureHandlerRegistry(this.viewRegistry, this.cleanLogger)
|
39
49
|
if (this.ctx.rnInstance.getArchitecture() === "C_API") {
|
40
50
|
this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::TOUCH_EVENT", (e: any) => {
|
41
51
|
this.onTouch(e)
|
@@ -44,60 +54,67 @@ export class RNGestureHandlerModule extends TurboModule implements TM.RNGestureH
|
|
44
54
|
this.onGHRootCreated(rootTag)
|
45
55
|
})
|
46
56
|
this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::CANCEL_TOUCHES", (rootTag: any) => {
|
47
|
-
const touchHandler = this.
|
57
|
+
const touchHandler = this.rootViewControllerByRootTag.get(rootTag)
|
48
58
|
touchHandler?.cancelTouches()
|
49
59
|
})
|
50
60
|
}
|
61
|
+
stopTracing()
|
51
62
|
}
|
52
63
|
|
53
64
|
/**
|
54
|
-
* @architecture: C-API
|
55
65
|
* Called from C++.
|
56
66
|
*/
|
57
67
|
private onGHRootCreated(rootTag: Tag) {
|
58
|
-
|
68
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("onGHRootCreated").startTracing()
|
69
|
+
this.rootViewControllerByRootTag.set(rootTag, new RNGHRootViewController(this.logger, this.gestureHandlerRegistry));
|
70
|
+
stopTracing()
|
59
71
|
}
|
60
72
|
|
61
73
|
/**
|
62
|
-
* @architecture: C-API
|
63
74
|
* Called from C++.
|
64
75
|
*/
|
65
76
|
private onTouch(e: RawTouchEvent & { rootTag: Tag }) {
|
66
|
-
const logger = this.logger.
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
e.touchableViews.forEach(touchableView => {
|
78
|
-
const view = this.viewRegistry.getViewByTag(touchableView.tag)
|
79
|
-
if (view) {
|
80
|
-
if (!(view instanceof ViewCAPI)) {
|
81
|
-
logger.error(`Expected ViewCAPI`)
|
82
|
-
return
|
83
|
-
}
|
84
|
-
view.updateBoundingBox(touchableView)
|
85
|
-
view.setButtonRole(touchableView.buttonRole)
|
86
|
-
} else {
|
87
|
-
this.viewRegistry.save(new ViewCAPI(touchableView))
|
77
|
+
const logger = this.logger.cloneAndJoinPrefix("onTouch")
|
78
|
+
const stopTracing = logger.startTracing();
|
79
|
+
(() => {
|
80
|
+
if (!(this.viewRegistry instanceof RNGHViewRegistry)) {
|
81
|
+
logger.error("Expected ViewRegistryCAPI")
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
const rootViewController = this.rootViewControllerByRootTag.get(e.rootTag)
|
85
|
+
if (!rootViewController) {
|
86
|
+
logger.error(`Couldn't find a rootViewController for a gesture root tag: ${e.rootTag}`)
|
87
|
+
return;
|
88
88
|
}
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
// update view registry
|
90
|
+
e.touchableViews.forEach(touchableView => {
|
91
|
+
const view = this.viewRegistry.getViewByTag(touchableView.tag)
|
92
|
+
if (view) {
|
93
|
+
if (!(view instanceof RNGHView)) {
|
94
|
+
logger.error(`Expected ViewCAPI`)
|
95
|
+
return
|
96
|
+
}
|
97
|
+
view.updateBoundingBox(touchableView)
|
98
|
+
view.setButtonRole(touchableView.buttonRole)
|
99
|
+
} else {
|
100
|
+
this.viewRegistry.save(new RNGHView(touchableView))
|
101
|
+
}
|
102
|
+
})
|
103
|
+
rootViewController.handleTouch(e, e.touchableViews.map(({ tag }) => this.viewRegistry.getViewByTag(tag)));
|
104
|
+
})()
|
105
|
+
stopTracing()
|
92
106
|
}
|
93
107
|
|
94
108
|
// -------------------------------------------------------------------------------------------------------------------
|
95
109
|
|
96
110
|
public install() {
|
97
|
-
|
98
|
-
|
99
|
-
const
|
100
|
-
|
111
|
+
const stopTracing = this.ctx.logger.clone("install").startTracing()
|
112
|
+
this.viewRegistry = new RNGHViewRegistry()
|
113
|
+
const scrollLocker = new RNOHScrollLockerCAPI(this.ctx.rnInstance, this.cleanLogger);
|
114
|
+
const rnGestureResponder = new RNOHGestureResponder(this.ctx.rnInstance)
|
115
|
+
this.gestureHandlerFactory =
|
116
|
+
new GestureHandlerFactory(this.cleanLogger, scrollLocker, this.interactionManager, rnGestureResponder)
|
117
|
+
stopTracing()
|
101
118
|
return true
|
102
119
|
}
|
103
120
|
|
@@ -106,16 +123,20 @@ export class RNGestureHandlerModule extends TurboModule implements TM.RNGestureH
|
|
106
123
|
handlerTag: number,
|
107
124
|
config: Readonly<Record<string, unknown>>
|
108
125
|
) {
|
109
|
-
const logger = this.logger.
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
126
|
+
const logger = this.logger.cloneAndJoinPrefix("createGestureHandler")
|
127
|
+
const stopTracing = logger.startTracing();
|
128
|
+
(() => {
|
129
|
+
if (!this.gestureHandlerFactory) {
|
130
|
+
logger.error("Trying to create a gesture handler before creating gesture handler factory")
|
131
|
+
return
|
132
|
+
}
|
133
|
+
logger.debug({ handlerName, handlerTag, config })
|
134
|
+
const gestureHandler = this.gestureHandlerFactory.create(handlerName, handlerTag)
|
135
|
+
this.gestureHandlerRegistry.addGestureHandler(gestureHandler)
|
136
|
+
this.interactionManager.configureInteractions(gestureHandler, config);
|
137
|
+
gestureHandler.updateGestureConfig(config)
|
138
|
+
})()
|
139
|
+
stopTracing()
|
119
140
|
}
|
120
141
|
|
121
142
|
public attachGestureHandler(
|
@@ -123,43 +144,55 @@ export class RNGestureHandlerModule extends TurboModule implements TM.RNGestureH
|
|
123
144
|
viewTag: number,
|
124
145
|
actionType: ActionType
|
125
146
|
) {
|
126
|
-
const
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
147
|
+
const logger = this.logger.cloneAndJoinPrefix("attachGestureHandler")
|
148
|
+
const stopTracing = logger.startTracing();
|
149
|
+
(() => {
|
150
|
+
const eventDispatcher = this.createEventDispatcher(actionType, viewTag)
|
151
|
+
if (!eventDispatcher) {
|
152
|
+
logger.error("RNGH: Couldn't create EventDispatcher")
|
153
|
+
return
|
154
|
+
}
|
155
|
+
const viewRegistry = this.viewRegistry
|
156
|
+
let view = this.viewRegistry.getViewByTag(viewTag)
|
157
|
+
if (!view && viewRegistry instanceof RNGHViewRegistry) {
|
158
|
+
view = new RNGHView({
|
159
|
+
tag: viewTag,
|
160
|
+
x: 0,
|
161
|
+
y: 0,
|
162
|
+
width: 0,
|
163
|
+
height: 0,
|
164
|
+
buttonRole: false
|
165
|
+
})
|
166
|
+
viewRegistry.save(view)
|
167
|
+
}
|
168
|
+
if (!view) {
|
169
|
+
logger.error("Expected view")
|
170
|
+
return;
|
171
|
+
}
|
172
|
+
this.gestureHandlerRegistry.bindGestureHandlerWithView(handlerTag, view)
|
173
|
+
this.gestureHandlerRegistry.getGestureHandlersByViewTag(view.getTag()).forEach((handler) => {
|
174
|
+
if (handler.isGestureContinuous() && eventDispatcher instanceof JSEventDispatcher) {
|
175
|
+
logger.warn(`Using JSEventDispatcher for a continuous gesture (${handler.getName()}). Gesture-driven animations may not be smooth. Consider using Animated.event.`)
|
176
|
+
}
|
141
177
|
})
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
}
|
148
|
-
this.gestureHandlerRegistry.bindGestureHandlerWithView(handlerTag, view)
|
149
|
-
this.gestureHandlerRegistry
|
150
|
-
.getGestureHandlerByHandlerTag(handlerTag)
|
151
|
-
.setEventDispatcher(eventDispatcher)
|
178
|
+
this.gestureHandlerRegistry
|
179
|
+
.getGestureHandlerByHandlerTag(handlerTag)
|
180
|
+
.setEventDispatcher(eventDispatcher)
|
181
|
+
})()
|
182
|
+
stopTracing()
|
152
183
|
}
|
153
184
|
|
154
185
|
private createEventDispatcher(actionType: ActionType, viewTag: number): OutgoingEventDispatcher | null {
|
155
186
|
switch (actionType) {
|
156
187
|
case ActionType.REANIMATED_WORKLET:
|
157
|
-
return new ReanimatedEventDispatcher(this.ctx.rnInstance,
|
188
|
+
return new ReanimatedEventDispatcher(this.ctx.rnInstance,
|
189
|
+
this.cleanLogger, viewTag)
|
158
190
|
case ActionType.NATIVE_ANIMATED_EVENT:
|
159
|
-
return new AnimatedEventDispatcher(this.ctx.rnInstance,
|
191
|
+
return new AnimatedEventDispatcher(this.ctx.rnInstance,
|
192
|
+
this.cleanLogger, viewTag)
|
160
193
|
case ActionType.JS_FUNCTION_OLD_API:
|
161
194
|
case ActionType.JS_FUNCTION_NEW_API:
|
162
|
-
return new JSEventDispatcher(this.ctx.rnInstance, this.
|
195
|
+
return new JSEventDispatcher(this.ctx.rnInstance, this.cleanLogger);
|
163
196
|
}
|
164
197
|
}
|
165
198
|
|
@@ -167,22 +200,26 @@ export class RNGestureHandlerModule extends TurboModule implements TM.RNGestureH
|
|
167
200
|
handlerTag: number,
|
168
201
|
newConfig: Readonly<Record<string, unknown>>
|
169
202
|
) {
|
203
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("updateGestureHandler").startTracing()
|
170
204
|
const gestureHandler = this.gestureHandlerRegistry.getGestureHandlerByHandlerTag(handlerTag)
|
171
205
|
this.interactionManager.configureInteractions(gestureHandler, newConfig);
|
172
206
|
gestureHandler.updateGestureConfig(newConfig)
|
207
|
+
stopTracing()
|
173
208
|
}
|
174
209
|
|
175
210
|
public dropGestureHandler(handlerTag: number) {
|
211
|
+
const stopTracing = this.logger.cloneAndJoinPrefix("dropGestureHandler").startTracing()
|
176
212
|
this.interactionManager.dropRelationsForHandlerWithTag(handlerTag)
|
177
213
|
this.gestureHandlerRegistry.removeGestureHandlerByHandlerTag(handlerTag)
|
214
|
+
stopTracing()
|
178
215
|
}
|
179
216
|
|
180
217
|
public handleSetJSResponder(tag: number, blockNativeResponder: boolean) {
|
181
|
-
this.warn("
|
218
|
+
this.logger.cloneAndJoinPrefix("handleSetJSResponder").warn("not implemented")
|
182
219
|
}
|
183
220
|
|
184
221
|
public handleClearJSResponder() {
|
185
|
-
this.warn("
|
222
|
+
this.logger.cloneAndJoinPrefix("handleClearJSResponder").warn("not implemented")
|
186
223
|
}
|
187
224
|
|
188
225
|
public flushOperations() {
|
@@ -190,9 +227,6 @@ export class RNGestureHandlerModule extends TurboModule implements TM.RNGestureH
|
|
190
227
|
}
|
191
228
|
|
192
229
|
// -------------------------------------------------------------------------------------------------------------------
|
193
|
-
protected warn(message: string) {
|
194
|
-
this.ctx.logger.warn("RNGH: " + message)
|
195
|
-
}
|
196
230
|
|
197
231
|
public getGestureHandlerRegistry() {
|
198
232
|
return this.gestureHandlerRegistry
|
@@ -204,7 +238,7 @@ export class RNGestureHandlerModule extends TurboModule implements TM.RNGestureH
|
|
204
238
|
|
205
239
|
public getViewRegistry() {
|
206
240
|
if (!this.viewRegistry) {
|
207
|
-
this.logger.
|
241
|
+
this.logger.error("Tried to get viewRegistry before it was initialized")
|
208
242
|
throw new Error("Tried to get viewRegistry before it was initialized")
|
209
243
|
}
|
210
244
|
return this.viewRegistry
|
@@ -1,16 +1,7 @@
|
|
1
1
|
import { RNInstance } from "@rnoh/react-native-openharmony/ts"
|
2
2
|
import { RNGestureResponder } from "../core"
|
3
3
|
|
4
|
-
export class FakeRNGestureResponder {
|
5
|
-
lock() {
|
6
|
-
// Cancelling RN events isn't supported in ArkTS architecture.
|
7
|
-
return () => {}
|
8
|
-
}
|
9
|
-
}
|
10
4
|
|
11
|
-
/**
|
12
|
-
* Used in C-API architecture.
|
13
|
-
*/
|
14
5
|
export class RNOHGestureResponder implements RNGestureResponder {
|
15
6
|
constructor(private rnInstance: RNInstance) {
|
16
7
|
}
|
@@ -1,20 +1,13 @@
|
|
1
1
|
import { RNInstance } from '@rnoh/react-native-openharmony/ts';
|
2
2
|
import { ScrollLocker, RNGHLogger } from '../core';
|
3
3
|
|
4
|
-
export class RNOHScrollLockerArkTS implements ScrollLocker {
|
5
|
-
constructor(private rnInstance: RNInstance) {
|
6
|
-
}
|
7
4
|
|
8
|
-
lockScrollContainingViewTag(viewTag: number) {
|
9
|
-
return this.rnInstance.blockComponentsGestures(viewTag);
|
10
|
-
}
|
11
|
-
}
|
12
5
|
|
13
6
|
export class RNOHScrollLockerCAPI implements ScrollLocker {
|
14
7
|
private logger: RNGHLogger
|
15
8
|
|
16
9
|
constructor(private rnInstance: RNInstance, logger: RNGHLogger) {
|
17
|
-
this.logger = logger.
|
10
|
+
this.logger = logger.cloneAndJoinPrefix("RNOHScrollLockerCAPI")
|
18
11
|
}
|
19
12
|
|
20
13
|
lockScrollContainingViewTag(viewTag: number) {
|
Binary file
|
package/package.json
CHANGED
@@ -2,13 +2,17 @@
|
|
2
2
|
"name": "@react-native-oh-tpl/react-native-gesture-handler",
|
3
3
|
"harmony": {
|
4
4
|
"alias": "react-native-gesture-handler",
|
5
|
-
"redirectInternalImports": true
|
5
|
+
"redirectInternalImports": true,
|
6
|
+
"autolinking": {
|
7
|
+
"cmakeLibraryTargetName": "rnoh_gesture_handler",
|
8
|
+
"ohPackageName": "@react-native-oh-tpl/react-native-gesture-handler"
|
9
|
+
}
|
6
10
|
},
|
7
11
|
"repository": {
|
8
12
|
"type": "git",
|
9
13
|
"url": "https://github.com/react-native-oh-library/react-native-harmony-gesture-handler.git"
|
10
14
|
},
|
11
|
-
"version": "2.14.1-2.14.
|
15
|
+
"version": "2.14.1-2.14.14",
|
12
16
|
"description": "",
|
13
17
|
"react-native": "src/index.ts",
|
14
18
|
"main": "lib/commonjs/index.js",
|
@@ -66,4 +70,4 @@
|
|
66
70
|
]
|
67
71
|
]
|
68
72
|
}
|
69
|
-
}
|
73
|
+
}
|
@@ -1,149 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
#include "GestureHandlerPackage.h"
|
3
|
-
#include "RNOH/RNInstanceCAPI.h"
|
4
|
-
#include "componentInstances/RNGestureHandlerButtonComponentInstance.h"
|
5
|
-
#include "componentInstances/RNGestureHandlerRootViewComponentInstance.h"
|
6
|
-
#include "RNOH/ArkTSTurboModule.h"
|
7
|
-
#include "RNGestureHandlerModule.h"
|
8
|
-
#include "RNGestureHandlerButtonComponentDescriptor.h"
|
9
|
-
#include "RNGestureHandlerRootViewComponentDescriptor.h"
|
10
|
-
#include "RNGestureHandlerButtonJSIBinder.h"
|
11
|
-
#include "RNGestureHandlerRootViewJSIBinder.h"
|
12
|
-
#include <glog/logging.h>
|
13
|
-
|
14
|
-
using namespace rnoh;
|
15
|
-
using namespace facebook;
|
16
|
-
|
17
|
-
class GestureHandlerTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
18
|
-
public:
|
19
|
-
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
20
|
-
if (name == "RNGestureHandlerModule") {
|
21
|
-
return std::make_shared<RNGestureHandlerModule>(ctx, name);
|
22
|
-
}
|
23
|
-
return nullptr;
|
24
|
-
};
|
25
|
-
};
|
26
|
-
|
27
|
-
|
28
|
-
class RNGHEventEmitRequestHandler : public EventEmitRequestHandler {
|
29
|
-
void handleEvent(EventEmitRequestHandler::Context const &ctx) override {
|
30
|
-
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::ViewEventEmitter>(ctx.tag);
|
31
|
-
if (eventEmitter == nullptr) {
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
if (ctx.eventName == "onGestureHandlerEvent") {
|
35
|
-
eventEmitter->dispatchUniqueEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
36
|
-
} else if (ctx.eventName == "onGestureHandlerStateChange") {
|
37
|
-
eventEmitter->dispatchEvent("onGestureHandlerStateChange", ArkJS(ctx.env).getDynamic(ctx.payload));
|
38
|
-
}
|
39
|
-
}
|
40
|
-
};
|
41
|
-
|
42
|
-
class RNOHCorePackageComponentInstanceFactoryDelegate : public ComponentInstanceFactoryDelegate {
|
43
|
-
public:
|
44
|
-
using ComponentInstanceFactoryDelegate::ComponentInstanceFactoryDelegate;
|
45
|
-
|
46
|
-
ComponentInstance::Shared create(ComponentInstance::Context ctx) override {
|
47
|
-
if (ctx.componentName == "RNGestureHandlerButton") {
|
48
|
-
return std::make_shared<RNGestureHandlerButtonComponentInstance>(ctx);
|
49
|
-
} else if (ctx.componentName == "RNGestureHandlerRootView") {
|
50
|
-
return std::make_shared<RNGestureHandlerRootViewComponentInstance>(ctx);
|
51
|
-
}
|
52
|
-
return nullptr;
|
53
|
-
}
|
54
|
-
};
|
55
|
-
|
56
|
-
std::unique_ptr<TurboModuleFactoryDelegate> GestureHandlerPackage::createTurboModuleFactoryDelegate() {
|
57
|
-
return std::make_unique<GestureHandlerTurboModuleFactoryDelegate>();
|
58
|
-
}
|
59
|
-
|
60
|
-
std::vector<react::ComponentDescriptorProvider> GestureHandlerPackage::createComponentDescriptorProviders() {
|
61
|
-
return {
|
62
|
-
react::concreteComponentDescriptorProvider<react::RNGestureHandlerRootViewComponentDescriptor>(),
|
63
|
-
react::concreteComponentDescriptorProvider<react::RNGestureHandlerButtonComponentDescriptor>(),
|
64
|
-
};
|
65
|
-
}
|
66
|
-
|
67
|
-
ComponentJSIBinderByString GestureHandlerPackage::createComponentJSIBinderByName() {
|
68
|
-
return {
|
69
|
-
{"RNGestureHandlerButton", std::make_shared<RNGestureHandlerButtonJSIBinder>()},
|
70
|
-
{"RNGestureHandlerRootView", std::make_shared<RNGestureHandlerRootViewJSIBinder>()},
|
71
|
-
};
|
72
|
-
};
|
73
|
-
|
74
|
-
EventEmitRequestHandlers GestureHandlerPackage::createEventEmitRequestHandlers() {
|
75
|
-
return {
|
76
|
-
std::make_shared<RNGHEventEmitRequestHandler>(),
|
77
|
-
};
|
78
|
-
}
|
79
|
-
|
80
|
-
ComponentInstanceFactoryDelegate::Shared GestureHandlerPackage::createComponentInstanceFactoryDelegate() {
|
81
|
-
return std::make_shared<RNOHCorePackageComponentInstanceFactoryDelegate>();
|
82
|
-
}
|
83
|
-
|
84
|
-
class ScrollLockerArkTSMessageHandler : public ArkTSMessageHandler {
|
85
|
-
public:
|
86
|
-
void handleArkTSMessage(const Context &ctx) override {
|
87
|
-
if (ctx.messageName == "RNGH::SET_NATIVE_RESPONDERS_BLOCK") {
|
88
|
-
auto targetComponentInstanceTag = ctx.messagePayload["targetTag"].asDouble();
|
89
|
-
auto shouldBlock = ctx.messagePayload["shouldBlock"].asBool();
|
90
|
-
auto rnInstance = ctx.rnInstance.lock();
|
91
|
-
if (rnInstance != nullptr) {
|
92
|
-
auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
|
93
|
-
if (rnInstanceCAPI != nullptr) {
|
94
|
-
|
95
|
-
std::vector<ComponentInstance::Shared> ancestors;
|
96
|
-
auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag(targetComponentInstanceTag);
|
97
|
-
while (tmpComponentInstance != nullptr) {
|
98
|
-
ancestors.push_back(tmpComponentInstance);
|
99
|
-
tmpComponentInstance = tmpComponentInstance->getParent().lock();
|
100
|
-
}
|
101
|
-
if (ancestors.size() == 0) {
|
102
|
-
return;
|
103
|
-
}
|
104
|
-
/**
|
105
|
-
* Ensure consistent behavior with Android by not blocking scrolls above the GestureHandlerRootView handling
|
106
|
-
* the touch. If there are multiple nested GestureHandlerRootViews, the one nearest to the actual root will
|
107
|
-
* handle the touch.
|
108
|
-
*/
|
109
|
-
auto isChangingResponderStatusAllowed = false;
|
110
|
-
for (size_t i = ancestors.size() - 1; i > 0; i--) {
|
111
|
-
auto ancestor = ancestors[i];
|
112
|
-
if (!isChangingResponderStatusAllowed) {
|
113
|
-
auto rootView = std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(ancestor);
|
114
|
-
if (rootView != nullptr) {
|
115
|
-
isChangingResponderStatusAllowed = true;
|
116
|
-
}
|
117
|
-
} else {
|
118
|
-
ancestor->setNativeResponderBlocked(shouldBlock, "RNGH");
|
119
|
-
}
|
120
|
-
}
|
121
|
-
}
|
122
|
-
}
|
123
|
-
} else if (ctx.messageName == "RNGH::ROOT_VIEW_IS_HANDLING_TOUCHES") {
|
124
|
-
auto descendantViewTag = ctx.messagePayload["descendantViewTag"].asDouble();
|
125
|
-
auto isHandlingTouches = ctx.messagePayload["isHandlingTouches"].asBool();
|
126
|
-
auto rnInstance = ctx.rnInstance.lock();
|
127
|
-
if (rnInstance != nullptr) {
|
128
|
-
auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
|
129
|
-
if (rnInstanceCAPI != nullptr) {
|
130
|
-
auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag(descendantViewTag);
|
131
|
-
while (tmpComponentInstance != nullptr) {
|
132
|
-
tmpComponentInstance = tmpComponentInstance->getParent().lock();
|
133
|
-
if (tmpComponentInstance) {
|
134
|
-
auto rnghRootViewComponentInstance =
|
135
|
-
std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(tmpComponentInstance);
|
136
|
-
if (rnghRootViewComponentInstance) {
|
137
|
-
rnghRootViewComponentInstance->setIsHandlingTouches(isHandlingTouches);
|
138
|
-
}
|
139
|
-
}
|
140
|
-
}
|
141
|
-
}
|
142
|
-
}
|
143
|
-
}
|
144
|
-
};
|
145
|
-
};
|
146
|
-
|
147
|
-
std::vector<ArkTSMessageHandler::Shared> GestureHandlerPackage::createArkTSMessageHandlers() {
|
148
|
-
return {std::make_shared<ScrollLockerArkTSMessageHandler>()};
|
149
|
-
}
|
@@ -1,98 +0,0 @@
|
|
1
|
-
import { Tag } from '@rnoh/react-native-openharmony/ts';
|
2
|
-
import { GestureHandlerArkUIAdapter } from './GestureHandlerArkUIAdapter';
|
3
|
-
import { RNGHLogger, GestureHandlerRegistry, View, ViewFinder } from '../core';
|
4
|
-
import { TouchEvent, TouchType } from './types';
|
5
|
-
|
6
|
-
export class RNGHRootTouchHandlerArkTS {
|
7
|
-
private adapterByViewTag: Map<number, GestureHandlerArkUIAdapter> = new Map(); // TODO: remove adapter when view is removed
|
8
|
-
/**
|
9
|
-
* A view is ACTIVE, if it recently received POINTER_DOWN event
|
10
|
-
*/
|
11
|
-
private activeViewTags = new Set<number>();
|
12
|
-
private viewFinder: ViewFinder;
|
13
|
-
private gestureHandlerRegistry: GestureHandlerRegistry;
|
14
|
-
private logger: RNGHLogger;
|
15
|
-
private rootTag: Tag;
|
16
|
-
|
17
|
-
constructor(
|
18
|
-
rootTag: Tag,
|
19
|
-
viewFinder: ViewFinder,
|
20
|
-
gestureHandlerRegistry: GestureHandlerRegistry,
|
21
|
-
logger: RNGHLogger,
|
22
|
-
) {
|
23
|
-
this.rootTag = rootTag;
|
24
|
-
this.viewFinder = viewFinder;
|
25
|
-
this.gestureHandlerRegistry = gestureHandlerRegistry;
|
26
|
-
this.logger = logger;
|
27
|
-
}
|
28
|
-
|
29
|
-
/**
|
30
|
-
*
|
31
|
-
* @param touchEvent - TouchEvent. The type is any to allow providing the type in ets file (any and unknowns aren't allowed in ets files).
|
32
|
-
* @param touchableViews - Optional. List of views that can have gesture handler attached for given touch. If not provided, viewFinder will be used.
|
33
|
-
*/
|
34
|
-
public handleTouch(touchEvent: any, touchableViews: View[] | null = null) {
|
35
|
-
const e = touchEvent as TouchEvent;
|
36
|
-
if (e.type === TouchType.Down) {
|
37
|
-
this.activeViewTags.clear();
|
38
|
-
}
|
39
|
-
for (const changedTouch of e.changedTouches) {
|
40
|
-
const views = touchableViews ?? this.viewFinder.getTouchableViewsAt(
|
41
|
-
{
|
42
|
-
x: changedTouch.windowX,
|
43
|
-
y: changedTouch.windowY,
|
44
|
-
},
|
45
|
-
this.rootTag,
|
46
|
-
);
|
47
|
-
for (const view of views) {
|
48
|
-
for (const handler of this.gestureHandlerRegistry.getGestureHandlersByViewTag(
|
49
|
-
view.getTag(),
|
50
|
-
)) {
|
51
|
-
this.logger.info(
|
52
|
-
`Found GestureHandler ${handler.getTag()} for view ${view.getTag()}`,
|
53
|
-
);
|
54
|
-
|
55
|
-
// create adapter if necessary
|
56
|
-
if (!this.adapterByViewTag.has(view.getTag())) {
|
57
|
-
this.adapterByViewTag.set(
|
58
|
-
view.getTag(),
|
59
|
-
new GestureHandlerArkUIAdapter(
|
60
|
-
view,
|
61
|
-
this.logger,
|
62
|
-
),
|
63
|
-
);
|
64
|
-
}
|
65
|
-
|
66
|
-
// attach handler (there might be multiple handlers per view)
|
67
|
-
this.adapterByViewTag.get(view.getTag())!.attachGestureHandler(handler) // TODO: detachGestureHandler
|
68
|
-
|
69
|
-
// register active view tag
|
70
|
-
if (e.type === TouchType.Down) {
|
71
|
-
this.activeViewTags.add(view.getTag());
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
// send touch to gesture handlers, prioritize handling touch events for child components
|
77
|
-
if (this.activeViewTags.size > 0) {
|
78
|
-
const tags = Array.from(this.activeViewTags);
|
79
|
-
for (let i = tags.length - 1; i >= 0; i--) {
|
80
|
-
const tag = tags[i];
|
81
|
-
const adapter = this.adapterByViewTag.get(tag);
|
82
|
-
if (adapter) {
|
83
|
-
adapter.handleTouch(e);
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
public cancelTouches() {
|
91
|
-
for (const activeViewTag of this.activeViewTags) {
|
92
|
-
this.gestureHandlerRegistry.getGestureHandlersByViewTag(activeViewTag).forEach(gh => {
|
93
|
-
gh.cancel()
|
94
|
-
gh.reset()
|
95
|
-
})
|
96
|
-
}
|
97
|
-
}
|
98
|
-
}
|