@react-native-oh-tpl/react-native-gesture-handler 2.14.13 → 2.14.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) 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 +123 -0
  8. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +15 -0
  9. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +17 -17
  10. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +203 -200
  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 +130 -96
  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/cpp/RNGestureHandlerButtonComponentDescriptor.h +0 -36
  43. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +0 -32
  44. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +0 -22
  45. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +0 -15
  46. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +0 -36
  47. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +0 -25
  48. package/harmony/gesture_handler/src/main/ets/core/ViewFinder.ts +0 -11
  49. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +0 -24
  50. package/harmony/gesture_handler/src/main/ets/namespace/components/RNGestureHandlerButton.ts +0 -139
  51. package/harmony/gesture_handler/src/main/ets/namespace/components/RNGestureHandlerRootView.ts +0 -101
  52. package/harmony/gesture_handler/src/main/ets/namespace/components/ts.ts +0 -2
  53. package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +0 -2
  54. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +0 -98
  55. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +0 -110
  56. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerButton.ets +0 -38
  57. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerRootView.ets +0 -53
  58. package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +0 -134
  59. package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +0 -97
@@ -1,36 +0,0 @@
1
-
2
- #pragma once
3
-
4
- // This file was generated.
5
-
6
- #include <react/renderer/core/ConcreteComponentDescriptor.h>
7
- #include <react/renderer/components/view/ConcreteViewShadowNode.h>
8
- #include <react/renderer/components/view/ViewShadowNode.h>
9
-
10
- namespace facebook {
11
- namespace react {
12
-
13
- extern const char RNGestureHandlerRootViewComponentName[] = "RNGestureHandlerRootView";
14
-
15
- class RNGestureHandlerRootViewProps : public ViewProps {
16
- public:
17
- RNGestureHandlerRootViewProps() = default;
18
-
19
- RNGestureHandlerRootViewProps(const PropsParserContext &context, const RNGestureHandlerRootViewProps &sourceProps, const RawProps &rawProps)
20
- : ViewProps(context, sourceProps, rawProps) {}
21
- };
22
-
23
- using RNGestureHandlerRootViewShadowNode = ConcreteViewShadowNode<
24
- RNGestureHandlerRootViewComponentName,
25
- RNGestureHandlerRootViewProps,
26
- ViewEventEmitter>;
27
-
28
- class RNGestureHandlerRootViewComponentDescriptor final
29
- : public ConcreteComponentDescriptor<RNGestureHandlerRootViewShadowNode> {
30
- public:
31
- RNGestureHandlerRootViewComponentDescriptor(ComponentDescriptorParameters const &parameters)
32
- : ConcreteComponentDescriptor(parameters) {}
33
- };
34
-
35
- } // namespace react
36
- } // namespace facebook
@@ -1,25 +0,0 @@
1
- #pragma once
2
-
3
- // This file was generated.
4
-
5
- #include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
6
-
7
- namespace rnoh {
8
- class RNGestureHandlerRootViewJSIBinder : public ViewComponentJSIBinder {
9
- protected:
10
- facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
11
- auto object = ViewComponentJSIBinder::createNativeProps(rt);
12
- return object;
13
- }
14
-
15
- facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
16
- facebook::jsi::Object events(rt);
17
- return events;
18
- }
19
-
20
- facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
21
- facebook::jsi::Object events(rt);
22
- return events;
23
- }
24
- };
25
- } // namespace rnoh
@@ -1,11 +0,0 @@
1
- import { Tag, View } from "./View"
2
-
3
- export interface ViewFinder {
4
- getTouchableViewsAt(
5
- pointRelativeToRoot: {
6
- x: number,
7
- y: number
8
- },
9
- rootTag: Tag
10
- ): View[]
11
- }
@@ -1,24 +0,0 @@
1
- // This file was generated.
2
-
3
- export namespace RNGestureHandlerModule {
4
- export const NAME = 'RNGestureHandlerModule' as const
5
-
6
- export interface Spec {
7
- handleSetJSResponder(tag: number, blockNativeResponder: boolean): void;
8
-
9
- handleClearJSResponder(): void;
10
-
11
- createGestureHandler(handlerName: string, handlerTag: number, config: Object): void;
12
-
13
- attachGestureHandler(handlerTag: number, newView: number, actionType: number): void;
14
-
15
- updateGestureHandler(handlerTag: number, newConfig: Object): void;
16
-
17
- dropGestureHandler(handlerTag: number): void;
18
-
19
- install(): boolean;
20
-
21
- flushOperations(): void;
22
-
23
- }
24
- }
@@ -1,139 +0,0 @@
1
- // This file was generated.
2
- import {
3
- Descriptor as ComponentDescriptor,
4
- ViewBaseProps,
5
- ViewRawProps,
6
- ViewDescriptorWrapperBase,
7
- ColorValue,
8
- Color,
9
- RNInstance,
10
- Tag,
11
- RNComponentCommandReceiver,
12
- ViewPropsSelector,
13
- } from '@rnoh/react-native-openharmony/ts';
14
-
15
-
16
- export namespace RNGestureHandlerButton {
17
- export const NAME = "RNGestureHandlerButton" as const
18
-
19
- export interface DirectRawProps {
20
- exclusive?: boolean;
21
- foreground?: boolean;
22
- borderless?: boolean;
23
- enabled?: boolean;
24
- rippleColor?: ColorValue;
25
- rippleRadius?: number;
26
- touchSoundDisabled?: boolean;
27
- }
28
-
29
- export interface Props extends ViewBaseProps {}
30
-
31
- export interface State {}
32
-
33
- export interface RawProps extends ViewRawProps, DirectRawProps {}
34
-
35
- export class PropsSelector extends ViewPropsSelector<Props, RawProps> {
36
- get exclusive() {
37
- return this.rawProps.exclusive ?? true;
38
- }
39
-
40
- get foreground() {
41
- return this.rawProps.foreground ?? false;
42
- }
43
-
44
- get borderless() {
45
- return this.rawProps.borderless ?? false;
46
- }
47
-
48
- get enabled() {
49
- return this.rawProps.enabled ?? true;
50
- }
51
-
52
- get rippleRadius() {
53
- return this.rawProps.rippleRadius ?? 0;
54
- }
55
-
56
- get touchSoundDisabled() {
57
- return this.rawProps.touchSoundDisabled ?? false;
58
- }
59
-
60
-
61
- get rippleColor() {
62
- if (this.rawProps.rippleColor) {
63
- return Color.fromColorValue(this.rawProps.rippleColor)
64
- } else {
65
- return new Color({ r: 0, g: 0, b: 0, a: 255})
66
- }
67
- }
68
-
69
- }
70
-
71
- export type Descriptor = ComponentDescriptor<
72
- typeof NAME,
73
- Props,
74
- State,
75
- RawProps
76
- >;
77
-
78
- export class DescriptorWrapper extends ViewDescriptorWrapperBase<
79
- typeof NAME,
80
- Props,
81
- State,
82
- RawProps,
83
- PropsSelector
84
- > {
85
- protected createPropsSelector() {
86
- return new PropsSelector(this.descriptor.props, this.descriptor.rawProps)
87
- }
88
- }
89
-
90
- export interface EventPayloadByName {
91
- }
92
-
93
- export class EventEmitter {
94
- constructor(private rnInstance: RNInstance, private tag: Tag) {}
95
-
96
- emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) {
97
- this.rnInstance.emitComponentEvent(this.tag, eventName, payload)
98
- }
99
- }
100
-
101
- export interface CommandArgvByName {
102
- }
103
-
104
- export class CommandReceiver {
105
- private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>()
106
- private cleanUp: (() => void) | undefined = undefined
107
-
108
- constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) {
109
- }
110
-
111
- subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) {
112
- if (!this.listenersByCommandName.has(commandName)) {
113
- this.listenersByCommandName.set(commandName, new Set())
114
- }
115
- this.listenersByCommandName.get(commandName)!.add(listener)
116
- const hasRegisteredCommandReceiver = !!this.cleanUp
117
- if (!hasRegisteredCommandReceiver) {
118
- this.cleanUp = this.componentCommandReceiver.registerCommandCallback(this.tag, (commandName: string, argv: any[]) => {
119
- if (this.listenersByCommandName.has(commandName)) {
120
- const listeners = this.listenersByCommandName.get(commandName)!
121
- listeners.forEach(listener => {
122
- listener(argv)
123
- })
124
- }
125
- })
126
- }
127
-
128
- return () => {
129
- this.listenersByCommandName.get(commandName)?.delete(listener)
130
- if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) {
131
- this.listenersByCommandName.delete(commandName)
132
- }
133
- if (this.listenersByCommandName.size === 0) {
134
- this.cleanUp?.()
135
- }
136
- }
137
- }
138
- }
139
- }
@@ -1,101 +0,0 @@
1
- // This file was generated.
2
- import {
3
- Descriptor as ComponentDescriptor,
4
- ViewBaseProps,
5
- ViewRawProps,
6
- ViewDescriptorWrapperBase,
7
- ColorValue,
8
- Color,
9
- RNInstance,
10
- Tag,
11
- RNComponentCommandReceiver,
12
- ViewPropsSelector,
13
- } from '@rnoh/react-native-openharmony/ts';
14
-
15
-
16
- export namespace RNGestureHandlerRootView {
17
- export const NAME = "RNGestureHandlerRootView" as const
18
-
19
- export interface DirectRawProps {
20
- }
21
-
22
- export interface Props extends ViewBaseProps {}
23
-
24
- export interface State {}
25
-
26
- export interface RawProps extends ViewRawProps, DirectRawProps {}
27
-
28
- export class PropsSelector extends ViewPropsSelector<Props, RawProps> {
29
-
30
- }
31
-
32
- export type Descriptor = ComponentDescriptor<
33
- typeof NAME,
34
- Props,
35
- State,
36
- RawProps
37
- >;
38
-
39
- export class DescriptorWrapper extends ViewDescriptorWrapperBase<
40
- typeof NAME,
41
- Props,
42
- State,
43
- RawProps,
44
- PropsSelector
45
- > {
46
- protected createPropsSelector() {
47
- return new PropsSelector(this.descriptor.props, this.descriptor.rawProps)
48
- }
49
- }
50
-
51
- export interface EventPayloadByName {
52
- }
53
-
54
- export class EventEmitter {
55
- constructor(private rnInstance: RNInstance, private tag: Tag) {}
56
-
57
- emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) {
58
- this.rnInstance.emitComponentEvent(this.tag, eventName, payload)
59
- }
60
- }
61
-
62
- export interface CommandArgvByName {
63
- }
64
-
65
- export class CommandReceiver {
66
- private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>()
67
- private cleanUp: (() => void) | undefined = undefined
68
-
69
- constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) {
70
- }
71
-
72
- subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) {
73
- if (!this.listenersByCommandName.has(commandName)) {
74
- this.listenersByCommandName.set(commandName, new Set())
75
- }
76
- this.listenersByCommandName.get(commandName)!.add(listener)
77
- const hasRegisteredCommandReceiver = !!this.cleanUp
78
- if (!hasRegisteredCommandReceiver) {
79
- this.cleanUp = this.componentCommandReceiver.registerCommandCallback(this.tag, (commandName: string, argv: any[]) => {
80
- if (this.listenersByCommandName.has(commandName)) {
81
- const listeners = this.listenersByCommandName.get(commandName)!
82
- listeners.forEach(listener => {
83
- listener(argv)
84
- })
85
- }
86
- })
87
- }
88
-
89
- return () => {
90
- this.listenersByCommandName.get(commandName)?.delete(listener)
91
- if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) {
92
- this.listenersByCommandName.delete(commandName)
93
- }
94
- if (this.listenersByCommandName.size === 0) {
95
- this.cleanUp?.()
96
- }
97
- }
98
- }
99
- }
100
-
101
- }
@@ -1,2 +0,0 @@
1
- export * from "./RNGestureHandlerButton"
2
- export * from "./RNGestureHandlerRootView"
@@ -1,2 +0,0 @@
1
- export * as RNC from "./components/ts"
2
- export * as TM from "./RNGestureHandlerModule"
@@ -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
- }
@@ -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
- }