@react-native-ohos/clipboard 1.16.3-rc.1 → 1.16.3-rc.2
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 +20 -20
- package/README.OpenSource +10 -10
- package/README.md +13 -13
- package/RNCClipboard.podspec +37 -37
- package/harmony/clipboard/LICENSE +20 -20
- package/harmony/clipboard/NOTICE +32 -32
- package/harmony/clipboard/OAT.xml +37 -37
- package/harmony/clipboard/README.OpenSource +10 -10
- package/harmony/clipboard/README.md +307 -307
- package/harmony/clipboard/build-profile.json5 +7 -7
- package/harmony/clipboard/hvigorfile.ts +1 -1
- package/harmony/clipboard/index.ets +24 -24
- package/harmony/clipboard/oh-package.json5 +12 -12
- package/harmony/clipboard/src/main/cpp/CMakeLists.txt +6 -6
- package/harmony/clipboard/src/main/cpp/ClipboardPackage.h +57 -57
- package/harmony/clipboard/src/main/cpp/RNCClipboardTurboModule.cpp +197 -197
- package/harmony/clipboard/src/main/cpp/RNCClipboardTurboModule.h +38 -38
- package/harmony/clipboard/src/main/ets/ClipboardPackage.ts +45 -45
- package/harmony/clipboard/src/main/ets/Logger.ts +63 -63
- package/harmony/clipboard/src/main/ets/RNCClipboardTurboModule.ts +480 -481
- package/harmony/clipboard/src/main/module.json5 +6 -6
- package/harmony/clipboard/src/main/resources/base/element/string.json +7 -7
- package/harmony/clipboard/src/main/resources/en_US/element/string.json +7 -7
- package/harmony/clipboard/src/main/resources/zh_CN/element/string.json +7 -7
- package/harmony/clipboard/ts.ts +25 -25
- package/harmony/clipboard.har +0 -0
- package/package.json +90 -90
- package/src/Clipboard.ts +211 -211
- package/src/index.ts +3 -3
|
@@ -1,307 +1,307 @@
|
|
|
1
|
-
> 模板版本:v0.2.2
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<h1 align="center"> <code>@react-native-clipboard/clipboard</code> </h1>
|
|
5
|
-
</p>
|
|
6
|
-
<p align="center">
|
|
7
|
-
<a href="https://github.com/react-native-clipboard/clipboard">
|
|
8
|
-
<img src="https://img.shields.io/badge/platforms-android%20|%20ios%20|%20macos%20|%20windows%20|%20harmony%20-lightgrey.svg" alt="Supported platforms" />
|
|
9
|
-
</a>
|
|
10
|
-
<a href="https://github.com/react-native-clipboard/clipboard/blob/master/LICENSE">
|
|
11
|
-
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" />
|
|
12
|
-
</a>
|
|
13
|
-
</p>
|
|
14
|
-
|
|
15
|
-
> [!TIP] [Github 地址](https://github.com/react-native-oh-library/clipboard/tree/sig)
|
|
16
|
-
|
|
17
|
-
## 安装与使用
|
|
18
|
-
|
|
19
|
-
请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-ohos/clipboard Releases](https://github.com/react-native-oh-library/clipboard/releases) 。对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。
|
|
20
|
-
|
|
21
|
-
进入到工程目录并输入以下命令:
|
|
22
|
-
|
|
23
|
-
<!-- tabs:start -->
|
|
24
|
-
|
|
25
|
-
#### **npm**
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm install @react-native-ohos/clipboard
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
#### **yarn**
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
yarn add @react-native-ohos/clipboard
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
<!-- tabs:end -->
|
|
38
|
-
|
|
39
|
-
下面的代码展示了这个库的基本使用场景:
|
|
40
|
-
|
|
41
|
-
> [!WARNING] 使用时 import 的库名不变。
|
|
42
|
-
|
|
43
|
-
```js
|
|
44
|
-
import React, { useState } from 'react';
|
|
45
|
-
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
|
46
|
-
import Clipboard from "@react-native-clipboard/clipboard";
|
|
47
|
-
|
|
48
|
-
const App = () => {
|
|
49
|
-
const [copiedText, setCopiedText] = useState("");
|
|
50
|
-
|
|
51
|
-
const copyToClipboard = () => {
|
|
52
|
-
Clipboard.setString("hello world");
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const fetchCopiedText = async () => {
|
|
56
|
-
const text = await Clipboard.getString();
|
|
57
|
-
setCopiedText(text);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<View style={styles.container}>
|
|
62
|
-
<TouchableOpacity onPress={copyToClipboard}>
|
|
63
|
-
<Text>Click here to copy to Clipboard</Text>
|
|
64
|
-
</TouchableOpacity>
|
|
65
|
-
<TouchableOpacity onPress={fetchCopiedText}>
|
|
66
|
-
<Text>View copied text</Text>
|
|
67
|
-
</TouchableOpacity>
|
|
68
|
-
|
|
69
|
-
<Text style={styles.copiedText}>{copiedText}</Text>
|
|
70
|
-
</View>
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const styles = StyleSheet.create({
|
|
75
|
-
container: {
|
|
76
|
-
flex: 1,
|
|
77
|
-
justifyContent: "center",
|
|
78
|
-
alignItems: "center",
|
|
79
|
-
padding: 20,
|
|
80
|
-
},
|
|
81
|
-
copiedText: {
|
|
82
|
-
marginTop: 20,
|
|
83
|
-
fontSize: 18,
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
export default App;
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Link
|
|
91
|
-
|
|
92
|
-
目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。
|
|
93
|
-
|
|
94
|
-
首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`
|
|
95
|
-
|
|
96
|
-
### 1.在工程根目录的 `oh-package.json5` 添加 overrides 字段
|
|
97
|
-
|
|
98
|
-
```json
|
|
99
|
-
{
|
|
100
|
-
...
|
|
101
|
-
"overrides": {
|
|
102
|
-
"@rnoh/react-native-openharmony" : "./react_native_openharmony"
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### 2.引入原生端代码
|
|
108
|
-
|
|
109
|
-
目前有两种方法:
|
|
110
|
-
|
|
111
|
-
1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
|
|
112
|
-
2. 直接链接源码。
|
|
113
|
-
|
|
114
|
-
方法一:通过 har 包引入
|
|
115
|
-
|
|
116
|
-
> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。
|
|
117
|
-
|
|
118
|
-
打开 `entry/oh-package.json5`,添加以下依赖
|
|
119
|
-
|
|
120
|
-
```json
|
|
121
|
-
"dependencies": {
|
|
122
|
-
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
|
|
123
|
-
|
|
124
|
-
"@react-native-ohos/clipboard": "file:../../node_modules/@react-native-ohos/clipboard/harmony/clipboard.har"
|
|
125
|
-
}
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
点击右上角的 `sync` 按钮
|
|
129
|
-
|
|
130
|
-
或者在终端执行:
|
|
131
|
-
|
|
132
|
-
```bash
|
|
133
|
-
cd entry
|
|
134
|
-
ohpm install
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
方法二:直接链接源码
|
|
138
|
-
|
|
139
|
-
> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md)
|
|
140
|
-
|
|
141
|
-
### 3.配置 CMakeLists 和引入 ClipboardPackage
|
|
142
|
-
|
|
143
|
-
打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
|
|
144
|
-
|
|
145
|
-
```diff
|
|
146
|
-
project(rnapp)
|
|
147
|
-
cmake_minimum_required(VERSION 3.4.1)
|
|
148
|
-
set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
|
149
|
-
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
150
|
-
set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
|
|
151
|
-
+ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
|
|
152
|
-
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
|
|
153
|
-
set(LOG_VERBOSITY_LEVEL 1)
|
|
154
|
-
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
|
|
155
|
-
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
|
|
156
|
-
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
|
|
157
|
-
add_compile_definitions(WITH_HITRACE_SYSTRACE)
|
|
158
|
-
|
|
159
|
-
add_subdirectory("${RNOH_CPP_DIR}" ./rn)
|
|
160
|
-
|
|
161
|
-
# RNOH_BEGIN: manual_package_linking_1
|
|
162
|
-
add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
|
|
163
|
-
+ add_subdirectory("${OH_MODULES}/@react-native-ohos/clipboard/src/main/cpp" ./clipboard)
|
|
164
|
-
# RNOH_END: manual_package_linking_1
|
|
165
|
-
|
|
166
|
-
file(GLOB GENERATED_CPP_FILES "./generated/*.cpp")
|
|
167
|
-
|
|
168
|
-
add_library(rnoh_app SHARED
|
|
169
|
-
${GENERATED_CPP_FILES}
|
|
170
|
-
"./PackageProvider.cpp"
|
|
171
|
-
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
|
|
172
|
-
)
|
|
173
|
-
target_link_libraries(rnoh_app PUBLIC rnoh)
|
|
174
|
-
|
|
175
|
-
# RNOH_BEGIN: manual_package_linking_2
|
|
176
|
-
target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
|
|
177
|
-
+ target_link_libraries(rnoh_app PUBLIC rnoh_clipboard)
|
|
178
|
-
# RNOH_END: manual_package_linking_2
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
|
|
182
|
-
|
|
183
|
-
```diff
|
|
184
|
-
#include "RNOH/PackageProvider.h"
|
|
185
|
-
#include "generated/RNOHGeneratedPackage.h"
|
|
186
|
-
#include "SamplePackage.h"
|
|
187
|
-
+ #include "ClipboardPackage.h"
|
|
188
|
-
|
|
189
|
-
using namespace rnoh;
|
|
190
|
-
|
|
191
|
-
std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
|
|
192
|
-
return {
|
|
193
|
-
std::make_shared<RNOHGeneratedPackage>(ctx),
|
|
194
|
-
std::make_shared<SamplePackage>(ctx),
|
|
195
|
-
+ std::make_shared<ClipboardPackage>(ctx),
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### 4.在 ArkTs 侧引入 ClipboardPackage
|
|
201
|
-
|
|
202
|
-
打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
|
|
203
|
-
|
|
204
|
-
```diff
|
|
205
|
-
import type {RNPackageContext, RNPackage} from 'rnoh/ts';
|
|
206
|
-
import {SamplePackage} from 'rnoh-sample-package/ts';
|
|
207
|
-
+ import {ClipboardPackage} from '@react-native-ohos/clipboard/ts';
|
|
208
|
-
|
|
209
|
-
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
|
|
210
|
-
return [
|
|
211
|
-
new SamplePackage(ctx),
|
|
212
|
-
+ new ClipboardPackage(ctx)
|
|
213
|
-
];
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
### 5.运行
|
|
219
|
-
|
|
220
|
-
点击右上角的 `sync` 按钮
|
|
221
|
-
|
|
222
|
-
或者在终端执行:
|
|
223
|
-
|
|
224
|
-
```bash
|
|
225
|
-
cd entry
|
|
226
|
-
ohpm install
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
然后编译、运行即可。
|
|
230
|
-
|
|
231
|
-
## 约束与限制
|
|
232
|
-
|
|
233
|
-
### 兼容性
|
|
234
|
-
|
|
235
|
-
要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
|
|
236
|
-
|
|
237
|
-
请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-ohos/clipboard Releases](https://github.com/react-native-oh-library/clipboard/releases)
|
|
238
|
-
|
|
239
|
-
### 权限要求
|
|
240
|
-
|
|
241
|
-
> [!TIP] "ohos.permission.READ_PASTEBOARD"权限等级为<B>system_basic</B>,授权方式为<B>user_grant</B>,[使用 ACL 签名的配置指导](https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/signing-0000001587684945-V3#section157591551175916)
|
|
242
|
-
|
|
243
|
-
#### 在 entry 目录下的module.json5中添加权限
|
|
244
|
-
|
|
245
|
-
打开 `entry/src/main/module.json5`,添加:
|
|
246
|
-
|
|
247
|
-
```diff
|
|
248
|
-
...
|
|
249
|
-
"requestPermissions": [
|
|
250
|
-
+ {
|
|
251
|
-
+ "name": "ohos.permission.READ_PASTEBOARD",
|
|
252
|
-
+ "reason": "$string:Access_clipboard",
|
|
253
|
-
+ "usedScene": {
|
|
254
|
-
+ "abilities": [
|
|
255
|
-
+ "EntryAbility"
|
|
256
|
-
+ ],
|
|
257
|
-
+ "when":"always"
|
|
258
|
-
+ }
|
|
259
|
-
+ },
|
|
260
|
-
]
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
#### 在 entry 目录下添加申请剪切板权限的原因
|
|
264
|
-
|
|
265
|
-
打开 `entry/src/main/resources/base/element/string.json`,添加:
|
|
266
|
-
|
|
267
|
-
```diff
|
|
268
|
-
...
|
|
269
|
-
{
|
|
270
|
-
"string": [
|
|
271
|
-
+ {
|
|
272
|
-
+ "name": "Access_clipboard",
|
|
273
|
-
+ "value": "access clipboard"
|
|
274
|
-
+ }
|
|
275
|
-
]
|
|
276
|
-
}
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
## 属性
|
|
280
|
-
|
|
281
|
-
> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
|
|
282
|
-
|
|
283
|
-
> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
|
|
284
|
-
|
|
285
|
-
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|
|
286
|
-
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------- | ----------- | ----------------- |
|
|
287
|
-
| getString | Get content of string type, this method returns a Promise, so you can use following code to get clipboard content | function | NO | iOS,Android | yes |
|
|
288
|
-
| setString | Set content of string type. You can use following code to set clipboard content | function | NO | iOS,Android | yes |
|
|
289
|
-
| hasString | Returns whether the clipboard has content or is empty. | function | NO | iOS,Android | yes |
|
|
290
|
-
| getImage | Get content of image in base64 string type, this method returns a Promise, so you can use following code to get clipboard content (iOS and Android only) | function | NO | iOS,Android | no |
|
|
291
|
-
| getStrings | (iOS only) Get contents of string array type, this method returns a Promise, so you can use following code to get clipboard content | function | NO | iOS | yes |
|
|
292
|
-
| setStrings | (iOS only) Set content of string array type. You can use following code to set clipboard content | function | NO | iOS | yes |
|
|
293
|
-
| hasNumber | (iOS 14+ only) Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+ | function | NO | iOS | yes |
|
|
294
|
-
| hasImage | Returns whether the clipboard has a Image | function | NO | iOS | yes |
|
|
295
|
-
| hasUrl | (iOS only) Returns whether the clipboard has a URL content. Can check if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+ | function | NO | iOS | yes |
|
|
296
|
-
| hasWebUrl | (iOS 14+ only) Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+ | function | NO | iOS | yes |
|
|
297
|
-
| setImage | Set content of Image type.(base64 string) | function | NO | iOS | yes |
|
|
298
|
-
| getImageJPG | get base64 string of JPG Image | function | NO | iOS | yes |
|
|
299
|
-
| getImagePNG | get base64 string of PNG Image | function | NO | iOS | yes |
|
|
300
|
-
|
|
301
|
-
## 遗留问题
|
|
302
|
-
|
|
303
|
-
## 其他
|
|
304
|
-
|
|
305
|
-
## 开源协议
|
|
306
|
-
|
|
307
|
-
本项目基于 [The MIT License (MIT)](https://github.com/react-native-clipboard/clipboard/blob/master/LICENSE) ,请自由地享受和参与开源。
|
|
1
|
+
> 模板版本:v0.2.2
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<h1 align="center"> <code>@react-native-clipboard/clipboard</code> </h1>
|
|
5
|
+
</p>
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://github.com/react-native-clipboard/clipboard">
|
|
8
|
+
<img src="https://img.shields.io/badge/platforms-android%20|%20ios%20|%20macos%20|%20windows%20|%20harmony%20-lightgrey.svg" alt="Supported platforms" />
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://github.com/react-native-clipboard/clipboard/blob/master/LICENSE">
|
|
11
|
+
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" />
|
|
12
|
+
</a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
> [!TIP] [Github 地址](https://github.com/react-native-oh-library/clipboard/tree/sig)
|
|
16
|
+
|
|
17
|
+
## 安装与使用
|
|
18
|
+
|
|
19
|
+
请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-ohos/clipboard Releases](https://github.com/react-native-oh-library/clipboard/releases) 。对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。
|
|
20
|
+
|
|
21
|
+
进入到工程目录并输入以下命令:
|
|
22
|
+
|
|
23
|
+
<!-- tabs:start -->
|
|
24
|
+
|
|
25
|
+
#### **npm**
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @react-native-ohos/clipboard
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### **yarn**
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
yarn add @react-native-ohos/clipboard
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
<!-- tabs:end -->
|
|
38
|
+
|
|
39
|
+
下面的代码展示了这个库的基本使用场景:
|
|
40
|
+
|
|
41
|
+
> [!WARNING] 使用时 import 的库名不变。
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import React, { useState } from 'react';
|
|
45
|
+
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
|
46
|
+
import Clipboard from "@react-native-clipboard/clipboard";
|
|
47
|
+
|
|
48
|
+
const App = () => {
|
|
49
|
+
const [copiedText, setCopiedText] = useState("");
|
|
50
|
+
|
|
51
|
+
const copyToClipboard = () => {
|
|
52
|
+
Clipboard.setString("hello world");
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const fetchCopiedText = async () => {
|
|
56
|
+
const text = await Clipboard.getString();
|
|
57
|
+
setCopiedText(text);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<View style={styles.container}>
|
|
62
|
+
<TouchableOpacity onPress={copyToClipboard}>
|
|
63
|
+
<Text>Click here to copy to Clipboard</Text>
|
|
64
|
+
</TouchableOpacity>
|
|
65
|
+
<TouchableOpacity onPress={fetchCopiedText}>
|
|
66
|
+
<Text>View copied text</Text>
|
|
67
|
+
</TouchableOpacity>
|
|
68
|
+
|
|
69
|
+
<Text style={styles.copiedText}>{copiedText}</Text>
|
|
70
|
+
</View>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const styles = StyleSheet.create({
|
|
75
|
+
container: {
|
|
76
|
+
flex: 1,
|
|
77
|
+
justifyContent: "center",
|
|
78
|
+
alignItems: "center",
|
|
79
|
+
padding: 20,
|
|
80
|
+
},
|
|
81
|
+
copiedText: {
|
|
82
|
+
marginTop: 20,
|
|
83
|
+
fontSize: 18,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export default App;
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Link
|
|
91
|
+
|
|
92
|
+
目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。
|
|
93
|
+
|
|
94
|
+
首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`
|
|
95
|
+
|
|
96
|
+
### 1.在工程根目录的 `oh-package.json5` 添加 overrides 字段
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
...
|
|
101
|
+
"overrides": {
|
|
102
|
+
"@rnoh/react-native-openharmony" : "./react_native_openharmony"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 2.引入原生端代码
|
|
108
|
+
|
|
109
|
+
目前有两种方法:
|
|
110
|
+
|
|
111
|
+
1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
|
|
112
|
+
2. 直接链接源码。
|
|
113
|
+
|
|
114
|
+
方法一:通过 har 包引入
|
|
115
|
+
|
|
116
|
+
> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。
|
|
117
|
+
|
|
118
|
+
打开 `entry/oh-package.json5`,添加以下依赖
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
"dependencies": {
|
|
122
|
+
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
|
|
123
|
+
|
|
124
|
+
"@react-native-ohos/clipboard": "file:../../node_modules/@react-native-ohos/clipboard/harmony/clipboard.har"
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
点击右上角的 `sync` 按钮
|
|
129
|
+
|
|
130
|
+
或者在终端执行:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
cd entry
|
|
134
|
+
ohpm install
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
方法二:直接链接源码
|
|
138
|
+
|
|
139
|
+
> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md)
|
|
140
|
+
|
|
141
|
+
### 3.配置 CMakeLists 和引入 ClipboardPackage
|
|
142
|
+
|
|
143
|
+
打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
|
|
144
|
+
|
|
145
|
+
```diff
|
|
146
|
+
project(rnapp)
|
|
147
|
+
cmake_minimum_required(VERSION 3.4.1)
|
|
148
|
+
set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
|
149
|
+
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
150
|
+
set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
|
|
151
|
+
+ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
|
|
152
|
+
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
|
|
153
|
+
set(LOG_VERBOSITY_LEVEL 1)
|
|
154
|
+
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
|
|
155
|
+
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
|
|
156
|
+
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
|
|
157
|
+
add_compile_definitions(WITH_HITRACE_SYSTRACE)
|
|
158
|
+
|
|
159
|
+
add_subdirectory("${RNOH_CPP_DIR}" ./rn)
|
|
160
|
+
|
|
161
|
+
# RNOH_BEGIN: manual_package_linking_1
|
|
162
|
+
add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
|
|
163
|
+
+ add_subdirectory("${OH_MODULES}/@react-native-ohos/clipboard/src/main/cpp" ./clipboard)
|
|
164
|
+
# RNOH_END: manual_package_linking_1
|
|
165
|
+
|
|
166
|
+
file(GLOB GENERATED_CPP_FILES "./generated/*.cpp")
|
|
167
|
+
|
|
168
|
+
add_library(rnoh_app SHARED
|
|
169
|
+
${GENERATED_CPP_FILES}
|
|
170
|
+
"./PackageProvider.cpp"
|
|
171
|
+
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
|
|
172
|
+
)
|
|
173
|
+
target_link_libraries(rnoh_app PUBLIC rnoh)
|
|
174
|
+
|
|
175
|
+
# RNOH_BEGIN: manual_package_linking_2
|
|
176
|
+
target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
|
|
177
|
+
+ target_link_libraries(rnoh_app PUBLIC rnoh_clipboard)
|
|
178
|
+
# RNOH_END: manual_package_linking_2
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
|
|
182
|
+
|
|
183
|
+
```diff
|
|
184
|
+
#include "RNOH/PackageProvider.h"
|
|
185
|
+
#include "generated/RNOHGeneratedPackage.h"
|
|
186
|
+
#include "SamplePackage.h"
|
|
187
|
+
+ #include "ClipboardPackage.h"
|
|
188
|
+
|
|
189
|
+
using namespace rnoh;
|
|
190
|
+
|
|
191
|
+
std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
|
|
192
|
+
return {
|
|
193
|
+
std::make_shared<RNOHGeneratedPackage>(ctx),
|
|
194
|
+
std::make_shared<SamplePackage>(ctx),
|
|
195
|
+
+ std::make_shared<ClipboardPackage>(ctx),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### 4.在 ArkTs 侧引入 ClipboardPackage
|
|
201
|
+
|
|
202
|
+
打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
|
|
203
|
+
|
|
204
|
+
```diff
|
|
205
|
+
import type {RNPackageContext, RNPackage} from 'rnoh/ts';
|
|
206
|
+
import {SamplePackage} from 'rnoh-sample-package/ts';
|
|
207
|
+
+ import {ClipboardPackage} from '@react-native-ohos/clipboard/ts';
|
|
208
|
+
|
|
209
|
+
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
|
|
210
|
+
return [
|
|
211
|
+
new SamplePackage(ctx),
|
|
212
|
+
+ new ClipboardPackage(ctx)
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 5.运行
|
|
219
|
+
|
|
220
|
+
点击右上角的 `sync` 按钮
|
|
221
|
+
|
|
222
|
+
或者在终端执行:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
cd entry
|
|
226
|
+
ohpm install
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
然后编译、运行即可。
|
|
230
|
+
|
|
231
|
+
## 约束与限制
|
|
232
|
+
|
|
233
|
+
### 兼容性
|
|
234
|
+
|
|
235
|
+
要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
|
|
236
|
+
|
|
237
|
+
请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-ohos/clipboard Releases](https://github.com/react-native-oh-library/clipboard/releases)
|
|
238
|
+
|
|
239
|
+
### 权限要求
|
|
240
|
+
|
|
241
|
+
> [!TIP] "ohos.permission.READ_PASTEBOARD"权限等级为<B>system_basic</B>,授权方式为<B>user_grant</B>,[使用 ACL 签名的配置指导](https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/signing-0000001587684945-V3#section157591551175916)
|
|
242
|
+
|
|
243
|
+
#### 在 entry 目录下的module.json5中添加权限
|
|
244
|
+
|
|
245
|
+
打开 `entry/src/main/module.json5`,添加:
|
|
246
|
+
|
|
247
|
+
```diff
|
|
248
|
+
...
|
|
249
|
+
"requestPermissions": [
|
|
250
|
+
+ {
|
|
251
|
+
+ "name": "ohos.permission.READ_PASTEBOARD",
|
|
252
|
+
+ "reason": "$string:Access_clipboard",
|
|
253
|
+
+ "usedScene": {
|
|
254
|
+
+ "abilities": [
|
|
255
|
+
+ "EntryAbility"
|
|
256
|
+
+ ],
|
|
257
|
+
+ "when":"always"
|
|
258
|
+
+ }
|
|
259
|
+
+ },
|
|
260
|
+
]
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### 在 entry 目录下添加申请剪切板权限的原因
|
|
264
|
+
|
|
265
|
+
打开 `entry/src/main/resources/base/element/string.json`,添加:
|
|
266
|
+
|
|
267
|
+
```diff
|
|
268
|
+
...
|
|
269
|
+
{
|
|
270
|
+
"string": [
|
|
271
|
+
+ {
|
|
272
|
+
+ "name": "Access_clipboard",
|
|
273
|
+
+ "value": "access clipboard"
|
|
274
|
+
+ }
|
|
275
|
+
]
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## 属性
|
|
280
|
+
|
|
281
|
+
> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
|
|
282
|
+
|
|
283
|
+
> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
|
|
284
|
+
|
|
285
|
+
| Name | Description | Type | Required | Platform | HarmonyOS Support |
|
|
286
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------- | ----------- | ----------------- |
|
|
287
|
+
| getString | Get content of string type, this method returns a Promise, so you can use following code to get clipboard content | function | NO | iOS,Android | yes |
|
|
288
|
+
| setString | Set content of string type. You can use following code to set clipboard content | function | NO | iOS,Android | yes |
|
|
289
|
+
| hasString | Returns whether the clipboard has content or is empty. | function | NO | iOS,Android | yes |
|
|
290
|
+
| getImage | Get content of image in base64 string type, this method returns a Promise, so you can use following code to get clipboard content (iOS and Android only) | function | NO | iOS,Android | no |
|
|
291
|
+
| getStrings | (iOS only) Get contents of string array type, this method returns a Promise, so you can use following code to get clipboard content | function | NO | iOS | yes |
|
|
292
|
+
| setStrings | (iOS only) Set content of string array type. You can use following code to set clipboard content | function | NO | iOS | yes |
|
|
293
|
+
| hasNumber | (iOS 14+ only) Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+ | function | NO | iOS | yes |
|
|
294
|
+
| hasImage | Returns whether the clipboard has a Image | function | NO | iOS | yes |
|
|
295
|
+
| hasUrl | (iOS only) Returns whether the clipboard has a URL content. Can check if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+ | function | NO | iOS | yes |
|
|
296
|
+
| hasWebUrl | (iOS 14+ only) Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+ | function | NO | iOS | yes |
|
|
297
|
+
| setImage | Set content of Image type.(base64 string) | function | NO | iOS | yes |
|
|
298
|
+
| getImageJPG | get base64 string of JPG Image | function | NO | iOS | yes |
|
|
299
|
+
| getImagePNG | get base64 string of PNG Image | function | NO | iOS | yes |
|
|
300
|
+
|
|
301
|
+
## 遗留问题
|
|
302
|
+
|
|
303
|
+
## 其他
|
|
304
|
+
|
|
305
|
+
## 开源协议
|
|
306
|
+
|
|
307
|
+
本项目基于 [The MIT License (MIT)](https://github.com/react-native-clipboard/clipboard/blob/master/LICENSE) ,请自由地享受和参与开源。
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
{
|
|
2
|
-
"apiType": "stageMode",
|
|
3
|
-
"targets": [
|
|
4
|
-
{
|
|
5
|
-
"name": "default",
|
|
6
|
-
}
|
|
7
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"apiType": "stageMode",
|
|
3
|
+
"targets": [
|
|
4
|
+
{
|
|
5
|
+
"name": "default",
|
|
6
|
+
}
|
|
7
|
+
]
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { harTasks } from '@ohos/hvigor-ohos-plugin';
|
|
1
|
+
export { harTasks } from '@ohos/hvigor-ohos-plugin';
|