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