From 667d67a20b0eb144aeb32271f471f20ded6e4390 Mon Sep 17 00:00:00 2001 From: ZZW <5237428+zhang_zhenwei@user.noreply.gitee.com> Date: Wed, 4 Feb 2026 10:25:54 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=96=B0=E5=A2=9Ereact-native-extra-di?= =?UTF-8?q?mensions=E7=9A=84=E4=B8=AD=E8=8B=B1=E6=96=87=E6=8C=87=E5=AF=BC?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ZZW --- en/react-native-extra-dimensions.md | 387 +++++++++++++++++++++++++ zh-cn/react-native-extra-dimensions.md | 387 +++++++++++++++++++++++++ 2 files changed, 774 insertions(+) create mode 100644 en/react-native-extra-dimensions.md create mode 100644 zh-cn/react-native-extra-dimensions.md diff --git a/en/react-native-extra-dimensions.md b/en/react-native-extra-dimensions.md new file mode 100644 index 00000000..e3069103 --- /dev/null +++ b/en/react-native-extra-dimensions.md @@ -0,0 +1,387 @@ +> Template version: v0.4.0 + +

+

@react-native-ohos/react-native-extra-dimensions

+

+

+ + Supported platforms + + + License + +

+ +This project is based on [@react-native-community/react-native-extra-dimensions-android](https://github.com/Sunhat/react-native-extra-dimensions-android). + +The repository is on Github and supports direct npm download. The new package name is: `@react-native-ohos/react-native-extra-dimensions`. Version relationships are as follows: + +| Library Name | Library Version | Release Information | Supported RN Versions | Autolink | Compile API Version | Community Baseline Version | +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | +| @react-native-ohos/react-native-extra-dimensions | 1.2.5-rc.1 | [Git Releases]() | 0.72, 0.77| No | API12+ | 1.2.4 | + +## 1. Installation and Usage + +Enter the project directory and enter the following command: + + + +#### **npm** + +```bash +npm install @react-native-ohos/react-native-extra-dimensions +``` + +#### **yarn** + +```bash +yarn add @react-native-ohos/react-native-extra-dimensions +``` + + + +The following code demonstrates the basic usage scenarios of this library: + +> [!WARNING] The import library name remains unchanged when using. + +```js +import React, { useState, useEffect } from 'react'; +import { + SafeAreaView, + ScrollView, + StatusBar, + StyleSheet, + Text, + View, +} from 'react-native'; +import ExtraDimensions from 'react-native-extra-dimensions'; + +function App(): JSX.Element { + const realWindowHeight = ExtraDimensions.getRealWindowHeight(); + const realWindowWidth = ExtraDimensions.getRealWindowWidth(); + const statusBarHeight = ExtraDimensions.getStatusBarHeight(); + const softMenuBarHeight = ExtraDimensions.getSoftMenuBarHeight(); + const softMenuBarEnabled = !!ExtraDimensions.isSoftMenuBarEnabled(); + + return ( + + + + + ExtraDimensions Demo + React Native for HarmonyOS + + + + Screen Dimensions + + + + + + System Bar Heights + + + + + + Navigation Bar Status + + + + + + ); +} + +interface InfoRowProps { + label: string; + value: string; + highlight?: boolean; +} + +function InfoRow({ label, value, highlight }: InfoRowProps): JSX.Element { + return ( + + {label} + {value} + + ); +} + +interface CodeBlockProps { + code: string; +} + +function CodeBlock({ code }: CodeBlockProps): JSX.Element { + return ( + + {code} + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: '#f5f5f5', + }, + scrollContent: { + padding: 16, + }, + header: { + marginBottom: 24, + paddingVertical: 16, + backgroundColor: '#fff', + borderRadius: 12, + paddingHorizontal: 20, + shadowColor: '#000', + shadowOffset: { width: 0, height: 2 }, + shadowOpacity: 0.1, + shadowRadius: 4, + elevation: 3, + }, + title: { + fontSize: 28, + fontWeight: 'bold', + color: '#333', + }, + subtitle: { + fontSize: 14, + color: '#666', + marginTop: 4, + }, + section: { + backgroundColor: '#fff', + borderRadius: 12, + padding: 16, + marginBottom: 16, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.05, + shadowRadius: 2, + elevation: 2, + }, + sectionTitle: { + fontSize: 18, + fontWeight: '600', + color: '#333', + marginBottom: 12, + }, + infoRow: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + paddingVertical: 8, + borderBottomWidth: 1, + borderBottomColor: '#f0f0f0', + }, + label: { + fontSize: 14, + color: '#666', + flex: 1, + }, + value: { + fontSize: 16, + fontWeight: '500', + color: '#333', + }, + highlightValue: { + color: '#007AFF', + fontWeight: '600', + }, + codeBlock: { + backgroundColor: '#f8f8f8', + borderRadius: 8, + padding: 12, + marginTop: 8, + borderLeftWidth: 3, + borderLeftColor: '#007AFF', + }, + code: { + fontFamily: 'monospace', + fontSize: 13, + color: '#333', + lineHeight: 20, + }, +}); + +export default App; +``` + +## 2. Link + +| | Auto-link Support | RN Framework Version | +|--------|-------------------|----------------------| +| 1.0.0 | No | 0.72/0.77 | + +Projects using AutoLink need to be configured according to this document. Autolink framework guide: https://gitcode.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md + +If your version supports Autolink and the project has already integrated Autolink, you can skip the ManualLink configuration. +
+ ManualLink: This step is a guide for manually configuring native dependencies + +First, you need to open the HarmonyOS project `harmony` in the project using DevEco Studio. + +### 2.1. Overrides RN SDK + +To ensure the project depends on the same version of RN SDK, you need to add an overrides field in the `oh-package.json5` at the project root directory, pointing to the RN SDK version the project needs to use. The replacement version can be a specific version number, a fuzzy version, or a local HAR package or source code directory. + +For information about this field, please read the [official documentation](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#zh-cn_topic_0000001792256137_overrides) + +```json +{ + "overrides": { + "@rnoh/react-native-openharmony": "^0.72.38" // ohpm online version + // "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // path to local har package + // "@rnoh/react-native-openharmony" : "./react_native_openharmony" // path to source code + } +} +``` + +### 2.2. Import native code + +There are currently two methods: + +- Import via har package; +- Directly link source code. + +Method 1: Import via har package (Recommended) + +> [!TIP] The har package is located in the `harmony` folder of the third-party library installation path. + +Open `entry/oh-package.json5` and add the following dependencies: + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + "@react-native-ohos/react-native-extra-dimensions": "file:../../node_modules/@react-native-ohos/react-native-extra-dimensions/harmony/extra_dimensions.har" + } +``` + +Click the `sync` button in the upper right corner + +Or execute in the terminal: + +```bash +cd entry +ohpm install +``` + +Method 2: Directly link source code + +> [!TIP] To use directly linking source code, please refer to [Direct Source Code Linking Guide](/zh-cn/link-source-code.md) + +### 2.3. Configure CMakeLists and import ExtraDimensionsPackage + +Open `entry/src/main/cpp/CMakeLists.txt` and add: + +```diff +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") + +# RNOH_BEGIN: manual_package_linking_1 ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-extra-dimensions/src/main/ets/cpp" ./extra_dimensions) +# RNOH_END: manual_package_linking_1 + +# RNOH_BEGIN: manual_package_linking_2 ++ target_link_libraries(rnoh_app PUBLIC rnoh_extra_dimensions) +# RNOH_END: manual_package_linking_2 +``` + +Open `entry/src/main/cpp/PackageProvider.cpp` and add: + +```diff +#include "RNOH/PackageProvider.h" +#include "generated/RNOHGeneratedPackage.h" ++ #include "RNOHExtraDimensionsPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), ++ std::make_shared(ctx), + }; +} +``` + +### 2.4. Import ExtraDimensionsPackage on the ArkTs side + +Open `entry/src/main/ets/RNPackagesFactory.ts` and add: + +```diff +import type {RNPackageContext, RNPackage} from '@rnoh/react-native-openharmony/ts'; ++ import { ExtraDimensionsPackage } from '@react-native-ohos/react-native-extra-dimensions/ts'; + +export function createRNPackages(ctx: RNPackageContext): RNPackage[] { + return [ ++ new ExtraDimensionsPackage(ctx) + ]; +} +``` + +### 2.5. Run + +Click the `sync` button in the upper right corner + +Or execute in the command-line terminal: + +```bash +cd entry +ohpm install +``` + +Then compile and run. +
+ +## 3. Constraints and Limitations + +### 3.1. Compatibility + +Please check the corresponding Releases page of the third-party library for version information: [@react-native-ohos/react-native-extra-dimensions Releases]() + +This document is validated on the following versions: + +1. RNOH: 0.72.96; SDK: HarmonyOS-6.0.0.47 (API Version 22); IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; +2. RNOH: 0.72.28; SDK: HarmonyOS-6.0.0.47 (API Version 22); IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; +3. RNOH: 0.77.18; SDK: HarmonyOS-6.0.0.47 (API Version 22); IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; + +### 3.2. Compilation and Runtime API Requirements + +> [!TIP] All versions of the current third-party library have implemented version isolation and support compilation in `API12+` projects and running on `API12+` ROM. + +## 4. Features + +> [!TIP] The "Platform" column indicates the platforms supported by the property in the original third-party library. + +> [!TIP] The "HarmonyOS Support" column: yes means the HarmonyOS platform supports this property; no means it is not supported; partially means partial support. The usage method is cross-platform consistent, and the effect corresponds to iOS or Android. + +### API List + +| Function | Description | Return Type | Platform | HarmonyOS Support | +| :---------------------: | :------------------: | :------------------: | :------: | :---------------: | +| getRealWindowHeight | Get real window height | number | All | Yes | +| getRealWindowWidth | Get real window width | number | All | Yes | +| getStatusBarHeight | Get status bar height | number | All | Yes | +| getSoftMenuBarHeight | Get soft navigation bar height | number | All | Yes | +| isSoftMenuBarEnabled | Check if soft navigation bar is enabled | boolean | All | Yes | + +## 5. Known Issues + +None + +## 6. Others + +None + +## 7. License + +This project is based on [The ISC License (ISC)](https://github.com/Sunhat/react-native-extra-dimensions-android/blob/master/LICENSE.md). Feel free to enjoy and contribute to the open source. \ No newline at end of file diff --git a/zh-cn/react-native-extra-dimensions.md b/zh-cn/react-native-extra-dimensions.md new file mode 100644 index 00000000..13fa1fd9 --- /dev/null +++ b/zh-cn/react-native-extra-dimensions.md @@ -0,0 +1,387 @@ +> 模板版本:v0.4.0 + +

+

@react-native-ohos/react-native-extra-dimensions

+

+

+ + Supported platforms + + + License + +

+ +本项目基于 [@react-native-community/react-native-extra-dimensions-android](https://github.com/Sunhat/react-native-extra-dimensions-android) 开发。 + +该第三方库的仓库在 Github,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/react-native-extra-dimensions` 版本所属关系如下: + +| 三方库名称 | 三方库版本 | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | +| @react-native-ohos/react-native-extra-dimensions | 1.2.5-rc.1 | [Git Releases]() | 0.72, 0.77| 否 | API12+ | 1.2.4 | + +## 1. 安装与使用 + +进入到工程目录并输入以下命令: + + + +#### **npm** + +```bash +npm install @react-native-ohos/react-native-extra-dimensions +``` + +#### **yarn** + +```bash +yarn add @react-native-ohos/react-native-extra-dimensions +``` + + + +下面的代码展示了这个库的基本使用场景: + +> [!WARNING] 使用时 import 的库名不变。 + +```js +import React, { useState, useEffect } from 'react'; +import { + SafeAreaView, + ScrollView, + StatusBar, + StyleSheet, + Text, + View, +} from 'react-native'; +import ExtraDimensions from 'react-native-extra-dimensions'; + +function App(): JSX.Element { + const realWindowHeight = ExtraDimensions.getRealWindowHeight(); + const realWindowWidth = ExtraDimensions.getRealWindowWidth(); + const statusBarHeight = ExtraDimensions.getStatusBarHeight(); + const softMenuBarHeight = ExtraDimensions.getSoftMenuBarHeight(); + const softMenuBarEnabled = !!ExtraDimensions.isSoftMenuBarEnabled(); + + return ( + + + + + ExtraDimensions Demo + React Native for HarmonyOS + + + + 屏幕尺寸 + + + + + + 系统栏高度 + + + + + + 导航栏状态 + + + + + + ); +} + +interface InfoRowProps { + label: string; + value: string; + highlight?: boolean; +} + +function InfoRow({ label, value, highlight }: InfoRowProps): JSX.Element { + return ( + + {label} + {value} + + ); +} + +interface CodeBlockProps { + code: string; +} + +function CodeBlock({ code }: CodeBlockProps): JSX.Element { + return ( + + {code} + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: '#f5f5f5', + }, + scrollContent: { + padding: 16, + }, + header: { + marginBottom: 24, + paddingVertical: 16, + backgroundColor: '#fff', + borderRadius: 12, + paddingHorizontal: 20, + shadowColor: '#000', + shadowOffset: { width: 0, height: 2 }, + shadowOpacity: 0.1, + shadowRadius: 4, + elevation: 3, + }, + title: { + fontSize: 28, + fontWeight: 'bold', + color: '#333', + }, + subtitle: { + fontSize: 14, + color: '#666', + marginTop: 4, + }, + section: { + backgroundColor: '#fff', + borderRadius: 12, + padding: 16, + marginBottom: 16, + shadowColor: '#000', + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.05, + shadowRadius: 2, + elevation: 2, + }, + sectionTitle: { + fontSize: 18, + fontWeight: '600', + color: '#333', + marginBottom: 12, + }, + infoRow: { + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + paddingVertical: 8, + borderBottomWidth: 1, + borderBottomColor: '#f0f0f0', + }, + label: { + fontSize: 14, + color: '#666', + flex: 1, + }, + value: { + fontSize: 16, + fontWeight: '500', + color: '#333', + }, + highlightValue: { + color: '#007AFF', + fontWeight: '600', + }, + codeBlock: { + backgroundColor: '#f8f8f8', + borderRadius: 8, + padding: 12, + marginTop: 8, + borderLeftWidth: 3, + borderLeftColor: '#007AFF', + }, + code: { + fontFamily: 'monospace', + fontSize: 13, + color: '#333', + lineHeight: 20, + }, +}); + +export default App; +``` + +## 2. Link + +| | 是否支持autolink | RN框架版本 | +|--------------------------------------|-----------------|------------| +| 1.0.0 | 否 | 0.72/0.77 | + +使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md + +如您使用的版本支持 Autolink,并且工程已接入 Autolink,可跳过ManualLink配置。 +
+ ManualLink: 此步骤为手动配置原生依赖项的指导 + +首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`。 + +### 2.1. Overrides RN SDK + +为了让工程依赖同一个版本的 RN SDK,需要在工程根目录的 `oh-package.json5` 添加 overrides 字段,指向工程需要使用的 RN SDK 版本。替换的版本既可以是一个具体的版本号,也可以是一个模糊版本,还可以是本地存在的 HAR 包或源码目录。 + +关于该字段的作用请阅读[官方说明](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#zh-cn_topic_0000001792256137_overrides) + +```json +{ + "overrides": { + "@rnoh/react-native-openharmony": "^0.72.38" // ohpm 在线版本 + // "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // 指向本地 har 包的路径 + // "@rnoh/react-native-openharmony" : "./react_native_openharmony" // 指向源码路径 + } +} +``` + +### 2.2. 引入原生端代码 + +目前有两种方法: + +- 通过 har 包引入; +- 直接链接源码。 + +方法一:通过 har 包引入(推荐) + +> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 + +打开 `entry/oh-package.json5`,添加以下依赖 + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + "@react-native-ohos/react-native-extra-dimensions": "file:../../node_modules/@react-native-ohos/react-native-extra-dimensions/harmony/extra_dimensions.har" + } +``` + +点击右上角的 `sync` 按钮 + +或者在命令行终端执行: + +```bash +cd entry +ohpm install +``` + +方法二:直接链接源码 + +> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) + +### 2.3. 配置 CMakeLists 和引入 ExtraDimensionsPackage + +打开 `entry/src/main/cpp/CMakeLists.txt`,添加: + +```diff +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") + +# RNOH_BEGIN: manual_package_linking_1 ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-extra-dimensions/src/main/ets/cpp" ./extra_dimensions) +# RNOH_END: manual_package_linking_1 + +# RNOH_BEGIN: manual_package_linking_2 ++ target_link_libraries(rnoh_app PUBLIC rnoh_extra_dimensions) +# RNOH_END: manual_package_linking_2 +``` + +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: + +```diff +#include "RNOH/PackageProvider.h" +#include "generated/RNOHGeneratedPackage.h" ++ #include "RNOHExtraDimensionsPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), ++ std::make_shared(ctx), + }; +} +``` + +### 2.4. 在 ArkTs 侧引入 ExtraDimensionsPackage + +打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: + +```diff +import type {RNPackageContext, RNPackage} from '@rnoh/react-native-openharmony/ts'; ++ import { ExtraDimensionsPackage } from '@react-native-ohos/react-native-extra-dimensions/ts'; + +export function createRNPackages(ctx: RNPackageContext): RNPackage[] { + return [ ++ new ExtraDimensionsPackage(ctx) + ]; +} +``` + +### 2.5. 运行 + +点击右上角的 `sync` 按钮 + +或者在命令行终端执行: + +```bash +cd entry +ohpm install +``` + +然后编译、运行即可。 +
+ +## 3. 约束与限制 + +### 3.1. 兼容性 + +请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-ohos/react-native-extra-dimensions Releases]() + +本文档内容基于以下版本验证通过: + +1. RNOH: 0.72.96; SDK: HarmonyOS-6.0.0.47 (API Version 22); IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; +2. RNOH: 0.72.28; SDK: HarmonyOS-6.0.0.47 (API Version 22); IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; +3. RNOH: 0.77.18; SDK: HarmonyOS-6.0.0.47 (API Version 22); IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; + +### 3.2. 编译运行API要求 + +> [!TIP] 当前三方库所有版本均已实现版本隔离,支持在 `API12+` 工程编译,及 `API12+` ROM运行。 + +## 4. 属性 + +> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 + +> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 + +### API 列表 + +| Function | Description | Return Type | Platform | HarmonyOS Support | +| :---------------------: | :------------------: | :------------------: | :------: | :---------------: | +| getRealWindowHeight | 获取实际窗口高度 | number | All | Yes | +| getRealWindowWidth | 获取实际窗口宽度 | number | All | Yes | +| getStatusBarHeight | 获取状态栏高度 | number | All | Yes | +| getSoftMenuBarHeight | 获取软导航栏高度 | number | All | Yes | +| isSoftMenuBarEnabled | 判断软导航栏是否启用 | boolean | All | Yes | + +## 5. 遗留问题 + +暂无 + +## 6. 其他 + +暂无 + +## 7. 开源协议 + +本项目基于 [The ISC License (ISC)](https://github.com/Sunhat/react-native-extra-dimensions-android/blob/master/LICENSE.md) ,请自由地享受和参与开源。 \ No newline at end of file -- Gitee