@react-native-ohos/react-native-context-menu-view 1.16.1-rc.1

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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +13 -0
  4. package/harmony/context_menu/BuildProfile.ets +17 -0
  5. package/harmony/context_menu/build-profile.json5 +12 -0
  6. package/harmony/context_menu/hvigorfile.ts +2 -0
  7. package/harmony/context_menu/index.ets +28 -0
  8. package/harmony/context_menu/oh-package.json5 +12 -0
  9. package/harmony/context_menu/src/main/cpp/CMakeLists.txt +8 -0
  10. package/harmony/context_menu/src/main/cpp/ComponentDescriptors.h +18 -0
  11. package/harmony/context_menu/src/main/cpp/ContextMenuJSIBinder.h +58 -0
  12. package/harmony/context_menu/src/main/cpp/ContextMenuPackage.h +140 -0
  13. package/harmony/context_menu/src/main/cpp/ContextMenuTurboModule.cpp +36 -0
  14. package/harmony/context_menu/src/main/cpp/ContextMenuTurboModule.h +38 -0
  15. package/harmony/context_menu/src/main/cpp/EventEmitters.cpp +49 -0
  16. package/harmony/context_menu/src/main/cpp/EventEmitters.h +41 -0
  17. package/harmony/context_menu/src/main/cpp/Props.cpp +33 -0
  18. package/harmony/context_menu/src/main/cpp/Props.h +115 -0
  19. package/harmony/context_menu/src/main/cpp/RTNContextMenuComponentInstance.cpp +286 -0
  20. package/harmony/context_menu/src/main/cpp/RTNContextMenuComponentInstance.h +165 -0
  21. package/harmony/context_menu/src/main/cpp/ShadowNodes.cpp +15 -0
  22. package/harmony/context_menu/src/main/cpp/ShadowNodes.h +30 -0
  23. package/harmony/context_menu/src/main/cpp/States.cpp +15 -0
  24. package/harmony/context_menu/src/main/cpp/States.h +34 -0
  25. package/harmony/context_menu/src/main/ets/ContextMenuLongPress.ets +374 -0
  26. package/harmony/context_menu/src/main/ets/ContextMenuLongPressWithNoSelect.ets +356 -0
  27. package/harmony/context_menu/src/main/ets/ContextMenuPackage.ets +48 -0
  28. package/harmony/context_menu/src/main/ets/ContextMenuThreeMenu.ets +224 -0
  29. package/harmony/context_menu/src/main/ets/ContextMenuThreeMenuWithNoSelect.ets +221 -0
  30. package/harmony/context_menu/src/main/ets/ContextMenuTurboModule.ets +293 -0
  31. package/harmony/context_menu/src/main/ets/ContextMenuTwoMenu.ets +209 -0
  32. package/harmony/context_menu/src/main/ets/ContextMenuTwoMenuWithNoSelect.ets +207 -0
  33. package/harmony/context_menu/src/main/ets/Logger.ets +64 -0
  34. package/harmony/context_menu/src/main/module.json5 +7 -0
  35. package/harmony/context_menu/src/main/resources/base/element/string.json +8 -0
  36. package/harmony/context_menu/src/main/resources/base/media/airplane_fill.png +0 -0
  37. package/harmony/context_menu/src/main/resources/base/media/background.png +0 -0
  38. package/harmony/context_menu/src/main/resources/base/media/foreground.png +0 -0
  39. package/harmony/context_menu/src/main/resources/base/media/layered_image.json +7 -0
  40. package/harmony/context_menu/src/main/resources/base/media/startIcon.png +0 -0
  41. package/harmony/context_menu/src/main/resources/base/profile/backup_config.json +3 -0
  42. package/harmony/context_menu/src/main/resources/base/profile/main_pages.json +5 -0
  43. package/harmony/context_menu/src/main/resources/en_US/element/string.json +8 -0
  44. package/harmony/context_menu/src/main/resources/zh_CN/element/string.json +8 -0
  45. package/harmony/context_menu/ts.ets +26 -0
  46. package/harmony/context_menu.har +0 -0
  47. package/index.js +44 -0
  48. package/package.json +49 -0
  49. package/react-native-context-menu-view.podspec +26 -0
  50. package/src/RTNContextMenuNativeComponent.ts +50 -0
@@ -0,0 +1,221 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { RNOHContext, } from '@rnoh/react-native-openharmony'
26
+ import Logger from './Logger';
27
+ import { SymbolGlyphModifier } from '@kit.ArkUI';
28
+ import { ContextMenuThreeMenu } from './ContextMenuThreeMenu';
29
+
30
+ //这里的属性类型要和ContextMenuTurboModule.ets下的ContextMenuProps一致
31
+ interface ContextMenuProps {
32
+ tag?: number;
33
+ width?: number;
34
+ height?: number;
35
+ x?: number;
36
+ y?: number;
37
+ windowX?: number;
38
+ windowY?: number;
39
+ title?: string;
40
+ action?: string;
41
+ dropdownMenuMode?: boolean;
42
+ disabled?: boolean;
43
+ subtitle?: string;
44
+
45
+ // disabledArray?: Array<boolean>;
46
+ selected?: boolean;
47
+ previewBackgroundColor?: string;
48
+ actionsTitle?: string;
49
+ touchViewActions?: ContextMenuProps
50
+ ctx: RNOHContext
51
+ romWidth?: number;
52
+ romHeight?: number;
53
+ systemIcon?: string;
54
+ icon?: string;
55
+ destructive?: string
56
+ iconColor?: string;
57
+
58
+ //二级目录
59
+ inlineChildren?: boolean;
60
+ d_childActions?: ContextMenuProps;
61
+ childActionsTag?: number;
62
+
63
+ //2+目录
64
+ childActions?: ContextMenuProps;
65
+ }
66
+
67
+ @Component
68
+ export struct ContextMenuThreeMenuWithNoSelect {
69
+ public static readonly NAME = "ContextMenuThreeMenuWithNoSelect"
70
+ menuCtx!: RNOHContext;
71
+ menuTag: number = 0;
72
+ longPress: ESObject = []
73
+ @State realViewPoint: Object = [];
74
+ @State listDate: ContextMenuProps[] = [];
75
+ @State menuIndexPath: number[] = [];
76
+ @State menuDestructive: string = '';
77
+ @State childActionsListDate: ESObject[] = [];
78
+ @State isTouch: boolean | undefined = false;
79
+ @State isTouchViewNumber: number = 0;
80
+ @State isChildActionsTouchViewNumber: number = 0;
81
+ @State menuChildActions: ContextMenuProps[] = [];
82
+ @State menuChild: ESObject[] = [];
83
+ @State deepChildActions: ESObject[] = [];
84
+ @State isShow: boolean = false;
85
+ @State nextMenu: ESObject[] = [];
86
+ @State selectedFlag: number = 0;
87
+
88
+ aboutToAppear() {
89
+ //从前一个菜单传递过来的
90
+ this.longPress = this.realViewPoint;
91
+ this.menuCtx = this.menuCtx;
92
+ this.menuTag = this.menuTag;
93
+ Logger.info('2024-3menu:' + JSON.stringify(this.longPress))
94
+ //menu的大标题
95
+ this.listDate = this.longPress;
96
+ Logger.info('2024-3menu,this.listDate:' + JSON.stringify(this.listDate))
97
+ for (let i = 0; i < this.listDate.length; i++) {
98
+ if (this.listDate[i] !== null && this.listDate[i] !== undefined) {
99
+ //为true,表示禁用,对应harmony next 的false
100
+ if (this.listDate[i].disabled) {
101
+ //为true,表示禁用,对应harmony next 的false
102
+ this.listDate[i].disabled = false;
103
+ } else {
104
+ //contextMenu的false 对标 harmony 的 true
105
+ this.listDate[i].disabled = true;
106
+ }
107
+ }
108
+ }
109
+ //遍历传递回前端的indexPath,indexPath只会计算子节点index
110
+ //第一个节点表示对应的深层目录,从3级起算
111
+ for (let i = 0; i < this.listDate.length; i++) {
112
+ this.menuIndexPath[i+1] = i;
113
+ }
114
+ for (let i = 0; i < this.listDate.length; i++) {
115
+ if (this.longPress[i].selected) {
116
+ this.selectedFlag++;
117
+ }
118
+ }
119
+
120
+ }
121
+
122
+ //退出组件
123
+ aboutToDisappear() {
124
+ }
125
+
126
+ @Builder
127
+ NextMenuWithNoSelect() {
128
+ ContextMenuThreeMenuWithNoSelect(
129
+ {
130
+ realViewPoint: this.nextMenu,
131
+ menuCtx: this.menuCtx,
132
+ menuTag: this.menuTag
133
+ });
134
+ }
135
+
136
+ @Builder
137
+ NextMenu() {
138
+ ContextMenuThreeMenu(
139
+ {
140
+ realViewPoint: this.nextMenu,
141
+ menuCtx: this.menuCtx,
142
+ menuTag: this.menuTag
143
+ });
144
+ }
145
+
146
+ build() {
147
+ Menu() {
148
+ ForEach(this.listDate, (childItem: ContextMenuProps, index1) => {
149
+ if (childItem.systemIcon) {
150
+ MenuItem({
151
+ content: childItem.title,
152
+ symbolEndIcon: new SymbolGlyphModifier($r(childItem.systemIcon)).fontSize('24vp')
153
+ .fontColor([childItem.iconColor]),
154
+ labelInfo: childItem.subtitle,
155
+ builder: (): void => {
156
+ if (childItem.childActions !== undefined) {
157
+ this.nextMenu = this.longPress[index1].childActions;
158
+ if (this.selectedFlag !== 0) {
159
+ this.NextMenu();
160
+ } else {
161
+ this.NextMenuWithNoSelect();
162
+ }
163
+ }
164
+ }
165
+ })//selected复选标记,根据传入的selected来判断selected为默认为false,不显示
166
+ .alignSelf(ItemAlign.Start)
167
+ .enabled(childItem.disabled)
168
+ .contentFontColor(childItem.destructive)
169
+ .onClick(() => {
170
+ this.nextMenu = this.longPress[index1].childActions;
171
+ this.isTouch = true && (!childItem.inlineChildren) && (childItem.childActions !== undefined);
172
+ this.isTouchViewNumber = index1;
173
+ if (childItem.inlineChildren || (childItem.childActions == undefined)) {
174
+ this.menuCtx.rnInstance.postMessageToCpp('contextMenu::SET_NATIVE_RESPONDERS_BLOCK', {
175
+ itemTitle: childItem.title,
176
+ itemTag: this.menuTag,
177
+ itemIndex: index1,
178
+ itemIndexPath: this.menuIndexPath,
179
+ itemInlineChildren: childItem.inlineChildren
180
+ });
181
+ }
182
+ })
183
+ } else {
184
+ MenuItem({
185
+ content: childItem.title,
186
+ endIcon: $r(childItem.icon),
187
+ labelInfo: childItem.subtitle,
188
+ builder: (): void => {
189
+ if (childItem.childActions !== undefined) {
190
+ this.nextMenu = this.longPress[index1].childActions;
191
+ if (this.selectedFlag !== 0) {
192
+ this.NextMenu();
193
+ } else {
194
+ this.NextMenuWithNoSelect();
195
+ }
196
+ }
197
+ }
198
+ })//selected复选标记,根据传入的selected来判断selected为默认为false,不显示
199
+ .alignSelf(ItemAlign.Start)
200
+ .enabled(childItem.disabled)
201
+ .contentFontColor(childItem.destructive)
202
+ .onClick(() => {
203
+ this.nextMenu = this.longPress[index1].childActions;
204
+ this.isTouch = true && (!childItem.inlineChildren) && (childItem.childActions !== undefined);
205
+ this.isTouchViewNumber = index1;
206
+ if (childItem.inlineChildren || (childItem.childActions == undefined)) {
207
+ this.menuCtx.rnInstance.postMessageToCpp('contextMenu::SET_NATIVE_RESPONDERS_BLOCK', {
208
+ itemTitle: childItem.title,
209
+ itemTag: this.menuTag,
210
+ itemIndex: index1,
211
+ itemIndexPath: this.menuIndexPath,
212
+ itemInlineChildren: childItem.inlineChildren
213
+ });
214
+ }
215
+ })
216
+ }
217
+
218
+ })
219
+ }
220
+ }
221
+ }
@@ -0,0 +1,293 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { TurboModule, TurboModuleContext } from "@rnoh/react-native-openharmony/ts";
26
+ import { ComponentContent, window } from '@kit.ArkUI';
27
+ import { ContextMenuLongPress } from './ContextMenuLongPress';
28
+ import { RNOHContext } from '@rnoh/react-native-openharmony';
29
+ import { ContextMenuLongPressWithNoSelect } from './ContextMenuLongPressWithNoSelect';
30
+
31
+ @Builder
32
+ //offset的单位是vp,传递的x,y值也对应的是组件里面的xy值,单点的特效
33
+ function buildContextMenu(realViewPoint: ESObject) {
34
+ ContextMenuLongPress({ realViewPoint: realViewPoint })
35
+ }
36
+
37
+ @Builder
38
+ //不带Select属性或者Select属性为false
39
+ function buildContextMenuWithNoSelect(realViewPoint: ESObject) {
40
+ ContextMenuLongPressWithNoSelect({ realViewPoint: realViewPoint })
41
+ }
42
+
43
+
44
+ export interface ContextMenuProps {
45
+ tag?: number;
46
+ width?: number;
47
+ height?: number;
48
+ x?: number;
49
+ y?: number;
50
+ windowX?: number;
51
+ windowY?: number;
52
+ title?: string;
53
+ subtitle?: string;
54
+ action?: string;
55
+ dropdownMenuMode?: boolean;
56
+ disabled?: boolean;
57
+ previewBackgroundColor?: string;
58
+ actionsTitle?: string;
59
+ touchViewActions?: ContextMenuProps;
60
+ ctx?: RNOHContext;
61
+ romWidth?: number;
62
+ romHeight?: number;
63
+ systemIcon?: string;
64
+ selected?: boolean;
65
+ destructive?: string
66
+ d_childActions?: ContextMenuProps;
67
+ inlineChildren?: boolean;
68
+ iconColor?: string;
69
+ childActions?: ContextMenuProps;
70
+ childActionsTag?: number;
71
+ }
72
+
73
+ export class ContextMenuTurboModule extends TurboModule {
74
+ //基本判定属性
75
+ timestamp: number = 0;
76
+ result: number = 0;
77
+ longResult: number = 0;
78
+ isCancel: boolean = false;
79
+ realViewPoint: ContextMenuProps = {};
80
+ touchViewActions: ContextMenuProps = {};
81
+ downTimestamp: number = 0;
82
+ upTimestamp: number = 0;
83
+ header: string = '';
84
+ longPressLock: boolean = false;
85
+ longPressTimestamp: number = 0;
86
+ //contextMenu所携带的属性
87
+ title: string = '';
88
+ actions: string = '';
89
+ dropdownMenuMode: boolean = false;
90
+ previewBackgroundColor: string = '';
91
+ actionsTitle: string = '';
92
+ //弹窗偏移量需要的值
93
+ width: number = 0;
94
+ height: number = 0;
95
+ romWidth: number = 0;
96
+ romHeight: number = 0;
97
+ windowX: number = 0;
98
+ windowY: number = 0;
99
+ customDialogOpen: boolean = false;
100
+ selectedFlag: number = 0;
101
+ menuHeight: number = 0;
102
+
103
+ constructor(ctx: TurboModuleContext) {
104
+ super(ctx)
105
+ if (this.ctx.rnInstance.getArchitecture() === "C_API") {
106
+ //e为C层拦截的ArkUI_UIInputEvent
107
+ this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::TOUCH_EVENT", (e: ESObject) => {
108
+ //获取view坐标
109
+ console.log('ContextMenu:在ArkTs侧获取到了点击事件!TOUCH_EVENT,touchableViews:' +
110
+ JSON.stringify(e.touchableViews) + '最后点击的节点为View:' + JSON.stringify(e.touchableViews[e.touchableViews.length-1]));
111
+ //e.action进行获取点击事件的次数,进行判定
112
+ switch (e.action) {
113
+ case 1:
114
+ //down手势判断,这里通过,手指按下的时间戳进行判断
115
+ this.downTimestamp = e.timestamp / Math.pow(10, 6);
116
+ //获取设备的rom
117
+ this.realViewPoint.romWidth = e.touchableViews[0].width;
118
+ this.romWidth = e.touchableViews[0].width;
119
+ this.realViewPoint.romHeight = e.touchableViews[0].height;
120
+ this.romHeight = e.touchableViews[0].height;
121
+ break;
122
+ case 2:
123
+ //isCancel = true; move x1-x > 150 移动判断 y1-y >200
124
+ //在按压的时候,此时会一直接口case2的消息,如果此在点击区域,且e.dropdownMenuMode为false按压事件超过500ms,则需要触发长按事件
125
+ this.longPressTimestamp = e.timestamp / Math.pow(10, 6);
126
+ this.longResult = this.longPressTimestamp - this.downTimestamp
127
+ if (e.touchableViews[e.touchableViews.length-1] && !(e.dropdownMenuMode) && this.longResult >= 500) {
128
+ //2024.12.06 fix:当处于多层嵌套外层情况下,tag值会错误
129
+ this.realViewPoint.tag = e.rootTag;
130
+ this.realViewPoint.x = e.touchableViews[e.touchableViews.length-1].x;
131
+ this.realViewPoint.y = e.touchableViews[e.touchableViews.length-1].y;
132
+ this.realViewPoint.width = e.touchableViews[e.touchableViews.length-1].width;
133
+ this.width = e.touchableViews[e.touchableViews.length-1].width;
134
+ this.realViewPoint.height = e.touchableViews[e.touchableViews.length-1].height;
135
+ this.height = e.touchableViews[e.touchableViews.length-1].height;
136
+ this.realViewPoint.title = e.title;
137
+ //获取点击的时候的触摸事件的坐标
138
+ this.realViewPoint.windowX = e.touchPoints[0].windowX;
139
+ this.windowX = e.touchPoints[0].windowX;
140
+ this.realViewPoint.windowY = e.touchPoints[0].windowY;
141
+ this.windowY = e.touchPoints[0].windowY;
142
+ this.realViewPoint.touchViewActions = e.touchViewActions;
143
+ let selectedActions: ESObject = e.touchViewActions;
144
+ if (!this.longPressLock) {
145
+ this.realViewPoint.ctx = this.ctx;
146
+ for (let i = 0; i < selectedActions.length; i++) {
147
+ if (selectedActions[i].selected) {
148
+ //复选框,默认为false
149
+ this.selectedFlag++;
150
+ }
151
+ this.menuHeight++;
152
+ }
153
+ if (this.menuHeight >= 5) {
154
+ this.menuHeight = this.menuHeight - 5;
155
+ } else {
156
+ this.menuHeight = 0;
157
+ }
158
+ if (this.selectedFlag > 0) {
159
+ //传入对应的ctx
160
+ this.realViewPoint.ctx = this.ctx;
161
+ this.onTouch(this.realViewPoint);
162
+ this.selectedFlag = 0;
163
+ } else {
164
+ //传入对应的ctx
165
+ this.realViewPoint.ctx = this.ctx;
166
+ //当获取到了view视图,并且dropdownMenuMode为true的时候,进入单点效果.
167
+ this.onTouchWithNoSelect(this.realViewPoint);
168
+ this.selectedFlag = 0;
169
+ }
170
+ this.longPressLock = true;
171
+ }
172
+ }
173
+ break;
174
+ case 3:
175
+ //up 手势判断,走入up才算一次点击;up手势判断,这里通过,手指按下的时间戳进行判断
176
+ this.upTimestamp = e.timestamp / Math.pow(10, 6);
177
+ //计算result,如果>=500则为长按,如果<500为单击
178
+ this.result = this.upTimestamp - this.downTimestamp
179
+ //e.touchableViews:当点击view区域时,到获取的view固定有三个,主屏幕,contextmenu容器,view.需要获取view的坐标,view固定为数组中第三个
180
+ //当点击外部的stack区域时候,获取的view只有两个,主屏幕和contextmenu容器,逻辑上是点击view才会触发menu
181
+ // dropdownMenuMode-->true---->onTouch(),如果此时点击的事件大于500ms则不触发点击事件,如果小于500ms则触发点击效果
182
+ if (e.touchableViews[e.touchableViews.length-1] && e.dropdownMenuMode && this.result < 500) {
183
+ this.realViewPoint.tag = e.rootTag;
184
+ this.realViewPoint.x = e.touchableViews[e.touchableViews.length-1].x;
185
+ this.realViewPoint.y = e.touchableViews[e.touchableViews.length-1].y;
186
+ this.realViewPoint.width = e.touchableViews[e.touchableViews.length-1].width;
187
+ this.width = e.touchableViews[e.touchableViews.length-1].width;
188
+ this.realViewPoint.height = e.touchableViews[e.touchableViews.length-1].height;
189
+ this.height = e.touchableViews[e.touchableViews.length-1].height;
190
+ this.realViewPoint.title = e.title;
191
+ //点击事件,触摸坐标
192
+ this.realViewPoint.windowX = e.touchPoints[0].windowX;
193
+ this.windowX = e.touchPoints[0].windowX;
194
+ this.realViewPoint.windowY = e.touchPoints[0].windowY;
195
+ this.windowY = e.touchPoints[0].windowY;
196
+ //此处获取actions值
197
+ this.realViewPoint.touchViewActions = e.touchViewActions;
198
+ //当获取到了view视图,并且dropdownMenuMode为true的时候,进入单点效果.
199
+ let selectedActions: ESObject = e.touchViewActions;
200
+ for (let i = 0; i < selectedActions.length; i++) {
201
+ if (selectedActions[i].selected) {
202
+ //复选框,默认为false
203
+ this.selectedFlag++;
204
+ }
205
+ this.menuHeight++;
206
+ }
207
+ if (this.menuHeight >= 5) {
208
+ this.menuHeight = this.menuHeight - 5;
209
+ } else {
210
+ this.menuHeight = 0;
211
+ }
212
+ if (this.selectedFlag > 0) {
213
+ //传入对应的ctx
214
+ this.realViewPoint.ctx = this.ctx;
215
+ this.onTouch(this.realViewPoint);
216
+ this.selectedFlag = 0;
217
+ } else {
218
+ //传入对应的ctx
219
+ this.realViewPoint.ctx = this.ctx;
220
+ //当获取到了view视图,并且dropdownMenuMode为true的时候,进入单点效果.
221
+ this.onTouchWithNoSelect(this.realViewPoint);
222
+ this.selectedFlag = 0;
223
+ }
224
+ //e.dropdownMenuMode(默认)--->false,那么默认为长按,如果此时单次点击时间大于500ms则可以触发长按事件,小于500ms则不触发点击事件
225
+ } else if (e.touchableViews[e.touchableViews.length-1] && !(e.dropdownMenuMode) && this.result >= 500) {
226
+ // 因为在case中,已经判定是否为长按,case2中的逻辑,当点击在view视图,且dropdownMenuMode为false,并且,满足按压时间大于500ms,就会走长按
227
+ //并且将长按锁置于true,在手指抬起的时候,会触发case3事件,那么在该处进行判断,不用再触发longPress事件,只用将长按锁置于初始化即可
228
+ this.longPressLock = false;
229
+ }
230
+ break;
231
+ default:
232
+ break;
233
+ }
234
+ })
235
+ }
236
+ }
237
+
238
+ //进行touch单击事件的调用
239
+ //长按和单击均属于点击事件,无非就是时间长短,最后均触发该事件
240
+ onTouch(realViewPoint: Object) {
241
+ window.getLastWindow(this.ctx.uiAbilityContext)
242
+ .then((value) => {
243
+ const uiContext = value.getUIContext()
244
+ const promptAction = uiContext?.getPromptAction();
245
+ const contentNode = new ComponentContent(uiContext!, wrapBuilder(buildContextMenu), realViewPoint);
246
+ let offDx = -this.romWidth / 2 + this.windowX + this.width / 2;
247
+ let OffDy = -this.romHeight / 2 + this.windowY + this.height * 0.4 + 48 * this.menuHeight;
248
+ try {
249
+ promptAction?.openCustomDialog(contentNode, {
250
+ offset: {
251
+ dx: offDx,
252
+ dy: OffDy,
253
+ }
254
+ })
255
+ this.menuHeight = 0;
256
+ this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::CLOSE_MENU", () => {
257
+ promptAction?.closeCustomDialog(contentNode);
258
+ offDx = 0;
259
+ OffDy = 0;
260
+ })
261
+ } catch (error) {
262
+ console.error(`eroor`);
263
+ }
264
+ })
265
+ }
266
+
267
+ onTouchWithNoSelect(realViewPoint: Object) {
268
+ window.getLastWindow(this.ctx.uiAbilityContext)
269
+ .then((value) => {
270
+ const uiContext = value.getUIContext()
271
+ const promptAction = uiContext?.getPromptAction();
272
+ const contentNode = new ComponentContent(uiContext!, wrapBuilder(buildContextMenuWithNoSelect), realViewPoint);
273
+ let offDx = -this.romWidth / 2 + this.windowX + this.width / 2;
274
+ let OffDy = -this.romHeight / 2 + this.windowY + this.height * 0.4 + 48 * this.menuHeight;
275
+ try {
276
+ promptAction?.openCustomDialog(contentNode, {
277
+ offset: {
278
+ dx: offDx,
279
+ dy: OffDy,
280
+ }
281
+ })
282
+ this.menuHeight = 0;
283
+ this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::CLOSE_MENU", () => {
284
+ promptAction?.closeCustomDialog(contentNode);
285
+ offDx = 0;
286
+ OffDy = 0;
287
+ })
288
+ } catch (error) {
289
+ console.error(`eroor`);
290
+ }
291
+ })
292
+ }
293
+ }