@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.
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 +9 -0
  6. package/harmony/context_menu/hvigorfile.ts +2 -0
  7. package/harmony/context_menu/index.ets +26 -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 +59 -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 +34 -0
  18. package/harmony/context_menu/src/main/cpp/Props.h +121 -0
  19. package/harmony/context_menu/src/main/cpp/RTNContextMenuComponentInstance.cpp +290 -0
  20. package/harmony/context_menu/src/main/cpp/RTNContextMenuComponentInstance.h +168 -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 +393 -0
  26. package/harmony/context_menu/src/main/ets/ContextMenuLongPressWithNoSelect.ets +375 -0
  27. package/harmony/context_menu/src/main/ets/ContextMenuPackage.ets +47 -0
  28. package/harmony/context_menu/src/main/ets/ContextMenuThreeMenu.ets +225 -0
  29. package/harmony/context_menu/src/main/ets/ContextMenuThreeMenuWithNoSelect.ets +222 -0
  30. package/harmony/context_menu/src/main/ets/ContextMenuTurboModule.ets +297 -0
  31. package/harmony/context_menu/src/main/ets/ContextMenuTwoMenu.ets +210 -0
  32. package/harmony/context_menu/src/main/ets/ContextMenuTwoMenuWithNoSelect.ets +208 -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 +39 -0
  49. package/react-native-context-menu-view.podspec +26 -0
  50. package/src/RTNContextMenuNativeComponent.ts +50 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matthew Iannucci
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "Name": "react-native-context-menu-view",
4
+ "License": "MIT License",
5
+ "License File": "https://github.com/mpiannucci/react-native-context-menu-view/blob/v1.19.0/LICENSE",
6
+ "Version Number": "1.19.0",
7
+ "Owner" : "xiafeng@huawei.com",
8
+ "Upstream URL": "https://github.com/mpiannucci/react-native-context-menu-view/tree/v1.19.0",
9
+ "Description": "Use native context menus in React Native"
10
+ }
11
+ ]
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @react-native-ohos/react-native-context-menu-view
2
+
3
+ This project is based on [react-native-context-menu-view](https://github.com/mpiannucci/react-native-context-menu-view/tree/v1.19.0)
4
+
5
+ ## Documentation
6
+
7
+ - [中文](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-context-menu-view.md)
8
+
9
+ - [English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/en/react-native-context-menu-view.md)
10
+
11
+ ## License
12
+
13
+ This library is licensed under [The MIT License (MIT)](https://github.com/mpiannucci/react-native-context-menu-view/blob/v1.19.0/LICENSE)
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Use these variables when you tailor your ArkTS code. They must be of the const type.
3
+ */
4
+ export const HAR_VERSION = '1.19.1-rc.1';
5
+ export const BUILD_MODE_NAME = 'debug';
6
+ export const DEBUG = true;
7
+ export const TARGET_NAME = 'default';
8
+
9
+ /**
10
+ * BuildProfile Class is used only for compatibility purposes.
11
+ */
12
+ export default class BuildProfile {
13
+ static readonly HAR_VERSION = HAR_VERSION;
14
+ static readonly BUILD_MODE_NAME = BUILD_MODE_NAME;
15
+ static readonly DEBUG = DEBUG;
16
+ static readonly TARGET_NAME = TARGET_NAME;
17
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "apiType": "stageMode",
3
+ "targets": [
4
+ {
5
+ "name": "default",
6
+ "runtimeOS": "HarmonyOS"
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1,2 @@
1
+ // Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
2
+ export { harTasks } from '@ohos/hvigor-ohos-plugin';
@@ -0,0 +1,26 @@
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
+ export * from './ts'
26
+ export * from './src/main/ets/ContextMenuLongPress'
@@ -0,0 +1,12 @@
1
+ {
2
+ license: 'ISC',
3
+ types: '',
4
+ name: "@react-native-ohos/react-native-context-menu-view",
5
+ version: '1.19.1-rc.1',
6
+ description: '',
7
+ main: 'index.ets',
8
+ type: 'module',
9
+ dependencies: {
10
+ "@rnoh/react-native-openharmony": "file:../react_native_openharmony"
11
+ },
12
+ }
@@ -0,0 +1,8 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ set(CMAKE_VERBOSE_MAKEFILE on)
3
+
4
+ file(GLOB rnoh_context_menu_SRC CONFIGURE_DEPENDS *.cpp)
5
+ add_library(rnoh_context_menu SHARED ${rnoh_context_menu_SRC})
6
+ target_include_directories(rnoh_context_menu PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
7
+ target_link_libraries(rnoh_context_menu PUBLIC rnoh)
8
+
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ #pragma once
8
+
9
+ #include "ShadowNodes.h"
10
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
11
+
12
+ namespace facebook {
13
+ namespace react {
14
+
15
+ using RTNContextMenuComponentDescriptor = ConcreteComponentDescriptor<RTNContextMenuShadowNode>;
16
+
17
+ } // namespace react
18
+ } // namespace facebook
@@ -0,0 +1,59 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 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
+ #pragma once
26
+ #include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
27
+
28
+ namespace rnoh {
29
+ class RTNContextMenuJSIBinder : public ViewComponentJSIBinder {
30
+
31
+ protected:
32
+ facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
33
+ LOG(INFO) << "ContextMenuJSIBinder----createNativeProps";
34
+ auto object = ViewComponentJSIBinder::createNativeProps(rt);
35
+ object.setProperty(rt, "title", "string");
36
+ object.setProperty(rt, "subtitle", "string");
37
+ object.setProperty(rt, "icon", "string");
38
+ object.setProperty(rt, "systemIcon", "string");
39
+ object.setProperty(rt, "dropdownMenuMode", "bool");
40
+ object.setProperty(rt, "disabled", "bool");
41
+ object.setProperty(rt, "destructive", "bool");
42
+ object.setProperty(rt, "inlineChildren", "bool");
43
+ object.setProperty(rt, "selected", "bool");
44
+ object.setProperty(rt, "previewBackgroundColor", "string");
45
+ object.setProperty(rt, "actions", "Object");
46
+ object.setProperty(rt, "fontName", "string");
47
+ return object;
48
+ }
49
+
50
+ facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
51
+ LOG(INFO) << "ContextMenuJSIBinder----createDirectEventTypes";
52
+ facebook::jsi::Object events = ViewComponentJSIBinder::createDirectEventTypes(rt);
53
+ events.setProperty(rt, "topPress", createDirectEvent(rt, "onPress"));
54
+ events.setProperty(rt, "topPreviewPress", createDirectEvent(rt, "onPreviewPress"));
55
+ events.setProperty(rt, "topCancel", createDirectEvent(rt, "onCancel"));
56
+ return events;
57
+ }
58
+ };
59
+ } // namespace rnoh
@@ -0,0 +1,140 @@
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
+ #include "RNOH/Package.h"
26
+ #include "RTNContextMenuComponentInstance.h"
27
+ #include "ComponentDescriptors.h"
28
+ #include "ContextMenuJSIBinder.h"
29
+ #include "ContextMenuTurboModule.h"
30
+
31
+ using namespace rnoh;
32
+ using namespace facebook;
33
+
34
+ namespace rnoh {
35
+
36
+ class ContextMenuPackageComponentInstanceFactoryDelegate : public ComponentInstanceFactoryDelegate {
37
+
38
+ public:
39
+ using ComponentInstanceFactoryDelegate::ComponentInstanceFactoryDelegate;
40
+
41
+ ComponentInstance::Shared create(ComponentInstance::Context ctx) override {
42
+ if (ctx.componentName == "RTNContextMenu") {
43
+ // RTNContextMenuComponentInstance 这里的方法对应是ComponentInstance.h命名的方法
44
+ return std::make_shared<RTNContextMenuComponentInstance>(std::move(ctx));
45
+ }
46
+ return nullptr;
47
+ }
48
+ };
49
+
50
+ //注册对应的TurboModuleFactoryDelegate,715版本新增。让组件在C化的时候同时进行ArkTs的初始化
51
+ class ContextMenuTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
52
+ public:
53
+ SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
54
+ if (name == "ContextMenuTurboModule") {
55
+ return std::make_shared<ContextMenuTurboModule>(ctx, name);
56
+ }
57
+ return nullptr;
58
+ };
59
+ };
60
+
61
+ class ContextMenuPackage : public Package {
62
+ public:
63
+ ContextMenuPackage(Package::Context ctx) : Package(ctx) {}
64
+
65
+ //创建TurboModuleFactoryDelegate,715版本新增
66
+ std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
67
+ return std::make_unique<ContextMenuTurboModuleFactoryDelegate>();
68
+ }
69
+
70
+ // 创建组件实体类
71
+ ComponentInstanceFactoryDelegate::Shared createComponentInstanceFactoryDelegate() override {
72
+ return std::make_shared<ContextMenuPackageComponentInstanceFactoryDelegate>();
73
+ }
74
+
75
+ std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
76
+ return {
77
+ facebook::react::concreteComponentDescriptorProvider<facebook::react::RTNContextMenuComponentDescriptor>()};
78
+ }
79
+
80
+ ComponentJSIBinderByString createComponentJSIBinderByName() override {
81
+ return {{"RTNContextMenu", std::make_shared<RTNContextMenuJSIBinder>()}};
82
+ }
83
+
84
+ // arkTs2CPP
85
+ std::vector<ArkTSMessageHandler::Shared> createArkTSMessageHandlers() override {
86
+ return {std::make_shared<ScrollLockerArkTSMessageHandler>()};
87
+ }
88
+
89
+ // 使用handleArkTSMessage接收消息,这里用来接收来自arkTs的消息
90
+ class ScrollLockerArkTSMessageHandler : public ArkTSMessageHandler {
91
+ public:
92
+ void handleArkTSMessage(const Context &ctx) override {
93
+ if (ctx.messageName == "contextMenu::onCancel") {
94
+ LOG(INFO) << "ContextMenuPackage:handleArkTSMessage--onCancel";
95
+ auto itemTag = ctx.messagePayload["itemTag"].asInt();
96
+ auto rnInstance = ctx.rnInstance.lock();
97
+ auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
98
+ auto contextInstance = rnInstanceCAPI->findComponentInstanceByTag(itemTag);
99
+ if (contextInstance) {
100
+ auto rnContextInstance =
101
+ std::dynamic_pointer_cast<RTNContextMenuComponentInstance>(contextInstance);
102
+ if (rnContextInstance) {
103
+ rnContextInstance->onCancel();
104
+ rnInstance->postMessageToArkTS("RNGH::CLOSE_MENU", NULL);
105
+ }
106
+ }
107
+ }
108
+
109
+ if (ctx.messageName == "contextMenu::SET_NATIVE_RESPONDERS_BLOCK") {
110
+ LOG(INFO) << "contextMenu:handleArkTSMessage--SET_NATIVE_RESPONDERS_BLOCK";
111
+ auto itemTag = ctx.messagePayload["itemTag"].asInt();
112
+ auto itemTitle = ctx.messagePayload["itemTitle"].asString();
113
+ auto itemIndex = ctx.messagePayload["itemIndex"].asInt();
114
+ auto itemIndexPath = ctx.messagePayload["itemIndexPath"];
115
+ auto itemInlineChildren = ctx.messagePayload["itemInlineChildren"].asBool();
116
+ // 数据转换,将dynamic类型转成std::vector<int>
117
+ std::vector<int> onPressIndexPath;
118
+ for (size_t i = 0; i < itemIndexPath.size() - 1; i++) {
119
+ onPressIndexPath.push_back(i);
120
+ }
121
+ auto rnInstance = ctx.rnInstance.lock();
122
+ auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
123
+ auto contextInstance = rnInstanceCAPI->findComponentInstanceByTag(itemTag);
124
+ LOG(INFO) << "ContextMenuPackage:ContextMenuPackage的方法---------ArkTSMessageHandler---contextInstance:"
125
+ << contextInstance;
126
+ if (contextInstance) {
127
+ auto rnContextInstance =
128
+ std::dynamic_pointer_cast<RTNContextMenuComponentInstance>(contextInstance);
129
+ if (rnContextInstance) {
130
+ rnContextInstance->onClick(itemIndex, onPressIndexPath, itemTitle);
131
+ // 发送消息到arkTS侧,提醒arkTS关闭当前弹框
132
+ // rnInstance->postMessageToArkTS("RNGH::CLOSE_MENU", NULL);
133
+ }
134
+ }
135
+ }
136
+ };
137
+ };
138
+ };
139
+
140
+ } // namespace rnoh
@@ -0,0 +1,36 @@
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
+ #include "ContextMenuTurboModule.h"
26
+ #include "RNOH/ArkTSTurboModule.h"
27
+ #include "RNOH/RNInstance.h"
28
+
29
+ using namespace facebook;
30
+ using namespace react;
31
+
32
+ namespace rnoh {
33
+ // 在715环境上,因为连接ArkTs的通道模式修改,需要在C侧注册对应的TurboModule
34
+ ContextMenuTurboModule::ContextMenuTurboModule(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
35
+ } // namespace rnoh
36
+ }
@@ -0,0 +1,38 @@
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
+ #pragma once
26
+
27
+ #include <ReactCommon/TurboModule.h>
28
+ #include "RNOH/ArkTSTurboModule.h"
29
+
30
+ using namespace facebook;
31
+ namespace rnoh {
32
+ class JSI_EXPORT ContextMenuTurboModule : public ArkTSTurboModule {
33
+ public:
34
+ //在715环境上,因为连接ArkTs的通道模式修改,需要在C侧注册对应的TurboModule
35
+ ContextMenuTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
36
+ };
37
+ } // namespace rnoh
38
+
@@ -0,0 +1,49 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ #include "EventEmitters.h"
8
+
9
+ namespace facebook {
10
+ namespace react {
11
+
12
+ void RTNContextMenuEventEmitter::onPress(OnPress event) const {
13
+ dispatchEvent("press", [event = std::move(event)](jsi::Runtime &runtime) {
14
+ auto payload = jsi::Object(runtime);
15
+ payload.setProperty(runtime, "index", event.index);
16
+
17
+ auto indexPath = jsi::Array(runtime, event.indexPath.size());
18
+ size_t indexPathIndex = 0;
19
+ for (auto indexPathValue : event.indexPath) {
20
+ indexPath.setValueAtIndex(runtime, indexPathIndex++, indexPathValue);
21
+ }
22
+ payload.setProperty(runtime, "indexPath", indexPath);
23
+ payload.setProperty(runtime, "name", event.name);
24
+ return payload;
25
+ });
26
+ }
27
+ void RTNContextMenuEventEmitter::onPreviewPress(OnPreviewPress event) const {
28
+ dispatchEvent("previewPress", [](jsi::Runtime &runtime) {
29
+ auto payload = jsi::Object(runtime);
30
+
31
+ return payload;
32
+ });
33
+ }
34
+ void RTNContextMenuEventEmitter::onCancel(OnCancel event) const {
35
+ dispatchEvent("cancel", [](jsi::Runtime &runtime) {
36
+ auto payload = jsi::Object(runtime);
37
+ return payload;
38
+ });
39
+ }
40
+
41
+ void RTNContextMenuEventEmitter::onContextMenuClick() const {
42
+ dispatchEvent("onContextMenuClick", [](jsi::Runtime &runtime) {
43
+ auto payload = jsi::Object(runtime);
44
+ return payload;
45
+ });
46
+ }
47
+
48
+ } // namespace react
49
+ } // namespace facebook
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ #pragma once
8
+
9
+ #include <react/renderer/components/view/ViewEventEmitter.h>
10
+ #include <jsi/jsi.h>
11
+
12
+ namespace facebook {
13
+ namespace react {
14
+
15
+ class JSI_EXPORT RTNContextMenuEventEmitter : public ViewEventEmitter {
16
+ public:
17
+ using ViewEventEmitter::ViewEventEmitter;
18
+
19
+ // 属性
20
+ struct OnPress {
21
+ int index;
22
+ std::vector<int> indexPath;
23
+ std::string name;
24
+ };
25
+
26
+ struct OnPreviewPress {};
27
+
28
+ struct OnCancel {};
29
+
30
+ // 方法
31
+ void onContextMenuClick() const;
32
+
33
+ void onPress(OnPress value) const;
34
+
35
+ void onPreviewPress(OnPreviewPress value) const;
36
+
37
+ void onCancel(OnCancel value) const;
38
+ };
39
+
40
+ } // namespace react
41
+ } // namespace facebook
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ #include "Props.h"
8
+ #include <react/renderer/core/PropsParserContext.h>
9
+ #include <react/renderer/core/propsConversions.h>
10
+
11
+ namespace facebook {
12
+ namespace react {
13
+
14
+ RTNContextMenuProps::RTNContextMenuProps(const PropsParserContext &context, const RTNContextMenuProps &sourceProps,
15
+ const RawProps &rawProps)
16
+ : ViewProps(context, sourceProps, rawProps),
17
+
18
+ title(convertRawProp(context, rawProps, "title", sourceProps.title, {})),
19
+ actions(convertRawProp(context, rawProps, "actions", sourceProps.actions, {})),
20
+ previewBackgroundColor(
21
+ convertRawProp(context, rawProps, "previewBackgroundColor", sourceProps.previewBackgroundColor, {})),
22
+ dropdownMenuMode(convertRawProp(context, rawProps, "dropdownMenuMode", sourceProps.dropdownMenuMode, {false})),
23
+ disabled(convertRawProp(context, rawProps, "disabled", sourceProps.disabled, {false})),
24
+ subtitle(convertRawProp(context, rawProps, "subtitle", sourceProps.subtitle, {})),
25
+ systemIcon(convertRawProp(context, rawProps, "systemIcon", sourceProps.systemIcon, {})),
26
+ icon(convertRawProp(context, rawProps, "icon", sourceProps.icon, {})),
27
+ iconColor(convertRawProp(context, rawProps, "iconColor", sourceProps.iconColor, {})),
28
+ destructive(convertRawProp(context, rawProps, "destructive", sourceProps.destructive, {false})),
29
+ selected(convertRawProp(context, rawProps, "selected", sourceProps.selected, {false})),
30
+ inlineChildren(convertRawProp(context, rawProps, "inlineChildren", sourceProps.inlineChildren, {false})),
31
+ fontName(convertRawProp(context, rawProps, "fontName", sourceProps.fontName, {})) {}
32
+
33
+ } // namespace react
34
+ } // namespace facebook