react-native-idosdk 1.0.4 → 1.0.5

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 (27) hide show
  1. package/README.md +3 -1
  2. package/package.json +4 -1
  3. package/react-native-harmony-ido/README.md +264 -0
  4. package/react-native-harmony-ido/gt-ido-ohos-plugin-1.0.0.tgz +0 -0
  5. package/react-native-harmony-ido/harmony/BuildProfile.ets +17 -0
  6. package/react-native-harmony-ido/harmony/IdoOhosSdk.har +0 -0
  7. package/react-native-harmony-ido/harmony/Index.ets +1 -0
  8. package/react-native-harmony-ido/harmony/build-profile.json5 +36 -0
  9. package/react-native-harmony-ido/harmony/consumer-rules.txt +0 -0
  10. package/react-native-harmony-ido/harmony/hvigorfile.ts +6 -0
  11. package/react-native-harmony-ido/harmony/libs/getui_ido_1.0.1.har +0 -0
  12. package/react-native-harmony-ido/harmony/obfuscation-rules.txt +23 -0
  13. package/react-native-harmony-ido/harmony/oh-package-lock.json5 +38 -0
  14. package/react-native-harmony-ido/harmony/oh-package.json5 +12 -0
  15. package/react-native-harmony-ido/harmony/src/main/cpp/CMakeLists.txt +7 -0
  16. package/react-native-harmony-ido/harmony/src/main/cpp/IdoModule.cpp +38 -0
  17. package/react-native-harmony-ido/harmony/src/main/cpp/IdoModule.h +21 -0
  18. package/react-native-harmony-ido/harmony/src/main/cpp/IdoPackage.h +76 -0
  19. package/react-native-harmony-ido/harmony/src/main/ets/IdoModule.ets +150 -0
  20. package/react-native-harmony-ido/harmony/src/main/ets/IdoPackage.ets +24 -0
  21. package/react-native-harmony-ido/harmony/src/main/module.json5 +9 -0
  22. package/react-native-harmony-ido/harmony/src/main/resources/base/element/float.json +8 -0
  23. package/react-native-harmony-ido/harmony/src/main/resources/base/element/string.json +8 -0
  24. package/react-native-harmony-ido/harmony/ts.ets +2 -0
  25. package/react-native-harmony-ido/index.ts +4 -0
  26. package/react-native-harmony-ido/package.json +35 -0
  27. package/react-native-harmony-ido/src/specs/v1/NativeIdo.ts +44 -0
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  1. React Native Version
9
9
  "react": "18.3.1"
10
10
  "react-native": "0.75.4"
11
- 2. 当前react-native-idosdk版本 1.0.4
11
+ 2. 当前react-native-idosdk版本 1.0.5
12
12
 
13
13
 
14
14
  # 1.安装
@@ -97,7 +97,9 @@ pod install
97
97
  android 与 ios 有部分API不同, 查看插件的index.js 或 index.d.ts中API的注释
98
98
 
99
99
 
100
+ ## 2.3 ohos
100
101
 
102
+ [鸿蒙文档](react-native-harmony-ido/README.md)
101
103
 
102
104
  ## 3.iOS注意事项
103
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-idosdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Getui ido sdk plugin for react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -51,5 +51,8 @@
51
51
  }
52
52
  },
53
53
  "dependencies": {
54
+ },
55
+ "devDependencies": {
56
+ "@react-native-community/cli": "^20.0.2"
54
57
  }
55
58
  }
@@ -0,0 +1,264 @@
1
+ [Github 地址]()
2
+
3
+ ## 安装与使用
4
+ * 下载鸿蒙插件工程[gt-ido-ohos-plugin-1.0.0.tgz](gt-ido-ohos-plugin-1.0.0.tgz)
5
+ * 将gt-ido-ohos-plugin-1.0.0.tgz放到RN工程下
6
+ * 安装 , 如:npm install file:gt-ido-ohos-plugin/gt-ido-ohos-plugin-1.0.0.tgz
7
+
8
+
9
+ 下面的代码展示了这个库的基本使用场景:
10
+ 完成代码参考[App.tsx](../example/OhosDemo/App.tsx)
11
+
12
+ > [!WARNING] 使用时 import 的库名不变。
13
+
14
+ ```js
15
+ import { GetuiIdo } from "gt-ido-ohos-plugin";
16
+ //....省略
17
+ function App(): React.JSX.Element {
18
+ const isDarkMode = useColorScheme() === 'dark';
19
+ const [gtcid, setGtcid] = useState<string | null>(null); // 存储 gtcid
20
+ const [version, setVersion] = useState<string>('未知'); // 存储版本号
21
+
22
+ // 初始化运营工具
23
+ const initIdo = () => {
24
+ try {
25
+ // 获取版本号
26
+ GetuiIdo.version((ver: string) => {
27
+ setVersion(ver);
28
+ });
29
+
30
+ const appId = 'djYjSlFVMf6p5YOy2OQUs8';
31
+ const channel = 'rn';
32
+ GetuiIdo.setDebugEnable(true)
33
+
34
+ GetuiIdo.startSdk(appId, channel);
35
+
36
+ setTimeout((): void => {
37
+ // 获取 gtcid
38
+ GetuiIdo.gtcid((id: string) => {
39
+ Alert.alert('成功', '运营工具初始化成功 \n '+id);
40
+ setGtcid(id);
41
+ });
42
+ }, 1000);
43
+
44
+ // 开启调试模式(可选)
45
+ GetuiIdo.setDebugEnable(true);
46
+ // 设置其他可选配置(根据需求调整,时间单位为毫秒)
47
+ GetuiIdo.setSessionTime(30000); // 设置会话时间(毫秒)
48
+ GetuiIdo.setMinAppActiveDuration(60000); // 设置最小活跃时长(毫秒)
49
+ GetuiIdo.setMaxAppActiveDuration(3600000); // 设置最大活跃时长(毫秒)
50
+ GetuiIdo.setEventUploadInterval(300000); // 设置事件上传间隔(毫秒)
51
+ GetuiIdo.setEventForceUploadSize(50); // 设置强制上传事件数量
52
+ GetuiIdo.setProfileUploadInterval(600000); // 设置用户画像上传间隔(毫秒)
53
+ GetuiIdo.setProfileForceUploadSize(20); // 设置用户画像强制上传数量
54
+
55
+ const profiles = {
56
+ "userId": 123,
57
+ "name": "Alice",
58
+ "isActive": true
59
+ };
60
+
61
+ GetuiIdo.setProfile(profiles, "sss");
62
+ } catch (error) {
63
+ Alert.alert('错误', '初始化运营工具失败: ' + error);
64
+ }
65
+ };
66
+ const trackCountEvent = () =>{
67
+ const profiles = {
68
+ "userId": 123,
69
+ "name": "Alice",
70
+ "isActive": true
71
+ };
72
+
73
+ GetuiIdo.trackCountEvent("123",profiles,"ss");
74
+ };
75
+ );
76
+ }
77
+ //....省略
78
+ export default App;
79
+
80
+ ```
81
+
82
+ ## Link
83
+
84
+ 目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。
85
+
86
+ 首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`
87
+
88
+ ### 1.在工程根目录的 `oh-package.json5` 添加 overrides 字段
89
+
90
+ ```json
91
+ {
92
+ ...
93
+ "overrides": {
94
+ "@rnoh/react-native-openharmony" : "./react_native_openharmony"
95
+ }
96
+ }
97
+ ```
98
+
99
+ ### 2.引入原生端代码
100
+
101
+ > [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。
102
+
103
+ 打开 `entry/oh-package.json5`,添加以下依赖
104
+
105
+ ```json
106
+ "dependencies": {
107
+ "@rnoh/react-native-openharmony": "0.72.90",
108
+ "IdoOhosSdk": "file:../../node_modules/gt-ido-ohos-plugin/IdoOhosSdk/IdoOhosSdk.har"
109
+ }
110
+ ```
111
+ 点击右上角的 `sync` 按钮
112
+
113
+
114
+ ### 3.配置 CMakeLists 和引入 IdoPackage
115
+
116
+ 打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
117
+
118
+ ```diff
119
+ project(rnapp)
120
+ cmake_minimum_required(VERSION 3.4.1)
121
+ set(CMAKE_SKIP_BUILD_RPATH TRUE)
122
+ set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
123
+ set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
124
+
125
+ set(RNOH_CPP_DIR "${OH_MODULE_DIR}/@rnoh/react-native-openharmony/src/main/cpp")
126
+ set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated")
127
+ set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
128
+ set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
129
+ add_compile_definitions(WITH_HITRACE_SYSTRACE)
130
+ set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
131
+
132
+ add_subdirectory("${RNOH_CPP_DIR}" ./rn)
133
+ add_subdirectory("${OH_MODULE_DIR}/IdoOhosSdk/src/main/cpp" ./ido)
134
+
135
+ add_library(rnoh_app SHARED
136
+ "./PackageProvider.cpp"
137
+ "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
138
+ )
139
+
140
+ target_link_libraries(rnoh_app PUBLIC rnoh)
141
+ target_link_libraries(rnoh_app PUBLIC rnoh_ido)
142
+ ```
143
+
144
+ 打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
145
+
146
+ ```diff
147
+ #include "RNOH/PackageProvider.h"
148
+ #include "IdoPackage.h"
149
+
150
+ using namespace rnoh;
151
+ std::vector<std::shared_ptr<Package>>
152
+ PackageProvider::getPackages(Package::Context ctx) {
153
+ return {
154
+ std::make_shared<IdoPackage>(ctx)
155
+ };
156
+ }
157
+ ```
158
+
159
+ ### 4.在 ArkTs 侧引入 NetInfoPackage
160
+
161
+ 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
162
+
163
+ ```diff
164
+ import { RNPackageContext, RNPackage } from '@rnoh/react-native-openharmony/ts';
165
+ import { IdoPackage } from 'IdoOhosSdk/ts';
166
+
167
+ export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
168
+ return [
169
+ new IdoPackage(ctx),
170
+ ];
171
+ }
172
+ ```
173
+
174
+ ### 5.配置appid参数
175
+
176
+ 打开 `entry/src/main/module.json5`,添加:
177
+
178
+ ```diff
179
+ "metadata": [
180
+ {
181
+ "name": "GETUI_APPID",
182
+ "value": "djYjSlFVMf6p5YOy2OQUs8"//你的APPID个推官网申请
183
+ },
184
+
185
+ ],
186
+ "requestPermissions": [
187
+ {
188
+ "name": "ohos.permission.INTERNET"
189
+ },
190
+ {
191
+ "name": "ohos.permission.GET_NETWORK_INFO"
192
+ },
193
+ {
194
+ "name": "ohos.permission.GET_WIFI_INFO"
195
+ },
196
+ {
197
+ "name": "ohos.permission.APP_TRACKING_CONSENT",
198
+ "reason" : "$string:oaid_reason",
199
+ "usedScene": {
200
+ "when": "always"
201
+ }
202
+ }
203
+ ]
204
+ ```
205
+
206
+ ### 6.运行
207
+
208
+ 点击右上角的 `sync` 按钮
209
+
210
+ 或者在终端执行:
211
+
212
+ ```bash
213
+ cd entry
214
+ ohpm install
215
+ ```
216
+
217
+ 然后编译、运行即可。
218
+
219
+ ## 约束与限制
220
+
221
+ ## 兼容性
222
+
223
+ 要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
224
+
225
+
226
+ ## 方法
227
+
228
+ ```ts
229
+ export interface Spec extends TurboModule {
230
+
231
+ startSdk(appid: string, channel: string): void;
232
+
233
+ gtcid(cb: (param: string) => void): void;
234
+
235
+ version(cb: (param: string) => void): void;
236
+
237
+ setDebugEnable(isEnable: boolean): void;
238
+
239
+ setSessionTime(time: number): void;
240
+
241
+ setMinAppActiveDuration(val: number): void;
242
+
243
+ setMaxAppActiveDuration(val: number): void;
244
+
245
+ setEventUploadInterval(val: number): void;
246
+
247
+ setEventForceUploadSize(val: number): void;
248
+
249
+ setProfileUploadInterval(val: number): void;
250
+
251
+ setProfileForceUploadSize(val: number): void;
252
+
253
+ setUserId(val: string): void;
254
+
255
+ trackCustomKeyValueEventBegin(eventId: string): void;
256
+
257
+ trackCustomKeyValueEventEnd(eventId: string, args:{[key: string]: string|number|boolean}, ext: string): void;
258
+
259
+ trackCountEvent(eventId: string, args:{[key: string]: string|number|boolean}, ext: string): void;
260
+
261
+ setProfile(profiles: {[key: string]: string|number|boolean}, ext: string): void;
262
+
263
+ }
264
+ ```
@@ -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.0.0';
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 @@
1
+ export * from './ts'
@@ -0,0 +1,36 @@
1
+ {
2
+ "apiType": "stageMode",
3
+ "buildOption": {
4
+ "resOptions": {
5
+ "copyCodeResource": {
6
+ "enable": false
7
+ }
8
+ }
9
+ },
10
+ "buildOptionSet": [
11
+ {
12
+ "name": "release",
13
+ "arkOptions": {
14
+ "obfuscation": {
15
+ "ruleOptions": {
16
+ "enable": false,
17
+ "files": [
18
+ "./obfuscation-rules.txt"
19
+ ]
20
+ },
21
+ "consumerFiles": [
22
+ "./consumer-rules.txt"
23
+ ]
24
+ }
25
+ },
26
+ },
27
+ ],
28
+ "targets": [
29
+ {
30
+ "name": "default"
31
+ },
32
+ {
33
+ "name": "ohosTest"
34
+ }
35
+ ]
36
+ }
@@ -0,0 +1,6 @@
1
+ import { harTasks } from '@ohos/hvigor-ohos-plugin';
2
+
3
+ export default {
4
+ system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
5
+ plugins: [] /* Custom plugin to extend the functionality of Hvigor. */
6
+ }
@@ -0,0 +1,23 @@
1
+ # Define project specific obfuscation rules here.
2
+ # You can include the obfuscation configuration files in the current module's build-profile.json5.
3
+ #
4
+ # For more details, see
5
+ # https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5
6
+
7
+ # Obfuscation options:
8
+ # -disable-obfuscation: disable all obfuscations
9
+ # -enable-property-obfuscation: obfuscate the property names
10
+ # -enable-toplevel-obfuscation: obfuscate the names in the global scope
11
+ # -compact: remove unnecessary blank spaces and all line feeds
12
+ # -remove-log: remove all console.* statements
13
+ # -print-namecache: print the name cache that contains the mapping from the old names to new names
14
+ # -apply-namecache: reuse the given cache file
15
+
16
+ # Keep options:
17
+ # -keep-property-name: specifies property names that you want to keep
18
+ # -keep-global-name: specifies names that you want to keep in the global scope
19
+
20
+ -enable-property-obfuscation
21
+ -enable-toplevel-obfuscation
22
+ -enable-filename-obfuscation
23
+ -enable-export-obfuscation
@@ -0,0 +1,38 @@
1
+ {
2
+ "meta": {
3
+ "stableOrder": true,
4
+ "enableUnifiedLockfile": false
5
+ },
6
+ "lockfileVersion": 3,
7
+ "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
8
+ "specifiers": {
9
+ "@getui/gtc@../oh_modules/.ohpm/@getui+ido@zkoyyirssaxz8gef8vqhhop3efu+q3r1jbt0qr5k6hs=/oh_modules/@getui/ido/libs/GTC-HM-1.0.5.har": "@getui/gtc@../oh_modules/.ohpm/@getui+ido@zkoyyirssaxz8gef8vqhhop3efu+q3r1jbt0qr5k6hs=/oh_modules/@getui/ido/libs/GTC-HM-1.0.5.har",
10
+ "@getui/ido@libs/getui_ido_1.0.1.har": "@getui/ido@libs/getui_ido_1.0.1.har",
11
+ "@rnoh/react-native-openharmony@0.72.90": "@rnoh/react-native-openharmony@0.72.90"
12
+ },
13
+ "packages": {
14
+ "@getui/gtc@../oh_modules/.ohpm/@getui+ido@zkoyyirssaxz8gef8vqhhop3efu+q3r1jbt0qr5k6hs=/oh_modules/@getui/ido/libs/GTC-HM-1.0.5.har": {
15
+ "name": "@getui/gtc",
16
+ "version": "1.0.5",
17
+ "resolved": "../oh_modules/.ohpm/@getui+ido@zkoyyirssaxz8gef8vqhhop3efu+q3r1jbt0qr5k6hs=/oh_modules/@getui/ido/libs/GTC-HM-1.0.5.har",
18
+ "registryType": "local"
19
+ },
20
+ "@getui/ido@libs/getui_ido_1.0.1.har": {
21
+ "name": "",
22
+ "version": "1.0.1",
23
+ "integrity": "",
24
+ "resolved": "",
25
+ "registryType": "local",
26
+ "dependencies": {
27
+ "@getui/gtc": "file:./libs/GTC-HM-1.0.5.har"
28
+ }
29
+ },
30
+ "@rnoh/react-native-openharmony@0.72.90": {
31
+ "name": "",
32
+ "version": "0.72.90",
33
+ "integrity": "sha512-15mpPRjzAWad/qTzQasUmKEvQi+FVnrjnduxam7YjOMI8+NNGuF5Srx0B/71KX3hyQTROUlwnUWUdMhfsQ/olw==",
34
+ "resolved": "https://repo.harmonyos.com/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.90.har",
35
+ "registryType": "ohpm"
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "IdoOhosSdk",
3
+ "version": "1.0.0",
4
+ "description": "Please describe the basic information.",
5
+ "main": "Index.ets",
6
+ "author": "",
7
+ "license": "Apache-2.0",
8
+ "dependencies": {
9
+ "@rnoh/react-native-openharmony": "0.72.90",
10
+ "@getui/ido": "file:./libs/getui_ido_1.0.1.har"
11
+ }
12
+ }
@@ -0,0 +1,7 @@
1
+ cmake_minimum_required(VERSION 3.4.1)
2
+ set(CMAKE_VERBOSE_MAKEFILE on)
3
+
4
+ file(GLOB rnoh_ido_SRC CONFIGURE_DEPENDS *.cpp)
5
+ add_library(rnoh_ido SHARED ${rnoh_ido_SRC})
6
+ target_include_directories(rnoh_ido PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
7
+ target_link_libraries(rnoh_ido PUBLIC rnoh)
@@ -0,0 +1,38 @@
1
+ /**
2
+ * This code was generated by "react-native codegen-harmony"
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be
5
+ * lost once the code is regenerated.
6
+ *
7
+ * @generatorVersion: 1
8
+ */
9
+
10
+
11
+ #include "IdoModule.h"
12
+
13
+ namespace rnoh {
14
+ using namespace facebook;
15
+
16
+ IdoModule::IdoModule(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
17
+ methodMap_ = {
18
+ ARK_METHOD_METADATA(startSdk, 2),
19
+ ARK_METHOD_METADATA(gtcid, 1),
20
+ ARK_METHOD_METADATA(version, 1),
21
+ ARK_METHOD_METADATA(setDebugEnable, 1),
22
+ ARK_METHOD_METADATA(setSessionTime, 1),
23
+ ARK_METHOD_METADATA(setMinAppActiveDuration, 1),
24
+ ARK_METHOD_METADATA(setMaxAppActiveDuration, 1),
25
+ ARK_METHOD_METADATA(setEventUploadInterval, 1),
26
+ ARK_METHOD_METADATA(setEventForceUploadSize, 1),
27
+ ARK_METHOD_METADATA(setProfileUploadInterval, 1),
28
+ ARK_METHOD_METADATA(setProfileForceUploadSize, 1),
29
+ ARK_METHOD_METADATA(setUserId, 1),
30
+ ARK_METHOD_METADATA(trackCustomKeyValueEventBegin, 1),
31
+ ARK_METHOD_METADATA(trackCustomKeyValueEventEnd, 3),
32
+ ARK_METHOD_METADATA(trackCountEvent, 3),
33
+ ARK_METHOD_METADATA(setProfile, 2),
34
+ };
35
+ }
36
+
37
+ } // namespace rnoh
38
+
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This code was generated by "react-native codegen-harmony"
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be
5
+ * lost once the code is regenerated.
6
+ *
7
+ * @generatorVersion: 1
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include "RNOH/ArkTSTurboModule.h"
13
+
14
+ namespace rnoh {
15
+
16
+ class JSI_EXPORT IdoModule : public ArkTSTurboModule {
17
+ public:
18
+ IdoModule(const ArkTSTurboModule::Context ctx, const std::string name);
19
+ };
20
+
21
+ } // namespace rnoh
@@ -0,0 +1,76 @@
1
+ /**
2
+ * This code was generated by "react-native codegen-harmony"
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be
5
+ * lost once the code is regenerated.
6
+ *
7
+ * @generatorVersion: 1
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include "RNOH/Package.h"
13
+ #include "RNOH/ArkTSTurboModule.h"
14
+ #include "IdoModule.h"
15
+
16
+ namespace rnoh {
17
+
18
+ class IdoPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
19
+ public:
20
+ SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
21
+ if (name == "IdoModule") {
22
+ return std::make_shared<IdoModule>(ctx, name);
23
+ }
24
+ return nullptr;
25
+ };
26
+ };
27
+
28
+ class GeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
29
+ public:
30
+ void handleEvent(Context const &ctx) override {
31
+ auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
32
+ auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
33
+
34
+ if (eventEmitter == nullptr) {
35
+ return;
36
+ }
37
+
38
+ std::vector<std::string> supportedComponentNames = {
39
+ };
40
+
41
+ std::vector<std::string> supportedEventNames = {
42
+ };
43
+
44
+ if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
45
+ std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
46
+ eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
47
+ }
48
+ }
49
+ };
50
+
51
+ class IdoPackage : public Package {
52
+ public:
53
+ IdoPackage(Package::Context ctx) : Package(ctx){};
54
+
55
+ std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
56
+ return std::make_unique<IdoPackageTurboModuleFactoryDelegate>();
57
+ }
58
+
59
+ std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
60
+ return {
61
+ };
62
+ }
63
+
64
+ ComponentJSIBinderByString createComponentJSIBinderByName() override {
65
+ return {
66
+ };
67
+ };
68
+
69
+ EventEmitRequestHandlers createEventEmitRequestHandlers() override {
70
+ return {
71
+ std::make_shared<GeneratedEventEmitRequestHandler>(),
72
+ };
73
+ }
74
+ };
75
+
76
+ } // namespace rnoh
@@ -0,0 +1,150 @@
1
+ // entry/src/main/ets/turbomodule/CalculatorModule.ts
2
+ import { AnyThreadTurboModule, UITurboModule } from '@rnoh/react-native-openharmony/ts';
3
+ import {Ido, IdoConfig} from "@getui/ido"
4
+ import { common } from '@kit.AbilityKit';
5
+ import { RNOHContext, UITurboModuleContext } from '@rnoh/react-native-openharmony/src/main/ets/RNOH/ts';
6
+ import hilog from '@ohos.hilog';
7
+
8
+ export class IdoModule extends UITurboModule{
9
+ protected _context: common.UIAbilityContext;
10
+ protected _RnContext: RNOHContext;
11
+ protected gtcId: string = '';
12
+
13
+ constructor(ctx: UITurboModuleContext) {
14
+ super(ctx);
15
+ this._context = ctx?.uiAbilityContext;
16
+ this._RnContext = ctx;
17
+ }
18
+ version(cb: (param: string) => void): void{
19
+ cb(Ido.getVersion())
20
+ }
21
+
22
+ startSdk(appid: string, channel: string): void{
23
+ IdoConfig.setAppId(appid)
24
+ IdoConfig.setChannel(channel)
25
+ Ido.preInit(this._context)
26
+ Ido.init(this._context).then((gtcId) => {
27
+ this. gtcId = gtcId
28
+ hilog.info(0x0000, 'IdoModule', 'IDO init Succeeded. GtcId: (%{public}s)', gtcId);
29
+ })
30
+ }
31
+
32
+ gtcid(cb: (param: string) => void): void{
33
+ cb(this.gtcId)
34
+ }
35
+
36
+ setDebugEnable(isEnable: boolean): void{
37
+ IdoConfig.setDebugEnable(isEnable)
38
+ // IdoConfig.setDebugEnable(6)
39
+ hilog.info(0x0000, 'IdoModule', `setDebugEnable ${isEnable}`);
40
+ }
41
+
42
+ setSessionTime(time: number): void{
43
+ IdoConfig.setSessionTimeoutMillis(time)
44
+ }
45
+
46
+ setMinAppActiveDuration(val: number): void{
47
+ IdoConfig.setMinAppActiveDuration(val)
48
+ }
49
+
50
+ setMaxAppActiveDuration(val: number): void{
51
+ IdoConfig.setMaxAppActiveDuration(val)
52
+ }
53
+
54
+ setEventUploadInterval(val: number): void{
55
+ IdoConfig.setEventUploadInterval(val)
56
+ }
57
+
58
+ setEventForceUploadSize(val: number): void{
59
+ IdoConfig.setEventForceUploadSize(val)
60
+ }
61
+
62
+ setProfileUploadInterval(val: number): void{
63
+ IdoConfig.setProfileUploadInterval(val)
64
+ }
65
+
66
+ setProfileForceUploadSize(val: number): void{
67
+ IdoConfig.setProfileForceUploadSize(val)
68
+ }
69
+
70
+ setUserId(val: string): void{
71
+ Ido.setUserId(val)
72
+ }
73
+
74
+ trackCustomKeyValueEventBegin(eventId: string): void{
75
+ Ido.onBeginEvent(eventId)
76
+ }
77
+
78
+ trackCustomKeyValueEventEnd(eventId: string, args: Object, ext: string): void{
79
+
80
+ // 转换前打印原始对象
81
+ hilog.info(0x0000, 'IdoModule', `trackCustomKeyValueEventEnd ${JSON.stringify(args, null, 2)}`);
82
+ // 将 Object 转换为 Map
83
+ const profileMap: Map<string, string | number | Date | boolean> = new Map(
84
+ Object.entries(args).map((entry:[string,object]) => {
85
+ const key = entry[0] as string; // 显式类型断言
86
+ const value = entry[1] as string | number | Date | boolean;
87
+ return [key, value];
88
+ })
89
+ );
90
+
91
+
92
+ // 转换后打印 Map 内容
93
+
94
+ hilog.info(0x0000, 'IdoModule', '转换后的 Map 内容:');
95
+ profileMap.forEach((value, key) => {
96
+ hilog.info(0x0000, 'IdoModule',`Key: ${key}, Value: ${value} (${typeof value})`);
97
+ });
98
+
99
+ Ido.onEndEvent(eventId,profileMap,ext)
100
+
101
+ }
102
+
103
+ trackCountEvent(eventId: string, args: Object, ext: string): void{
104
+
105
+ // 转换前打印原始对象
106
+ hilog.info(0x0000, 'IdoModule', `trackCountEvent ${JSON.stringify(args, null, 2)}`);
107
+ // 将 Object 转换为 Map
108
+ const profileMap: Map<string, string | number | Date | boolean> = new Map(
109
+ Object.entries(args).map((entry:[string,object]) => {
110
+ const key = entry[0] as string; // 显式类型断言
111
+ const value = entry[1] as string | number | Date | boolean;
112
+ return [key, value];
113
+ })
114
+ );
115
+
116
+ // 转换后打印 Map 内容
117
+ hilog.info(0x0000, 'IdoModule', '转换后的 Map 内容:');
118
+ profileMap.forEach((value, key) => {
119
+ hilog.info(0x0000, 'IdoModule',`Key: ${key}, Value: ${value} (${typeof value})`);
120
+ });
121
+
122
+ Ido.onEvent(eventId,profileMap,ext)
123
+ }
124
+
125
+ setProfile(profiles: Object, ext: string): void{
126
+ // 转换前打印原始对象
127
+ hilog.info(0x0000, 'IdoModule', `setProfile ${JSON.stringify(profiles, null, 2)}`);
128
+
129
+ // 将 Object 转换为 Map
130
+ const profileMap: Map<string, string | number | Date | boolean> = new Map(
131
+ Object.entries(profiles).map((entry:[string,object]) => {
132
+ const key = entry[0] as string; // 显式类型断言
133
+ const value = entry[1] as string | number | Date | boolean;
134
+ return [key, value];
135
+ })
136
+ );
137
+
138
+ // 转换后打印 Map 内容
139
+ hilog.info(0x0000, 'IdoModule', '转换后的 Map 内容:');
140
+ profileMap.forEach((value, key) => {
141
+ hilog.info(0x0000, 'IdoModule',`Key: ${key}, Value: ${value} (${typeof value})`);
142
+ });
143
+
144
+
145
+ // 调用原方法
146
+ Ido.onProfile(profileMap, ext);
147
+ }
148
+
149
+ }
150
+
@@ -0,0 +1,24 @@
1
+ // entry/src/main/ets/GeneratedPackage.ets
2
+ import {
3
+ RNOHPackage,
4
+ AnyThreadTurboModule,
5
+ AnyThreadTurboModuleContext,
6
+ UITurboModule,
7
+ UITurboModuleContext
8
+ } from '@rnoh/react-native-openharmony';
9
+
10
+ import { IdoModule } from './IdoModule';
11
+
12
+ export class IdoPackage extends RNOHPackage {
13
+ override getUITurboModuleFactoryByNameMap(): Map<string, (ctx: UITurboModuleContext) => UITurboModule | null> {
14
+ return new Map<string, ((ctx: UITurboModuleContext) => UITurboModule)>()
15
+ .set("IdoModule", (ctx) => new IdoModule(ctx))
16
+ }
17
+
18
+
19
+ override async createEagerUITurboModuleByNameMap(ctx: UITurboModuleContext): Promise<Map<string, UITurboModule>> {
20
+ const calculatorModule = new IdoModule(ctx);
21
+ return new Map()
22
+ .set("IdoModule", calculatorModule)
23
+ }
24
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "module": {
3
+ "name": "IdoOhosSdk",
4
+ "type": "har",
5
+ "deviceTypes": [
6
+ "default"
7
+ ]
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "float": [
3
+ {
4
+ "name": "page_text_font_size",
5
+ "value": "50fp"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from package"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,2 @@
1
+ export * from './src/main/ets/IdoPackage'
2
+ export * from './src/main/ets/IdoModule'
@@ -0,0 +1,4 @@
1
+ // index.ts
2
+ import NativeIdo from "./src/specs/v1/NativeIdo";
3
+
4
+ export const GetuiIdo = NativeIdo;
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "gt-ido-ohos-plugin",
3
+ "version": "1.0.0",
4
+ "description": "Add numbers with TurboModules",
5
+ "main": "index.ts",
6
+ "keywords": [],
7
+ "author": "",
8
+ "license": "ISC",
9
+ "harmony": {
10
+ "alias": "gt-ido-ohos-plugin",
11
+ "codegenConfig": [
12
+ {
13
+ "version": 1,
14
+ "specPaths": [
15
+ "./src/specs/v1"
16
+ ],
17
+ "des": "version:表示版本,需要强调一下,这里的版本并没有新旧之说,它们只是使用场景不同而已。\"version\": 1 适用于创建 TurboModule 或者是 ArkTS 组件的场景;\n\"version\": 2 则适用于创建 CAPI 组件的场景。"
18
+ }
19
+ ]
20
+ },
21
+ "files": [
22
+ "index.ts",
23
+ "src/*",
24
+ "harmony"
25
+ ],
26
+ "peerDependencies": {
27
+ "react": "*",
28
+ "react-native": "*"
29
+ },
30
+ "devDependencies": {
31
+ "@types/react": "^18.2.47",
32
+ "react": "18.2.0",
33
+ "react-native": "0.72.5"
34
+ }
35
+ }
@@ -0,0 +1,44 @@
1
+ // NativeCalculator.ts
2
+ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
3
+ import { TurboModuleRegistry } from 'react-native';
4
+
5
+
6
+ export interface Spec extends TurboModule {
7
+
8
+ startSdk(appid: string, channel: string): void;
9
+
10
+ gtcid(cb: (param: string) => void): void;
11
+
12
+ version(cb: (param: string) => void): void;
13
+
14
+ setDebugEnable(isEnable: boolean): void;
15
+
16
+ setSessionTime(time: number): void;
17
+
18
+ setMinAppActiveDuration(val: number): void;
19
+
20
+ setMaxAppActiveDuration(val: number): void;
21
+
22
+ setEventUploadInterval(val: number): void;
23
+
24
+ setEventForceUploadSize(val: number): void;
25
+
26
+ setProfileUploadInterval(val: number): void;
27
+
28
+ setProfileForceUploadSize(val: number): void;
29
+
30
+ setUserId(val: string): void;
31
+
32
+ trackCustomKeyValueEventBegin(eventId: string): void;
33
+
34
+ trackCustomKeyValueEventEnd(eventId: string, args:{[key: string]: string|number|boolean}, ext: string): void;
35
+
36
+ trackCountEvent(eventId: string, args:{[key: string]: string|number|boolean}, ext: string): void;
37
+
38
+ setProfile(profiles: {[key: string]: string|number|boolean}, ext: string): void;
39
+
40
+ }
41
+
42
+ export default TurboModuleRegistry.get<Spec>(
43
+ 'IdoModule',
44
+ ) as Spec | null;