{"_id":"@bingtang-rn/react-native-orientation-turbo","_rev":"2-28022353623eacb4a23e2ea962661f42","name":"@bingtang-rn/react-native-orientation-turbo","dist-tags":{"latest":"2.2.1"},"versions":{"2.2.0":{"name":"@bingtang-rn/react-native-orientation-turbo","version":"2.2.0","keywords":["react-native","harmony","harmonyos","react-native-orientation-turbo"],"license":"MIT","_id":"@bingtang-rn/react-native-orientation-turbo@2.2.0","maintainers":[{"name":"luyizouyuan","email":"189605613@qq.com"}],"homepage":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_turbo","dist":{"shasum":"392433c8fe8b8f71875688bc371b2f55e9d2332f","tarball":"https://registry.npmjs.org/@bingtang-rn/react-native-orientation-turbo/-/react-native-orientation-turbo-2.2.0.tgz","fileCount":37,"integrity":"sha512-O+Bu3RQP2sbjDo/sj16MP41bv0PhwYkztnWqWbwFnuKXbOddqrspHd9yTk2jrnvZgzf00G75i7xVGvXoIQjWRw==","signatures":[{"sig":"MEQCIAigd9KlyJCXTiTY23+UmksFQSUy00d9YsX8roHyaUHHAiBoBfecebVoNZfCJyr2qwF5Mn5niZUcGdagzT+gaEmLpg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":59437},"main":"./src/index.tsx","module":"./src/index.tsx","engines":{"node":">=18"},"gitHead":"01e6b9e63fd0549c0009dfc48ba68b1d5ec59f21","harmony":{"alias":"react-native-orientation-turbo","autolinking":{"ohPackageName":"@oh-rn/react-native-orientation-turbo","cppPackageClassName":"OrientationTurboPackage","etsPackageClassName":"OrientationTurboPackage","cmakeLibraryTargetName":"orientation_turbo"},"codegenConfig":[{"version":1,"specPaths":["./src/specs/v1"]}]},"private":false,"scripts":{"prepare":"echo skip","codegen-lib":"react-native codegen-harmony --cpp-output-path ./harmony/orientation_turbo/src/main/cpp/generated --ets-output-path ./harmony/orientation_turbo/src/main/ets/generated"},"_npmUser":{"name":"luyizouyuan","email":"189605613@qq.com"},"repository":{"url":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_turbo","type":"git"},"_npmVersion":"11.12.1","description":"适配鸿蒙版本，提供react_native_orientation_turbo组件。","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-turbo_2.2.0_1785417728876_0.6377769822884065","host":"s3://npm-registry-packages-npm-production"}},"2.2.1":{"_id":"@bingtang-rn/react-native-orientation-turbo@2.2.1","dist":{"shasum":"e47371ebcefb201c508f40768f7c6bfb5a852fab","tarball":"https://registry.npmjs.org/@bingtang-rn/react-native-orientation-turbo/-/react-native-orientation-turbo-2.2.1.tgz","fileCount":37,"integrity":"sha512-e9cxlBsyG/abpFd7eVPjJDbcdtkIGTiWZYwHL/N8SgvilSGVyc5CnC1fTs2V+IjFxw4q3+1TWyVVU0OgKfWKrQ==","signatures":[{"sig":"MEQCICenht6mObCxVLP+SkI3tqrnltoHvfxD4GQ+rSYqjTT3AiAKAT/af18Ju3FAvJVXXYiJfNv+0W8hcVgPuGVKL2aYvA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDpJ5nlSfdD1DW57WAturKZ33GWzraozv5EL/oeskAxkwIhAKWQdNFo1DSzka1nhTazzihvzOa9AjTL+syh6CR6XXU+"}],"unpackedSize":59639},"main":"./src/index.tsx","name":"@bingtang-rn/react-native-orientation-turbo","_from":"file:bingtang-rn-react-native-orientation-turbo-2.2.1.tgz","module":"./src/index.tsx","engines":{"node":">=18"},"harmony":{"alias":"react-native-orientation-turbo","autolinking":{"ohPackageName":"@bingtang-rn/react-native-orientation-turbo","cppPackageClassName":"OrientationTurboPackage","etsPackageClassName":"OrientationTurboPackage","cmakeLibraryTargetName":"orientation_turbo"},"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_turbo/src/main/cpp/generated --ets-output-path ./harmony/orientation_turbo/src/main/ets/generated"},"version":"2.2.1","_npmUser":{"name":"luyizouyuan","email":"189605613@qq.com"},"homepage":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_turbo","keywords":["react-native","harmony","harmonyos","react-native-orientation-turbo"],"_resolved":"D:\\code\\rn\\npm\\batch\\react_native_orientation_turbo\\bingtang-rn-react-native-orientation-turbo-2.2.1.tgz","_integrity":"sha512-e9cxlBsyG/abpFd7eVPjJDbcdtkIGTiWZYwHL/N8SgvilSGVyc5CnC1fTs2V+IjFxw4q3+1TWyVVU0OgKfWKrQ==","repository":{"url":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_turbo","type":"git"},"_npmVersion":"11.12.1","description":"适配鸿蒙版本，提供react_native_orientation_turbo组件。","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-turbo_2.2.1_1790569333324_0.10907510666655185"}}},"time":{"created":"2026-07-30T13:22:03.880Z","modified":"2026-09-28T04:22:13.612Z","2.2.0":"2026-07-30T13:22:09.016Z","2.2.1":"2026-09-28T04:22:13.403Z"},"license":"MIT","homepage":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_turbo","keywords":["react-native","harmony","harmonyos","react-native-orientation-turbo"],"repository":{"url":"https://gitcode.com/rn_ohos_plugin/react_native_orientation_turbo","type":"git"},"description":"适配鸿蒙版本，提供react_native_orientation_turbo组件。","maintainers":[{"name":"luyizouyuan","email":"189605613@qq.com"}],"readme":"# @bingtang-rn/react-native-orientation-turbo for HarmonyOS\r\n\r\n本项目基于 [react-native-orientation-turbo](https://github.com/whitestranger7/react-native-orientation-turbo) 开发，为 React Native 鸿蒙（OpenHarmony）适配版本。如果在使用过程中有任何问题，可以在GitCode提Issue，会及时跟进。issue地址：[issues](https://gitcode.com/rn_ohos_plugin/react_native_orientation_turbo/issues)。\r\n\r\n## 版本对应关系\r\n\r\n| 鸿蒙适配包版本 | 原始库版本 | 支持 RN 版本 | Autolink | 编译 API 版本 |\r\n| ------------ | ---------- | ------------ | -------- | ------------- |\r\n| 见发布记录 | 2.2.0 | 0.72+ | 是/否 | API17+ |\r\n\r\n## 安装\r\n\r\n```bash\r\nnpm install @bingtang-rn/react-native-orientation-turbo\r\n```\r\n\r\n## 使用\r\n\r\n```tsx\r\nimport {\r\n  lockToPortrait,\r\n  lockToLandscape,\r\n  unlockAllOrientations,\r\n  getCurrentOrientation,\r\n  isLocked,\r\n  onOrientationChange,\r\n  onLockOrientationChange,\r\n  startOrientationTracking,\r\n  stopOrientationTracking,\r\n  LandscapeDirection,\r\n} from 'react-native-orientation-turbo';\r\n\r\n// 锁定竖屏\r\nlockToPortrait();\r\nlockToPortrait('UPSIDE_DOWN');\r\n\r\n// 锁定横屏\r\nlockToLandscape(LandscapeDirection.LEFT);\r\nlockToLandscape(LandscapeDirection.RIGHT);\r\n\r\n// 解锁方向（跟随传感器自动旋转）\r\nunlockAllOrientations();\r\n\r\n// 获取当前方向\r\nconst orientation = getCurrentOrientation(); // 'PORTRAIT' | 'LANDSCAPE_LEFT' | ...\r\n\r\n// 查询是否锁定\r\nconst locked = isLocked();\r\n\r\n// 监听方向变化\r\nstartOrientationTracking();\r\nconst sub = onOrientationChange((event) => {\r\n  console.log('方向变为:', event.orientation);\r\n});\r\n\r\n// 监听锁定状态变化\r\nconst lockSub = onLockOrientationChange((event) => {\r\n  console.log('锁定状态:', event.isLocked, '方向:', event.orientation);\r\n});\r\n```\r\n\r\n> import 时使用原库名 `'react-native-orientation-turbo'`，而非鸿蒙包名。\r\n\r\n**平台差异**：\r\n- HarmonyOS 上 `getDeviceAutoRotateStatus()` 返回 `null`（鸿蒙无查询系统自动旋转开关的公共 API，与 iOS 行为一致）\r\n- HarmonyOS 不支持 `FACE_UP` / `FACE_DOWN` 方向（无设备物理姿态传感器暴露给方向 API，与 Android 行为一致）\r\n\r\n**权限要求**：\r\n- 本模块无需声明额外权限\r\n\r\n## Link\r\n\r\n| 版本 | 是否支持 Autolink |\r\n|------|------------------|\r\n| 当前版本 | 是 |\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-turbo\": \"file:../../node_modules/@bingtang-rn/react-native-orientation-turbo/harmony/orientation_turbo.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-turbo/src/main/cpp\" ./orientation_turbo)\r\n\r\ntarget_link_libraries(rnoh_app PUBLIC orientation_turbo)\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 \"OrientationTurboPackage.h\"\r\n\r\nstd::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {\r\n    return {\r\n        std::make_shared<OrientationTurboPackage>(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 { OrientationTurboPackage } from '@bingtang-rn/react-native-orientation-turbo/ts';\r\n\r\nexport function createRNPackages(ctx: RNPackageContext): RNPackage[] {\r\n  return [\r\n    new OrientationTurboPackage(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| lockToPortrait | 锁定竖屏 | direction?: string ('UP'/'UPSIDE_DOWN') | void | ✅ 完全支持 |\r\n| lockToLandscape | 锁定横屏 | direction: string ('LEFT'/'RIGHT') | void | ✅ 完全支持 |\r\n| unlockAllOrientations | 解锁所有方向 | 无 | void | ✅ 完全支持 |\r\n| getCurrentOrientation | 获取当前方向 | 无 | string | ✅ 完全支持 |\r\n| isLocked | 查询是否锁定 | 无 | boolean | ✅ 完全支持 |\r\n| startOrientationTracking | 开始方向追踪 | 无 | void | ✅ 完全支持 |\r\n| stopOrientationTracking | 停止方向追踪 | 无 | void | ✅ 完全支持 |\r\n| getDeviceAutoRotateStatus | 获取自动旋转状态 | 无 | {isAutoRotateEnabled, canDetectOrientation} \\| null | ⚠️ 部分支持（返回 null） |\r\n| onOrientationChange | 方向变化事件 | callback | EventSubscription | ✅ 完全支持 |\r\n| onLockOrientationChange | 锁定状态变化事件 | callback | EventSubscription | ✅ 完全支持 |\r\n\r\n### 平台差异\r\n- `getDeviceAutoRotateStatus()`：HarmonyOS 返回 `null`（无查询系统自动旋转开关的公共 API），与 iOS 行为一致\r\n- `FACE_UP` / `FACE_DOWN`：HarmonyOS 不支持这两个方向值（无设备物理姿态传感器暴露给方向 API），与 Android 行为一致\r\n- `PORTRAIT_UPSIDE_DOWN`：Android 大多数设备不支持，HarmonyOS 通过 `window.Orientation.PORTRAIT_INVERTED` 支持\r\n\r\n### 方向映射说明\r\n| RN 方向 | 含义 | HarmonyOS window.Orientation |\r\n|---------|------|------------------------------|\r\n| PORTRAIT | HOME 在下 | PORTRAIT |\r\n| LANDSCAPE_RIGHT | HOME 在右 | LANDSCAPE |\r\n| LANDSCAPE_LEFT | HOME 在左 | LANDSCAPE_INVERTED |\r\n| PORTRAIT_UPSIDE_DOWN | HOME 在上 | PORTRAIT_INVERTED |\r\n\r\n### 未实现功能\r\n| API | 原因 |\r\n|-----|------|\r\n| getDeviceAutoRotateStatus 返回非 null 值 | HarmonyOS 无查询系统自动旋转开关状态的公共 API |\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](https://github.com/whitestranger7/react-native-orientation-turbo/blob/main/LICENSE) 协议，详见 [LICENSE](./LICENSE) 文件。\r\n","readmeFilename":"README.md"}