@expo-harmony/expo-screen-capture 55.0.14-harmony.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/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # @expo-harmony/expo-screen-capture
2
+
3
+ [**GitHub 仓库**](https://github.com/renbaoshuo/expo-harmony/tree/master/packages/expo-screen-capture) | [官方文档](https://docs.expo.dev/versions/v55.0.0/sdk/screen-capture/)
4
+
5
+ 为 HarmonyOS 上的 React Native 应用提供 Expo ScreenCapture 的原生实现,与官方同版本的 `expo-screen-capture` 配套使用。支持阻止和恢复截屏、录屏,以及监听截图。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install @expo-harmony/expo-screen-capture expo-screen-capture@55.0.14
11
+ ```
12
+
13
+ 本包适配 Expo SDK 55 的 `expo-screen-capture`,原生模块通过 Expo Harmony 自动链接,不需要配置插件。最低支持 HarmonyOS 5.0.1(API 13),宿主的 `compatibleSdkVersion` 也要满足这一要求。
14
+
15
+ HAR 声明 `ohos.permission.PRIVACY_WINDOW`,构建时合并到宿主,不会弹出授权对话框;截图监听不需要相册或存储权限。
16
+
17
+ 业务代码从官方包导入:
18
+
19
+ ```ts
20
+ import * as ScreenCapture from 'expo-screen-capture';
21
+
22
+ await ScreenCapture.preventScreenCaptureAsync();
23
+ const subscription = ScreenCapture.addScreenshotListener(() => {
24
+ console.log('用户截图了');
25
+ });
26
+ ```
27
+
28
+ ## API 对照表
29
+
30
+ ### Hooks
31
+
32
+ #### `usePermissions(options)`
33
+
34
+ 返回 `[PermissionResponse | null, request, get]`。HarmonyOS 上截图监听不需要权限,两者都返回已授权。
35
+
36
+ #### `usePreventScreenCapture(key)`
37
+
38
+ 在组件挂载期间阻止截屏,卸载后恢复。`key` 用于区分多个调用方,见 `preventScreenCaptureAsync()`。
39
+
40
+ #### `useScreenshotListener(listener)`
41
+
42
+ 在组件挂载期间监听截图,卸载后取消监听。
43
+
44
+ ### Methods
45
+
46
+ #### `ScreenCapture.preventScreenCaptureAsync(key)`
47
+
48
+ 返回 `Promise<void>`,通过 React Native 窗口的隐私模式阻止截屏和录屏。
49
+
50
+ `key` 用于区分多个调用方,不同的 `key` 相互独立,全部恢复前保护一直有效。启用后保护在后台继续生效,多任务界面由系统遮罩,其他独立窗口不受影响。应用重载或 runtime 释放时,已设置的隐私模式会被解除。
51
+
52
+ 没有 UI 窗口的后台运行时无法调用,抛出 `ERR_SCREEN_CAPTURE_WINDOW`。运行时已销毁后调用抛出 `ERR_SCREEN_CAPTURE_DESTROYED`。
53
+
54
+ #### `ScreenCapture.allowScreenCaptureAsync(key)`
55
+
56
+ 返回 `Promise<void>`,恢复截屏和录屏。要放开全部保护,需要把所有用过的 `key` 都恢复一次。遗留的隐私窗口释放失败时抛出 `ERR_SCREEN_CAPTURE_RELEASE`。
57
+
58
+ #### `ScreenCapture.getPermissionsAsync()`
59
+
60
+ 返回 `Promise<PermissionResponse>`,恒为已授权。
61
+
62
+ #### `ScreenCapture.requestPermissionsAsync()`
63
+
64
+ 返回 `Promise<PermissionResponse>`,恒为已授权,不弹出对话框。
65
+
66
+ #### `ScreenCapture.isAvailableAsync()`
67
+
68
+ 返回 `Promise<boolean>`,恒为 `true`。
69
+
70
+ > **未实现的内容**
71
+ >
72
+ > - `enableAppSwitcherProtectionAsync()`、`disableAppSwitcherProtectionAsync()`:iOS 专属接口,HarmonyOS 上没有对应能力,调用抛出 `UnavailabilityError`。
73
+
74
+ ### Event subscriptions
75
+
76
+ #### `ScreenCapture.addScreenshotListener(listener)`
77
+
78
+ 返回 `Subscription`,监听用户截图。只在应用处于前台且存在订阅时触发。
79
+
80
+ 通知只表示系统检测到截图操作,不代表截图文件已经保存成功。
81
+
82
+ #### `ScreenCapture.removeScreenshotListener(subscription)`
83
+
84
+ 取消监听。官方已标记废弃,改调 `subscription.remove()`。
85
+
86
+ ### Types
87
+
88
+ #### `PermissionHookOptions`
89
+
90
+ `PermissionHookBehavior | Options`。
91
+
92
+ #### `PermissionResponse`
93
+
94
+ | 属性 | 类型 | 说明 |
95
+ | ------------- | ---------------------- | ---------------- |
96
+ | `status` | `PermissionStatus` | 恒为 `'granted'` |
97
+ | `granted` | `boolean` | 恒为 `true` |
98
+ | `canAskAgain` | `boolean` | 恒为 `true` |
99
+ | `expires` | `PermissionExpiration` | 恒为 `'never'` |
100
+
101
+ ### Enums
102
+
103
+ #### `PermissionStatus`
104
+
105
+ `'granted' | 'denied' | 'undetermined'`。HarmonyOS 上只出现 `'granted'`。
106
+
107
+ ## Author
108
+
109
+ **expo-harmony** © [Baoshuo](https://github.com/renbaoshuo), Released under the MIT License.<br>
110
+ Authored and maintained by Baoshuo with help from [contributors](https://github.com/renbaoshuo/expo-harmony/contributors)
111
+
112
+ > [Personal Website](https://baoshuo.ren) · [Blog](https://blog.baoshuo.ren) · GitHub [@renbaoshuo](https://github.com/renbaoshuo) · Twitter [@renbaoshuo](https://twitter.com/renbaoshuo)
@@ -0,0 +1,6 @@
1
+ {
2
+ "platforms": ["harmony"],
3
+ "harmony": {
4
+ "modules": ["ExpoScreenCaptureModule"]
5
+ }
6
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@expo-harmony/expo-screen-capture",
3
+ "version": "55.0.14-harmony.1",
4
+ "description": "HarmonyOS port of expo-screen-capture",
5
+ "keywords": [
6
+ "react-native",
7
+ "expo",
8
+ "expo-harmony",
9
+ "harmonyos"
10
+ ],
11
+ "homepage": "https://github.com/renbaoshuo/expo-harmony/tree/master/packages/expo-screen-capture#readme",
12
+ "repository": "https://github.com/renbaoshuo/expo-harmony",
13
+ "author": {
14
+ "name": "Baoshuo",
15
+ "email": "i@baoshuo.ren",
16
+ "url": "https://github.com/renbaoshuo"
17
+ },
18
+ "main": "Index.ets",
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@expo-harmony/expo-modules-core": "55.0.25-harmony.3"
22
+ }
23
+ }
Binary file
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ module.exports = Object.freeze({});
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@expo-harmony/expo-screen-capture",
3
+ "version": "55.0.14-harmony.1",
4
+ "description": "HarmonyOS port of expo-screen-capture",
5
+ "keywords": [
6
+ "react-native",
7
+ "expo",
8
+ "expo-harmony",
9
+ "harmonyos"
10
+ ],
11
+ "homepage": "https://github.com/renbaoshuo/expo-harmony/tree/master/packages/expo-screen-capture#readme",
12
+ "bugs": "https://github.com/renbaoshuo/expo-harmony/issues",
13
+ "license": "MIT",
14
+ "author": "Baoshuo <i@baoshuo.ren>",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/renbaoshuo/expo-harmony.git",
18
+ "directory": "packages/expo-screen-capture"
19
+ },
20
+ "main": "index.js",
21
+ "types": "index.d.ts",
22
+ "scripts": {
23
+ "harmony:clean": "expo-harmony-module prepare --clean-only",
24
+ "harmony:build": "expo-harmony-module prepare",
25
+ "prepack": "expo-harmony-module prepack"
26
+ },
27
+ "peerDependencies": {
28
+ "@expo-harmony/expo-modules-core": "55.0.25-harmony.3",
29
+ "expo-screen-capture": "55.0.14"
30
+ },
31
+ "devDependencies": {
32
+ "@expo-harmony/expo-module-scripts": "55.0.0-harmony.3",
33
+ "@expo-harmony/expo-modules-core": "55.0.25-harmony.3",
34
+ "@react-native-oh/react-native-harmony": "0.84.1",
35
+ "expo": "55.0.26",
36
+ "expo-modules-core": "55.0.25",
37
+ "expo-screen-capture": "55.0.14",
38
+ "react": "19.2.3",
39
+ "react-native": "0.84.1"
40
+ },
41
+ "engines": {
42
+ "node": ">=20"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ }
47
+ }