{"_id":"@capacitor-ohos/screen-orientation","_rev":"2-701cad1ef5aa0d2e8906fbe14fa6bc40","name":"@capacitor-ohos/screen-orientation","dist-tags":{"latest":"8.0.1"},"versions":{"8.0.0":{"name":"@capacitor-ohos/screen-orientation","version":"8.0.0","keywords":["capacitor","plugin","native"],"author":{"url":"Group","name":"Huawei Device Co., Ltd and iSoftStone Information Technology"},"license":"MIT","_id":"@capacitor-ohos/screen-orientation@8.0.0","maintainers":[{"name":"luqi_tan","email":"295099422@qq.com"}],"bugs":{"url":"https://gitcode.com/CPF-Ionic/capacitor-screen-orientation/issues"},"dist":{"shasum":"f2d276f742ac78ed6c9daf7b01b7783dc6809ba6","tarball":"https://registry.npmjs.org/@capacitor-ohos/screen-orientation/-/screen-orientation-8.0.0.tgz","fileCount":10,"integrity":"sha512-Ij8vItus5HSgDrtors51gAMWJLaiiZyfaeQYOFwPyAbEYD2lngB8SDw4q3Zm83lMj2aGt4+LaretEPQLOoCu+A==","signatures":[{"sig":"MEYCIQC6fehWmHm8hq/HFzx6WDLTfdg4n4TBf49MhH7nt19dWQIhANUYHH2vVIHsD1g1Yz5y5ucvK5Qhrop+0UpPwwXwK674","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":42252},"gitHead":"ee857360cf07441511aeaf60cd8c6d86bbae2002","_npmUser":{"name":"luqi_tan","email":"295099422@qq.com"},"capacitor":{"id":"@capacitor/screen-orientation","platforms":["openharmony"]},"repository":{"url":"gitcode:CPF-Ionic/capacitor-screen-orientation","type":"git"},"_npmVersion":"10.5.1","description":"The Screen Orientation API provides information and functionality related to the orientation of the screen.","directories":{},"_nodeVersion":"22.0.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/screen-orientation_8.0.0_1777547233799_0.20533240069431846","host":"s3://npm-registry-packages-npm-production"}},"8.0.1":{"name":"@capacitor-ohos/screen-orientation","version":"8.0.1","description":"The Screen Orientation API provides information and functionality related to the orientation of the screen.","capacitor":{"id":"@capacitor/screen-orientation","platforms":["openharmony"]},"repository":{"type":"git","url":"gitcode:CPF-Ionic/capacitor-screen-orientation"},"bugs":{"url":"https://gitcode.com/CPF-Ionic/capacitor-screen-orientation/issues"},"keywords":["capacitor","plugin","native"],"author":{"name":"Huawei Device Co., Ltd and iSoftStone Information Technology","url":"Group"},"license":"MIT","_id":"@capacitor-ohos/screen-orientation@8.0.1","gitHead":"f3e581b4ab13f1b76e0027d5dc422ba8663f5102","_nodeVersion":"22.0.0","_npmVersion":"10.5.1","dist":{"integrity":"sha512-JeNzVSzj8EgxJRPlGkX6MdZaUFjdtsDUzmOf2CVzazlzDP+dScydO+yqgJ5G5vkEdpl0TYQof13PXBS5L1aX4g==","shasum":"e576353e7eb14b20d9915b08c656841d13565c62","tarball":"https://registry.npmjs.org/@capacitor-ohos/screen-orientation/-/screen-orientation-8.0.1.tgz","fileCount":10,"unpackedSize":42276,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDsC0FpYN8Br5vZejBrKhJtMrXTq1RrpnjZ8HidQJdzrwIgZ2oWXvdT86RZjY6bOSNZJbs+JkBRrStZ9T4wy/4CA28="}]},"_npmUser":{"name":"luqi_tan","email":"295099422@qq.com"},"directories":{},"maintainers":[{"name":"luqi_tan","email":"295099422@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/screen-orientation_8.0.1_1784797217494_0.6042203009392817"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-30T11:07:13.703Z","modified":"2026-07-23T09:00:17.795Z","8.0.0":"2026-04-30T11:07:13.990Z","8.0.1":"2026-07-23T09:00:17.641Z"},"bugs":{"url":"https://gitcode.com/CPF-Ionic/capacitor-screen-orientation/issues"},"author":{"name":"Huawei Device Co., Ltd and iSoftStone Information Technology","url":"Group"},"license":"MIT","keywords":["capacitor","plugin","native"],"repository":{"type":"git","url":"gitcode:CPF-Ionic/capacitor-screen-orientation"},"description":"The Screen Orientation API provides information and functionality related to the orientation of the screen.","maintainers":[{"name":"luqi_tan","email":"295099422@qq.com"}],"readme":"# <center>`@capacitor/screen-orientation`</center>\r\n[![zh-CN](https://img.shields.io/badge/lang-中文-blue.svg)](README.md)\r\n[![en](https://img.shields.io/badge/lang-English-blue.svg)](README.en.md)\r\n\r\n本项目基于 [@capacitor/screen-orientation@8.0.0](https://www.npmjs.com/package/@capacitor/screen-orientation) 开发。\r\n\r\n## 简介\r\n\r\n提供屏幕方向 API 及相关功能，支持获取当前方向、锁定/解锁方向和监听方向变化。本插件是 capacitor 生态系统中的核心插件，为跨平台应用开发提供设备差异化适配能力，兼容 capacitor 的 Android、iOS 等主流移动平台及浏览器环境中使用，本文档仅说明在 OpenHarmony 系统中的使用情况。\r\n\r\n## 支持平台\r\n\r\n- **OpenHarmony**：5.0+\r\n\r\n## 下载安装\r\n\r\n通过命令行或手动引入即可快速安装插件，支持从npm仓库获取。\r\n\r\n### 命令行安装（推荐）\r\n\r\n安装hionic CLI：\r\n\r\n```bash\r\nnpm install -g hionic\r\n```\r\n\r\n以下两种方式中**任选其一**即可，无需重复操作：\r\n\r\nnpm安装：\r\n\r\n```bash\r\n# 安装插件\r\nnpm install @capacitor/screen-orientation\r\n\r\n# 同步插件\r\nhionic sync openharmony\r\n```\r\n\r\nhionic CLI安装：\r\n\r\n```bash\r\nhionic plugin add @capacitor/screen-orientation\r\n```\r\n\r\n### 手动引入安装\r\n\r\n根据插件源码中 `plugin.xml` 配置在项目中引入插件：\r\n\r\n#### 1. 添加插件配置\r\n\r\n根据 `plugin.xml` 的 `config-json` 项，找到 `entry` 模块中 `capacitor.plugins.json` 文件，并根据 `param` 标签添加配置如下：\r\n\r\n```json\r\n{\r\n  \"pkg\": \"@capacitor/screen-orientation\",\r\n  \"classpath\": \"ScreenOrientation\"\r\n}\r\n```\r\n\r\n#### 2. 修改 CMake 配置\r\n\r\n根据 `plugin.xml` 的 `CMakeLists` 项，找到 `capacitor` 模块，路径为 `target` 字段的 `CMakeLists.txt` 文件，并添加 `add_subdirectory` 和 `target_link_libraries` 如下：\r\n\r\n```cmake\r\n// ...\r\nadd_subdirectory(ScreenOrientation)\r\n// ...\r\n\r\n// ...\r\ntarget_link_libraries(capacitor PUBLIC\r\n  \"-Wl,--whole-archive\"\r\n  // ...\r\n  ScreenOrientation\r\n  // ...\r\n  \"-Wl,--no-whole-archive\"\r\n);\r\n```\r\n\r\n#### 3. 复制源码文件\r\n\r\n根据 `plugin.xml` 的 `source-file` 项，根据 `src` 字段找到需要复制的文件，并复制到对应的目录：\r\n\r\n将源码中 src/main/cpp/ScreenOrientation 目录下 ScreenOrientation.h、ScreenOrientation.cpp、CMakeLists.txt 文件引入到 capacitor 模块中 src/main/cpp/ScreenOrientation 目录下。\r\n\r\n将源码中 src/main/ets/components/ScreenOrientation 目录下 ScreenOrientation.ets 文件引入到 capacitor 模块中 src/main/ets/components/ScreenOrientation 目录下。\r\n\r\n在 `capacitor` 模块下 `build-profile.json5` 文件中，`buildOption/arkOptions/runtimeOnly/sources` 配置项数组中加入拷贝的 `ets` 文件路径：\r\n\r\n```json\r\n\"buildOption\": {\r\n  \"arkOptions\": {\r\n    \"runtimeOnly\": {\r\n      \"sources\": [\r\n        // ...\r\n        \"./src/main/ets/components/ScreenOrientation/ScreenOrientation.ets\"\r\n        // ...\r\n      ]\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## 卸载\r\n\r\n```bash\r\n# 卸载 screen-orientation 插件\r\nhionic plugin remove @capacitor/screen-orientation\r\n```\r\n\r\n## 约束与限制\r\n\r\n### 兼容性\r\n\r\n在以下版本中已测试通过：\r\n\r\n1. SDK: 5.0.5(17); IDE: DevEco Studio: 6.0.0; ROM: 5.1.0.150;\r\n\r\n### 权限要求\r\n\r\n不需要额外权限。\r\n\r\n## 使用示例\r\n\r\n### 基础示例：获取屏幕方向、锁定方向、解锁方向并监听方向变化\r\n\r\n```typescript\r\nimport { ScreenOrientation } from '@capacitor/screen-orientation';\r\n\r\n// 获取当前屏幕方向\r\nconst getOrientation = async () => {\r\n  const result = await ScreenOrientation.orientation();\r\n  console.log('Current orientation:', result.type);\r\n};\r\n\r\n// 锁定屏幕方向为横屏\r\nconst lockLandscape = async () => {\r\n  await ScreenOrientation.lock({\r\n    orientation: 'landscape'\r\n  });\r\n};\r\n\r\n// 锁定屏幕方向为竖屏\r\nconst lockPortrait = async () => {\r\n  await ScreenOrientation.lock({\r\n    orientation: 'portrait'\r\n  });\r\n};\r\n\r\n// 解锁屏幕方向\r\nconst unlockOrientation = async () => {\r\n  await ScreenOrientation.unlock();\r\n};\r\n\r\n// 监听屏幕方向变化\r\nconst listenOrientationChanges = async () => {\r\n  const listener = await ScreenOrientation.addListener(\r\n    'screenOrientationChange',\r\n    (orientation) => {\r\n      console.log('Orientation changed:', orientation.type);\r\n    }\r\n  );\r\n\r\n  // 稍后移除监听器\r\n  // listener.remove();\r\n};\r\n\r\n// 移除所有监听器\r\nconst removeAllListeners = async () => {\r\n  await ScreenOrientation.removeAllListeners();\r\n};\r\n```\r\n\r\n## 使用说明\r\n\r\n### 接口方法\r\n\r\n| 方法名              | 返回类型                       | 描述                               |\r\n| ------------------- | ------------------------------ | ---------------------------------- |\r\n| orientation()     | Promise&lt;[ScreenOrientationResult](#screenorientationresult)&gt; | 返回当前屏幕方向                     |\r\n| lock(options: [OrientationLockOptions](#orientationlockoptions))           | Promise<void>                  | 锁定屏幕方向                      |\r\n| unlock()          | Promise<void>                  | 解锁屏幕方向                      |\r\n| addListener('screenOrientationChange', ...) | Promise&lt;[PluginListenerHandle](#pluginListenerHandle)&gt; | 监听屏幕方向变化             |\r\n| removeAllListeners() | Promise<void>                  | 移除所有监听器                    |\r\n\r\n### 数据结构\r\n\r\n#### ScreenOrientationResult\r\n\r\n```typescript\r\nexport interface ScreenOrientationResult {\r\n  type: OrientationType;\r\n}\r\n```\r\n\r\n#### OrientationLockOptions\r\n\r\n```typescript\r\nexport interface OrientationLockOptions {\r\n  orientation: OrientationLockType;\r\n}\r\n```\r\n\r\n#### PluginListenerHandle\r\n\r\n| 属性         | 类型                  |\r\n| ------------ | --------------------- |\r\n| **`remove`** | `() => Promise<void>` |\r\n\r\n#### OrientationType\r\n\r\n```typescript\r\nexport type OrientationType =\r\n  | 'any'\r\n  | 'natural'\r\n  | 'landscape'\r\n  | 'portrait'\r\n  | 'portrait-primary'\r\n  | 'portrait-secondary'\r\n  | 'landscape-primary'\r\n  | 'landscape-secondary';\r\n```\r\n\r\n#### OrientationLockType\r\n\r\n```typescript\r\nexport type OrientationLockType =\r\n  | 'any'\r\n  | 'natural'\r\n  | 'landscape'\r\n  | 'portrait'\r\n  | 'portrait-primary'\r\n  | 'portrait-secondary'\r\n  | 'landscape-primary'\r\n  | 'landscape-secondary';\r\n```\r\n\r\n## 目录结构\r\n\r\n```\r\n|---- 项目根目录\r\n|     |---- src\r\n|           |---- main\r\n|                 |---- cpp\r\n|                       |---- ScreenOrientation   # 插件核心 C++ 实现\r\n|                             |---- ScreenOrientation.h\r\n|                             |---- ScreenOrientation.cpp\r\n|                             |---- CMakeLists.txt\r\n|                 |---- ets\r\n|                       |---- components\r\n|                             |---- ScreenOrientation   # 插件核心 ArkTS 实现\r\n|                                   |---- ScreenOrientation.ets\r\n|     |---- README.md          # 说明文档\r\n|     |---- package.json       # npm 配置文件\r\n|     |---- plugin.xml         # capacitor 插件配置\r\n|     |---- LICENSE            # 许可证文件\r\n```\r\n\r\n## 贡献代码\r\n\r\n使用过程中发现任何问题都可以提 [Issue](https://gitcode.com/CPF-Ionic/capacitor-screen-orientation/issues)，当然，也非常欢迎发 [PR](https://gitcode.com/CPF-Ionic/capacitor-screen-orientation/pulls) 共建。\r\n\r\n## 许可证\r\n\r\n本插件基于 **MIT License** 开源，详见 [LICENSE](./LICENSE) 文件。\r\n","readmeFilename":"README.md"}