{"_id":"@bingtang-rn/react-native-orientation-director","_rev":"2-630e88c34747d9abd26a78aa8d9d9db1","name":"@bingtang-rn/react-native-orientation-director","dist-tags":{"latest":"3.0.3"},"versions":{"3.0.2":{"name":"@bingtang-rn/react-native-orientation-director","version":"3.0.2","keywords":["react-native","harmony","harmonyos","react-native-orientation-director"],"license":"MIT","_id":"@bingtang-rn/react-native-orientation-director@3.0.2","maintainers":[{"name":"luyizouyuan","email":"189605613@qq.com"}],"homepage":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_director","dist":{"shasum":"77b1004293484c2cd431294678381ed00349975c","tarball":"https://registry.npmjs.org/@bingtang-rn/react-native-orientation-director/-/react-native-orientation-director-3.0.2.tgz","fileCount":49,"integrity":"sha512-agcS5mCtOXeCDVQ8s2iL2UFiyduW6tPT7yfntsDSyJve+0RXJoRsVrRo1UoxohogY9M+iagORZmOLDQPcJn6eA==","signatures":[{"sig":"MEYCIQCVw5yZkdmdDICHKErNPT7DFwHeLu6xv0lTvI7OoZixJAIhAJ5g3IkqYL7uubUYM5RSNGgky7N2pYyp6zqC3oNEZBxm","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35834481},"main":"./src/index.tsx","module":"./src/index.tsx","engines":{"node":">=18"},"gitHead":"8a3130ce79d4bb33c4c50ce72cc0a97f5bf51d87","harmony":{"alias":"react-native-orientation-director","autolinking":{"ohPackageName":"@oh-rn/react-native-orientation-director","cppPackageClassName":"OrientationDirectorPackage","etsPackageClassName":"OrientationDirectorPackage","cmakeLibraryTargetName":"orientation_director"},"codegenConfig":[{"version":1,"specPaths":["./src/specs/v1"]}]},"private":false,"scripts":{"prepare":"echo skip","codegen-lib":"react-native codegen-harmony --cpp-output-path ./harmony/orientation_director/src/main/cpp/generated --ets-output-path ./harmony/orientation_director/src/main/ets/generated"},"_npmUser":{"name":"luyizouyuan","email":"189605613@qq.com"},"repository":{"url":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_director","type":"git"},"_npmVersion":"11.12.1","description":"适配鸿蒙版本，提供react_native_orientation_director组件。","directories":{},"_nodeVersion":"24.15.0","react-native":"./src/index.tsx","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.6.3","metro":"^0.81.0","react":"18.2.0","typescript":"5.0.4","@types/react":"18.2.79","react-native":"0.72.5","@react-native/typescript-config":"0.79.5","@react-native-oh/react-native-harmony-cli":"^0.77.50"},"peerDependencies":{"react-native":">=0.72"},"_npmOperationalInternal":{"tmp":"tmp/react-native-orientation-director_3.0.2_1785417758327_0.9533039418279872","host":"s3://npm-registry-packages-npm-production"}},"3.0.3":{"_id":"@bingtang-rn/react-native-orientation-director@3.0.3","dist":{"shasum":"2713657b59a808e74e957394b19f89444e28e92f","tarball":"https://registry.npmjs.org/@bingtang-rn/react-native-orientation-director/-/react-native-orientation-director-3.0.3.tgz","fileCount":49,"integrity":"sha512-LmvlxHdKgAXjVic/VLvqITcslfKRHpQNHQFN94FaO/vOc2wffaZU14+2TugL+R8sbg6j0irLfcfiYkwrJNyKlA==","signatures":[{"sig":"MEUCIQCTk8SzZAQA75IRFKoBf5R0OxIutgC9j8Fbi2BbLzeTlgIgEzqCV4IGtnIpV3i6nQBv0umtt4KBHnmQ/gLDfFeEoag=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIClgIlJ8Un8xUOq7YBWiTDojieNUFcSdLfmp0zi4yDN2AiEAj5B3AvgUEt0Umua4Nx8z0MQoySw//VSEbzfDYVqZ7ug="}],"unpackedSize":35834793},"main":"./src/index.tsx","name":"@bingtang-rn/react-native-orientation-director","_from":"file:bingtang-rn-react-native-orientation-director-3.0.3.tgz","module":"./src/index.tsx","engines":{"node":">=18"},"harmony":{"alias":"react-native-orientation-director","autolinking":{"ohPackageName":"@bingtang-rn/react-native-orientation-director","cppPackageClassName":"OrientationDirectorPackage","etsPackageClassName":"OrientationDirectorPackage","cmakeLibraryTargetName":"orientation_director"},"codegenConfig":[{"version":1,"specPaths":["./src/specs/v1"]}]},"license":"MIT","private":false,"scripts":{"prepare":"echo skip","codegen-lib":"react-native codegen-harmony --cpp-output-path ./harmony/orientation_director/src/main/cpp/generated --ets-output-path ./harmony/orientation_director/src/main/ets/generated"},"version":"3.0.3","_npmUser":{"name":"luyizouyuan","email":"189605613@qq.com"},"homepage":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_director","keywords":["react-native","harmony","harmonyos","react-native-orientation-director"],"_resolved":"D:\\code\\rn\\npm\\batch\\react_native_orientation_director\\bingtang-rn-react-native-orientation-director-3.0.3.tgz","_integrity":"sha512-LmvlxHdKgAXjVic/VLvqITcslfKRHpQNHQFN94FaO/vOc2wffaZU14+2TugL+R8sbg6j0irLfcfiYkwrJNyKlA==","repository":{"url":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_director","type":"git"},"_npmVersion":"11.12.1","description":"适配鸿蒙版本，提供react_native_orientation_director组件。","directories":{},"maintainers":[{"name":"luyizouyuan","email":"189605613@qq.com"}],"_nodeVersion":"24.15.0","react-native":"./src/index.tsx","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.6.3","metro":"^0.81.0","react":"18.2.0","typescript":"5.0.4","@types/react":"18.2.79","react-native":"0.72.5","@react-native/typescript-config":"0.79.5","@react-native-oh/react-native-harmony-cli":"^0.77.50"},"peerDependencies":{"react-native":">=0.72"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/react-native-orientation-director_3.0.3_1790569618938_0.16855344229544755"}}},"time":{"created":"2026-07-30T13:22:38.087Z","modified":"2026-09-28T04:26:59.606Z","3.0.2":"2026-07-30T13:22:38.915Z","3.0.3":"2026-09-28T04:26:59.436Z"},"license":"MIT","homepage":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_director","keywords":["react-native","harmony","harmonyos","react-native-orientation-director"],"repository":{"url":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_director","type":"git"},"description":"适配鸿蒙版本，提供react_native_orientation_director组件。","maintainers":[{"name":"luyizouyuan","email":"189605613@qq.com"}],"readme":"# @bingtang-rn/react-native-orientation-director for HarmonyOS\r\n\r\n本项目基于 [react-native-orientation-director](https://github.com/gladiuscode/react-native-orientation-director) 开发，为 React Native 鸿蒙（OpenHarmony）适配版本。如果在使用过程中有任何问题，可以在GitCode提Issue，会及时跟进。issue地址：[issues](https://gitcode.com/rn_ohos_plugin/react_native_orientation_director/issues)。\r\n\r\n## 版本对应关系\r\n\r\n| 鸿蒙适配包版本 | 原始库版本 | 支持 RN 版本 | Autolink | 编译 API 版本 |\r\n| ------------ | ---------- | ------------ | -------- | ------------- |\r\n| 3.0.2 | 3.0.2 | 0.72+ | 是 | API17+ |\r\n\r\n## 安装\r\n\r\n```bash\r\nnpm install @bingtang-rn/react-native-orientation-director\r\n```\r\n\r\n## 使用\r\n\r\n```tsx\r\nimport RNOrientationDirector, {\r\n  Orientation,\r\n  OrientationType,\r\n  useDeviceOrientation,\r\n  useInterfaceOrientation,\r\n} from 'react-native-orientation-director';\r\n\r\n// 实时获取设备 / 界面方向\r\nconst deviceOrientation = useDeviceOrientation();\r\nconst interfaceOrientation = useInterfaceOrientation();\r\n\r\n// 锁定到竖屏\r\nRNOrientationDirector.lockTo(Orientation.portrait);\r\n\r\n// 解锁\r\nRNOrientationDirector.unlock();\r\n\r\n// 查询当前锁定状态\r\nconst locked = RNOrientationDirector.isLocked();\r\n```\r\n\r\n> import 时使用原库名 `'react-native-orientation-director'`，RNOH 通过 alias 自动重定向到 `@bingtang-rn/react-native-orientation-director`。\r\n\r\n**平台差异**：\r\n- `isAutoRotationEnabled()` 在 HarmonyOS 上返回 `AutoRotation.unknown`（鸿蒙无直接对应系统自动旋转开关 API），原生 stub 不被实际调用。\r\n- 设备方向由 `@ohos.sensor` `SensorId.GRAVITY` 传感器 x/y/z 分量计算（含 faceUp/faceDown），与 Android 的 `OrientationEventListener` + `TYPE_ROTATION_VECTOR` 算法等价但实现不同。\r\n- 界面方向变化监听使用 `@ohos.display` `on('change')` 事件，替代 Android 的 `BroadcastReceiver`。\r\n- 横屏方向（landscapeLeft/Right）在设备↔界面间做了反转，与原库 iOS 行为对齐。\r\n\r\n**权限要求**：\r\n- 无需任何 `ohos.permission.*` 运行时权限。传感器订阅、`display`/`window` API 均为普通应用能力，`module.json5` 的 `requestPermissions` 为空。\r\n\r\n## Link\r\n\r\n| 版本 | 是否支持 Autolink |\r\n|------|------------------|\r\n| 3.0.2 | 是 |\r\n\r\n如使用版本支持 Autolink 且工程已接入，可跳过手动配置。\r\n\r\n<details>\r\n<summary>Manual Link 配置</summary>\r\n\r\n> **说明**：本模块需要同时在 C++ 侧和 ETS 侧注册 Package。\r\n\r\n### 1. Overrides RN SDK\r\n\r\n在工程根目录 `oh-package.json5` 添加：\r\n\r\n```json\r\n{\r\n  \"overrides\": {\r\n    \"@rnoh/react-native-openharmony\": \"./react_native_openharmony\"\r\n  }\r\n}\r\n```\r\n\r\n### 2. 引入原生端依赖\r\n\r\n打开 `entry/oh-package.json5`，添加：\r\n\r\n```json\r\n\"dependencies\": {\r\n  \"@bingtang-rn/react-native-orientation-director\": \"file:../../node_modules/@bingtang-rn/react-native-orientation-director/harmony/orientation_director.har\"\r\n}\r\n```\r\n\r\n执行 `ohpm install`。\r\n\r\n### 3. 配置 CMakeLists\r\n\r\n打开 `entry/src/main/cpp/CMakeLists.txt`，添加：\r\n\r\n```cmake\r\nset(OH_MODULES \"${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules\")\r\n\r\nadd_subdirectory(\"${OH_MODULES}/@bingtang-rn/react-native-orientation-director/src/main/cpp\" ./orientation_director)\r\n\r\ntarget_link_libraries(rnoh_app PUBLIC orientation_director)\r\n```\r\n\r\n### 4. 注册 Package（C++ 侧）\r\n\r\n打开 `entry/src/main/cpp/PackageProvider.cpp`，添加：\r\n\r\n```cpp\r\n#include \"OrientationDirectorPackage.h\"\r\n\r\nstd::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {\r\n    return {\r\n        std::make_shared<OrientationDirectorPackage>(ctx),\r\n    };\r\n}\r\n```\r\n\r\n### 5. 注册 Package（ETS 侧）\r\n\r\n打开 `entry/src/main/ets/RNPackagesFactory.ets`，添加：\r\n\r\n```typescript\r\nimport { OrientationDirectorPackage } from '@bingtang-rn/react-native-orientation-director';\r\n\r\nexport function createRNPackages(ctx: RNPackageContext): RNPackage[] {\r\n  return [\r\n    new OrientationDirectorPackage(ctx),\r\n  ];\r\n}\r\n```\r\n\r\n</details>\r\n\r\n## 属性 / API\r\n\r\n| API | 描述 | 参数 | 返回值 | HarmonyOS 支持 |\r\n|-----|------|------|--------|----------------|\r\n| getInterfaceOrientation | 获取当前界面方向 | 无 | Promise&lt;Orientation&gt; | ✅ 完全支持 |\r\n| getDeviceOrientation | 获取当前设备方向 | 无 | Promise&lt;Orientation&gt; | ✅ 完全支持 |\r\n| lockTo | 锁定到指定方向 | orientation: Orientation, orientationType?: OrientationType | void | ✅ 完全支持 |\r\n| unlock | 解除方向锁定 | 无 | void | ✅ 完全支持 |\r\n| isLocked | 查询是否已锁定 | 无 | boolean | ✅ 完全支持 |\r\n| resetSupportedInterfaceOrientations | 恢复初始方向配置 | 无 | void | ✅ 完全支持 |\r\n| isAutoRotationEnabled | 查询系统自动旋转开关 | 无 | AutoRotation | ❌ 不支持 |\r\n| enableOrientationSensors | 开启方向传感器 | 无 | void | ✅ 完全支持 |\r\n| disableOrientationSensors | 关闭方向传感器 | 无 | void | ✅ 完全支持 |\r\n| onDeviceOrientationChanged | 设备方向变化事件 | { orientation: number } | EventEmitter | ✅ 完全支持 |\r\n| onInterfaceOrientationChanged | 界面方向变化事件 | { orientation: number } | EventEmitter | ✅ 完全支持 |\r\n| onLockChanged | 锁定状态变化事件 | { locked: boolean } | EventEmitter | ✅ 完全支持 |\r\n| useDeviceOrientation | Hook：设备方向 | 无 | Orientation | ✅ 完全支持 |\r\n| useInterfaceOrientation | Hook：界面方向 | 无 | Orientation | ✅ 完全支持 |\r\n| useIsInterfaceOrientationLocked | Hook：是否锁定 | 无 | boolean | ✅ 完全支持 |\r\n| Orientation | 方向枚举（0-7） | — | — | ✅ 完全支持 |\r\n| AutoRotation | 自动旋转枚举（0-2） | — | — | ⚠️ 部分支持 |\r\n| OrientationType | 方向类型枚举 | — | — | ✅ 完全支持 |\r\n| convertOrientationToHumanReadableString | 方向转可读字符串 | Orientation | string | ✅ 完全支持 |\r\n| convertAutoRotationToHumanReadableString | 自动旋转转可读字符串 | AutoRotation | string | ✅ 完全支持 |\r\n| isLockableOrientation | 判断是否可锁定方向 | Orientation | boolean | ✅ 完全支持 |\r\n\r\n### 平台差异\r\n\r\n- **事件通道**：RNOH codegen-harmony 不生成 Spec `EventEmitter<T>` 属性，原生侧通过 `ctx.rnInstance.emitDeviceEvent` 发送，JS 侧通过 `DeviceEventEmitter.addListener` 订阅，事件名（`OrientationDirector.deviceOrientationChanged` 等）与 payload 结构（`{orientation: number}` / `{locked: boolean}`）与原库一致。\r\n- **横屏镜像**：设备横屏方向与界面横屏方向互为镜像（landscapeLeft ↔ landscapeRight），与 iOS 行为对齐；`lockTo` 的 `OrientationType.device` 分支由 JS 门面完成反转。\r\n- **传感器按需启停**：首个设备方向监听注册时开启 GRAVITY 传感器，最后一个取消时关闭；构造时也短暂启动以计算初始方向。\r\n\r\n### 未实现功能\r\n\r\n| API | 原因 |\r\n|-----|------|\r\n| isAutoRotationEnabled | HarmonyOS 无直接对应系统自动旋转设置 API（`@ohos.settings` 无此项，display/window 无查询接口），JS 层对非 android 平台返回 `AutoRotation.unknown`，与 iOS 行为一致 |\r\n\r\n### 使用限制\r\n\r\n- Example 的 `module.json5` 需将 ability 的 `orientation` 设为 `auto_rotation`，`lockTo` 各方向与自动旋转才能生效。\r\n- `window.setPreferredOrientation` 的方向锁定语义需真机校准（文档未明确 LANDSCAPE/LANDSCAPE_INVERTED 的物理旋转方向），代码注释已标注校准点。\r\n\r\n## 快速验证（运行 Example）\r\n\r\n### 前置条件\r\n\r\n| 依赖 | 版本要求 |\r\n|------|----------|\r\n| Node.js | >= 18 |\r\n| DevEco Studio | 5.0+ / 6.0+ |\r\n| HarmonyOS SDK | API 17+ |\r\n\r\n### 运行步骤\r\n\r\n**1. 克隆仓库**\r\n\r\n```bash\r\ngit clone <仓库地址>\r\ncd <仓库目录>\r\n```\r\n\r\n**2. 安装依赖并构建**\r\n\r\n```bash\r\nnpm install --legacy-peer-deps\r\nnpm pack           # 生成 tgz 包（会自动触发 prepare 构建 JS 产物）\r\n```\r\n\r\n**3. 进入 example 目录，安装依赖**\r\n\r\n```bash\r\ncd example\r\nnpm install --legacy-peer-deps\r\n```\r\n\r\n**4. 生成 JS Bundle**\r\n\r\n```bash\r\nnpm run dev\r\n```\r\n\r\n产物：`harmony/entry/src/main/resources/rawfile/bundle.harmony.js`\r\n\r\n**5. 用 DevEco Studio 打开鸿蒙工程**\r\n\r\n- 打开 DevEco Studio\r\n- 选择 `example/harmony` 目录\r\n- 等待 Sync 完成\r\n\r\n**6. 编译并运行 HAP**\r\n\r\n在 DevEco Studio 中点击运行按钮，将 HAP 安装到设备/模拟器。\r\n\r\n> **注意**：Example 中已预置插件依赖和 Package 注册，无需手动配置 Link。\r\n\r\n## 约束与限制\r\n\r\n### 兼容性\r\n\r\n- RNOH: 0.72+\r\n- HarmonyOS SDK: API 17+\r\n- DevEco Studio: 5.0+\r\n\r\n## 遗留问题\r\n\r\n无（或列出已知问题）\r\n\r\n## 开源协议\r\n\r\n本项目基于 [MIT License](https://github.com/gladiuscode/react-native-orientation-director/blob/main/LICENSE)，详见 [LICENSE](./LICENSE) 文件。\r\n","readmeFilename":"README.md"}