@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.
Files changed (48) hide show
  1. package/harmony/gesture_handler/BuildProfile.ets +1 -1
  2. package/harmony/gesture_handler/index.ets +1 -2
  3. package/harmony/gesture_handler/oh-package-lock.json5 +1 -1
  4. package/harmony/gesture_handler/oh-package.json5 +1 -1
  5. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +1 -1
  6. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +9 -18
  7. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp +157 -0
  8. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +21 -0
  9. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +16 -16
  10. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +202 -199
  11. package/harmony/gesture_handler/src/main/ets/RNOHPackage.ets +17 -0
  12. package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +84 -35
  13. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +20 -11
  14. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +2 -2
  15. package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +4 -4
  16. package/harmony/gesture_handler/src/main/ets/core/Multiset.ts +26 -0
  17. package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +7 -3
  18. package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +1 -2
  19. package/harmony/gesture_handler/src/main/ets/core/index.ts +2 -2
  20. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +12 -4
  21. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +8 -5
  22. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +14 -2
  23. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +9 -1
  24. package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +13 -4
  25. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +31 -12
  26. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +145 -130
  27. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +9 -1
  28. package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +15 -5
  29. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +7 -4
  30. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +74 -16
  31. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +35 -12
  32. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootViewController.ts +182 -0
  33. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHView.ts +62 -0
  34. package/harmony/gesture_handler/src/main/ets/rnoh/{GestureHandlerArkUIAdapter.ts → RNGHViewController.ts} +44 -22
  35. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewRegistry.ts +19 -0
  36. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +127 -93
  37. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +0 -9
  38. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +1 -8
  39. package/harmony/gesture_handler.har +0 -0
  40. package/package.json +7 -3
  41. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +0 -149
  42. package/harmony/gesture_handler/src/main/ets/core/ViewFinder.ts +0 -11
  43. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +0 -98
  44. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +0 -110
  45. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerButton.ets +0 -38
  46. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerRootView.ets +0 -53
  47. package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +0 -134
  48. package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +0 -97
@@ -1,110 +0,0 @@
1
- import { RNGHRootTouchHandlerArkTS } from './RNGHRootTouchHandlerArkTS';
2
- import { TouchEvent as TouchEventArkTS, TouchType, TouchObject } from './types';
3
- import { RNGHLogger, View } from '../core';
4
- import { RawTouchableView } from "./View"
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 root to leaf which contain the touch point specified by `actionTouch` in their boundary boxes. */
19
- touchableViews: RawTouchableView[]
20
- };
21
-
22
- const CACHED_TOUCHES_MAP = new Map<number, RawTouchPoint>();
23
- let lastChangedPointerId: number | null = null;
24
- const MAX_SIZE = 10;
25
- const areRawTouchPointsEqual = (a: RawTouchPoint, b: RawTouchPoint) =>
26
- a.pointerId === b.pointerId &&
27
- a.windowX === b.windowX &&
28
- a.windowY === b.windowY;
29
-
30
-
31
- export class RNGHRootTouchHandlerCAPI {
32
- private logger: RNGHLogger;
33
-
34
- constructor(
35
- logger: RNGHLogger,
36
- private touchHandlerArkTS: RNGHRootTouchHandlerArkTS,
37
- ) {
38
- this.logger = logger.cloneWithPrefix('RNGHRootTouchHandlerCAPI');
39
- }
40
-
41
- handleTouch(rawTouchEvent: RawTouchEvent, touchableViews: View[]) {
42
- this.touchHandlerArkTS.handleTouch(
43
- touchEventArkTSFromRawTouchEvent(rawTouchEvent), touchableViews
44
- );
45
- }
46
-
47
- cancelTouches() {
48
- this.touchHandlerArkTS.cancelTouches()
49
- }
50
- }
51
-
52
- function touchEventArkTSFromRawTouchEvent(raw: RawTouchEvent): TouchEventArkTS {
53
- const touchType = touchTypeFromAction(raw.action);
54
- const actionTouch = raw.actionTouch;
55
- let hasTouchChanged = true;
56
- let lastChangedTouch: RawTouchPoint = actionTouch;
57
- if (CACHED_TOUCHES_MAP.has(actionTouch.pointerId)) {
58
- if (areRawTouchPointsEqual(actionTouch, CACHED_TOUCHES_MAP.get(actionTouch.pointerId) as RawTouchPoint)) {
59
- hasTouchChanged = false;
60
- } else {
61
- lastChangedPointerId = actionTouch.pointerId;
62
- CACHED_TOUCHES_MAP.set(actionTouch.pointerId, actionTouch);
63
- }
64
- } else {
65
- // remove first element if the cache is full
66
- if (CACHED_TOUCHES_MAP.size >= MAX_SIZE) {
67
- CACHED_TOUCHES_MAP.delete(CACHED_TOUCHES_MAP.keys().next().value);
68
- }
69
- lastChangedPointerId = actionTouch.pointerId;
70
- CACHED_TOUCHES_MAP.set(actionTouch.pointerId, actionTouch);
71
- }
72
- lastChangedTouch = CACHED_TOUCHES_MAP.get(lastChangedPointerId as number) as RawTouchPoint
73
- return {
74
- type: touchTypeFromAction(raw.action),
75
- touches: raw.touchPoints.map(tp =>
76
- touchObjectFromTouchPoint(tp, touchType),
77
- ),
78
- changedTouches: [
79
- touchObjectFromTouchPoint(lastChangedTouch, touchType),
80
- ],
81
- timestamp: raw.timestamp / Math.pow(10, 6),
82
- };
83
- }
84
-
85
- function touchTypeFromAction(action: number): TouchType {
86
- switch (action) {
87
- case 1:
88
- return TouchType.Down;
89
- case 2:
90
- return TouchType.Move;
91
- case 3:
92
- return TouchType.Up;
93
- default:
94
- return TouchType.Cancel;
95
- }
96
- }
97
-
98
- function touchObjectFromTouchPoint(
99
- touchPoint: RawTouchPoint,
100
- touchType: TouchType,
101
- ): TouchObject {
102
- return {
103
- id: touchPoint.pointerId,
104
- windowX: touchPoint.windowX,
105
- windowY: touchPoint.windowY,
106
- x: touchPoint.windowX,
107
- y: touchPoint.windowY,
108
- type: touchType,
109
- };
110
- }
@@ -1,38 +0,0 @@
1
- import { RNOHContext, RNViewBase, ComponentBuilderContext, RNComponentFactory, Tag } from "@rnoh/react-native-openharmony"
2
- import { RNC } from "../namespace/ts"
3
-
4
- export type RNGestureHandlerButtonDescriptor = RNC.RNGestureHandlerButton.Descriptor
5
-
6
- @Component
7
- export struct RNGestureHandlerButton {
8
- static readonly NAME = RNC.RNGestureHandlerButton.NAME
9
- public ctx!: RNOHContext
10
- public tag: number = -1
11
- @BuilderParam public buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
12
-
13
- @State private descriptor: RNGestureHandlerButtonDescriptor = {} as RNGestureHandlerButtonDescriptor
14
- private unsubscribes: (() => void)[] = []
15
-
16
- aboutToAppear() {
17
- this.handleDescriptorChange(this.ctx.descriptorRegistry.getDescriptor<RNGestureHandlerButtonDescriptor>(this.tag))
18
- this.unsubscribes.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag, (d) => {
19
- this.handleDescriptorChange(d as RNGestureHandlerButtonDescriptor)
20
- }))
21
- }
22
-
23
- aboutToDisappear() {
24
- this.unsubscribes.forEach(unsubscribe => unsubscribe())
25
- }
26
-
27
- handleDescriptorChange(newDescriptor: RNGestureHandlerButtonDescriptor) {
28
- this.descriptor = newDescriptor
29
- }
30
-
31
- build() {
32
- RNViewBase({ ctx: this.ctx, tag: this.tag }) {
33
- ForEach(this.descriptor.childrenTags, (childrenTag: Tag) => {
34
- RNComponentFactory({ ctx: this.ctx, tag: childrenTag, buildCustomComponent: this.buildCustomComponent })
35
- })
36
- }
37
- }
38
- }
@@ -1,53 +0,0 @@
1
- import { RNOHContext, RNViewBase, ComponentBuilderContext, RNComponentFactory, Tag } from "@rnoh/react-native-openharmony"
2
- import { RNC } from "../namespace/ts"
3
- import { RNGHRootTouchHandlerArkTS as RNGHRootTouchHandler } from "./RNGHRootTouchHandlerArkTS"
4
- import { RNGestureHandlerModule } from "./RNGestureHandlerModule"
5
-
6
-
7
- export type RNGestureHandlerRootViewDescriptor = RNC.RNGestureHandlerRootView.Descriptor
8
-
9
- @Component
10
- export struct RNGestureHandlerRootView {
11
- static readonly NAME = RNC.RNGestureHandlerRootView.NAME
12
- ctx!: RNOHContext
13
- tag: number = -1
14
- @BuilderParam buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
15
- @State descriptor: RNGestureHandlerRootViewDescriptor = {} as RNGestureHandlerRootViewDescriptor
16
- private unsubscribes: (() => void)[] = []
17
- private touchHandler: RNGHRootTouchHandler | undefined = undefined
18
-
19
- aboutToAppear() {
20
- const rnGestureHandlerModule = this.ctx.rnInstance.getTurboModule<RNGestureHandlerModule>(RNGestureHandlerModule.NAME)
21
- const rootTag = this.ctx.descriptorRegistry.getDescriptorLineage(this.tag)[0].tag
22
- this.touchHandler = new RNGHRootTouchHandler(rootTag, rnGestureHandlerModule.getViewRegistry(), rnGestureHandlerModule.getGestureHandlerRegistry(), rnGestureHandlerModule.getLogger())
23
- this.handleDescriptorChange(this.ctx.descriptorRegistry.getDescriptor<RNGestureHandlerRootViewDescriptor>(this.tag))
24
- this.unsubscribes.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag, (d) => {
25
- this.handleDescriptorChange(d as RNGestureHandlerRootViewDescriptor)
26
- }))
27
- }
28
-
29
- aboutToDisappear() {
30
- this.unsubscribes.forEach(unsubscribe => unsubscribe())
31
- }
32
-
33
- handleDescriptorChange(newDescriptor: RNGestureHandlerRootViewDescriptor) {
34
- this.descriptor = newDescriptor
35
- }
36
-
37
- build() {
38
- RNViewBase({ ctx: this.ctx, tag: this.tag }) {
39
- ForEach(this.descriptor.childrenTags, (childrenTag: Tag) => {
40
- RNComponentFactory({ ctx: this.ctx, tag: childrenTag, buildCustomComponent: this.buildCustomComponent })
41
- })
42
- Stack() {
43
- }
44
- .width("100%")
45
- .height("100%")
46
- .onTouch((e) => {
47
- this.touchHandler?.handleTouch(e)
48
- })
49
- .hitTestBehavior(HitTestMode.Transparent)
50
-
51
- }
52
- }
53
- }
@@ -1,134 +0,0 @@
1
- import { DescriptorRegistry, Descriptor, Tag } from '@rnoh/react-native-openharmony/ts';
2
- import { View, Vector2D, BoundingBox } from "../core"
3
-
4
-
5
- export type RawTouchableView = {
6
- tag: number,
7
- /**
8
- * Relative to application window.
9
- */
10
- x: number,
11
- /**
12
- * Relative to application window.
13
- */
14
- y: number,
15
- width: number,
16
- height: number,
17
- buttonRole: boolean,
18
- }
19
-
20
- export class ViewCAPI implements View {
21
- private tag: number
22
- private buttonRole: boolean
23
- private boundingBox: BoundingBox
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
- isPositionInBounds({x, y}: {
40
- x: number;
41
- y: number
42
- }): boolean {
43
- const rect = this.getBoundingRect();
44
- return (
45
- x >= rect.x &&
46
- x <= rect.x + rect.width &&
47
- y >= rect.y &&
48
- y <= rect.y + rect.height
49
- );
50
- }
51
-
52
- updateBoundingBox(boundingBox: BoundingBox) {
53
- this.boundingBox = boundingBox
54
- }
55
-
56
- setButtonRole(buttonRole: boolean) {
57
- this.buttonRole = buttonRole
58
- }
59
-
60
- hasButtonRole(): boolean {
61
- return this.buttonRole
62
- }
63
- }
64
-
65
- export class ViewArkTS implements View {
66
- constructor(
67
- private descriptorRegistry: DescriptorRegistry,
68
- private viewTag: number,
69
- ) {
70
- }
71
-
72
-
73
- public getTag(): Tag {
74
- return this.viewTag;
75
- }
76
-
77
- public isPositionInBounds({x, y}: {
78
- x: number;
79
- y: number
80
- }): boolean {
81
- const rect = this.getBoundingRect();
82
- return (
83
- x >= rect.x &&
84
- x <= rect.x + rect.width &&
85
- y >= rect.y &&
86
- y <= rect.y + rect.height
87
- );
88
- }
89
-
90
- public getBoundingRect(): BoundingBox {
91
- const d = this.getDescriptor();
92
- if (!d) {
93
- return { x: 0, y: 0, width: 0, height: 0 };
94
- }
95
- const offsetToAbsolutePosition = this.getOffsetToAbsolutePosition();
96
- return {
97
- x: d.layoutMetrics.frame.origin.x - offsetToAbsolutePosition.x,
98
- y: d.layoutMetrics.frame.origin.y - offsetToAbsolutePosition.y,
99
- width: d.layoutMetrics.frame.size.width,
100
- height: d.layoutMetrics.frame.size.height,
101
- };
102
- }
103
-
104
- private getDescriptor() {
105
- return this.descriptorRegistry.getDescriptor(this.viewTag);
106
- }
107
-
108
- private getOffsetToAbsolutePosition(): Vector2D {
109
- const currentOffset = new Vector2D();
110
- let parentTag = this.getDescriptor()?.parentTag;
111
- while (parentTag !== undefined) {
112
- const d = this.descriptorRegistry.getDescriptor(parentTag);
113
- currentOffset.add(this.extractScrollOffsetFromDescriptor(d));
114
- currentOffset.subtract(new Vector2D(d.layoutMetrics.frame.origin));
115
- parentTag = d.parentTag;
116
- }
117
- return currentOffset;
118
- }
119
-
120
- private extractScrollOffsetFromDescriptor(descriptor: Descriptor<any>) {
121
- if (descriptor.type !== 'ScrollView') {
122
- return new Vector2D();
123
- }
124
- const scrollViewState: any = descriptor.state;
125
- return new Vector2D({
126
- x: scrollViewState.contentOffsetX,
127
- y: scrollViewState.contentOffsetY,
128
- });
129
- }
130
-
131
- public hasButtonRole(): boolean {
132
- return false;
133
- }
134
- }
@@ -1,97 +0,0 @@
1
- import { DescriptorRegistry, Tag, } from '@rnoh/react-native-openharmony/ts';
2
- import { ViewArkTS } from './View';
3
- import { View, ViewRegistry } from '../core';
4
-
5
- export class ViewRegistryArkTS implements ViewRegistry {
6
- constructor(
7
- private descriptorRegistry: DescriptorRegistry,
8
- ) {
9
- }
10
-
11
- getViewByTag(viewTag: Tag) {
12
- return this.createView(viewTag);
13
- }
14
-
15
- save(view: View) {
16
- /**
17
- * Currently, a new View object is created when getViewByTag is called. That was the approach in initial "quick"
18
- * implementation of this library. The save was introduced later, for the needs of implementation using C-API architecture.
19
- * C-API architecture is going to replace ArkTS anyway, so there's no point of doing this properly since this class
20
- * will be removed in the future.
21
- */
22
- }
23
-
24
- deleteByTag(viewTag: Tag) {
25
- // No-op, ArkTS is going to be deprecated at some point in the future.
26
- }
27
-
28
- private createView(tag: Tag): ViewArkTS {
29
- return new ViewArkTS(this.descriptorRegistry, tag);
30
- }
31
-
32
- getTouchableViewsAt(
33
- pos: {
34
- x: number;
35
- y: number;
36
- },
37
- rootTag: Tag,
38
- ): ViewArkTS[] {
39
- const rootView = this.createView(rootTag);
40
- const results: ViewArkTS[] = [];
41
- for (const view of this.getTouchableViewsAtPosInView(pos, rootView)) {
42
- results.push(view);
43
- }
44
- return results;
45
- }
46
-
47
- private getTouchableViewsAtPosInView(
48
- pos: {
49
- x: number;
50
- y: number;
51
- },
52
- view: ViewArkTS,
53
- ) {
54
- if (!view.isPositionInBounds(pos)) return [];
55
- const results: ViewArkTS[] = [];
56
- results.push(view);
57
- for (const child of this.getChildrenOf(view.getTag())) {
58
- for (const result of this.getTouchableViewsAtPosInView(pos, child)) {
59
- results.push(result);
60
- }
61
- }
62
- return results;
63
- }
64
-
65
- private getChildrenOf(viewTag: Tag): ViewArkTS[] {
66
- return this.descriptorRegistry.findDescriptorWrapperByTag(viewTag).childrenTags.map((tag) => new ViewArkTS(this.descriptorRegistry, tag))
67
- }
68
- }
69
-
70
-
71
- export class ViewRegistryCAPI implements ViewRegistry {
72
- private viewByTag = new Map<Tag, View>()
73
-
74
- save(view: View) {
75
- this.viewByTag.set(view.getTag(), view)
76
- }
77
-
78
- deleteByTag(viewTag: Tag) {
79
- this.viewByTag.delete(viewTag)
80
- }
81
-
82
- getViewByTag(viewTag: Tag) {
83
- return this.viewByTag.get(viewTag);
84
- }
85
-
86
- getTouchableViewsAt(
87
- pos: {
88
- x: number;
89
- y: number;
90
- },
91
- rootTag: Tag,
92
- ): ViewArkTS[] {
93
- // Finding views is handled on CPP side and provided with the touch event.
94
- // This method can be removed from ViewRegistry interface once support for ArkTS architecture is removed.
95
- return []
96
- }
97
- }