文件最后提交记录最后更新时间
docs: turn off the obfuscation feature. Co-authored-by: 谢代荣<xiedairong@huawei.com> # message auto-generated for no-merge-commit merge: !1771 merge 77-docs into 0.77.1-rc.1-ohos docs: turn off the obfuscation feature. Created-by: xiedrsz Commit-by: 谢代荣 Merged-by: huangyouhua Description: docs: turn off the obfuscation feature. See merge request: openharmony-sig/ohos_react_native!17716 个月前
!2799 merge 0518 into main docs(Docs):update samples Created-by: fangyygw Commit-by: fangyygw Merged-by: openharmony_ci Description: ## 变更类型 请在对应类型(请勿多选)前打 ,**仅可选择一项**: - [ ] feat(新增功能,对应 Changelog Added) - [ ] fix(修复 Bug,对应 Changelog Fixed) - [x] docs(文档变更,对应 Changelog Documentation) - [ ] refactor(代码重构,对应 Changelog Changed) - [ ] perf(性能优化,对应 Changelog Performance) - [ ] test(测试相关,不进入 Changelog) - [ ] chore(构建/工具链/依赖,不进入 Changelog) - [ ] deprecated(标记弃用,对应 Changelog Deprecated) - [ ] removed(移除功能,对应 Changelog Removed) - [ ] security(安全修复,对应 Changelog Security) ## 变更内容 - 简要描述本次变更的具体内容、解决的问题; - 若为**破坏性变更**,请详细说明: - 影响范围(哪些 API/配置/功能被修改); - 用户适配方案(旧版→新版的替换步骤) ## 测试步骤 <!-- 如何测试这条PR。例如: 1. 打开Tester工程. 2. 执行npm run start命令. ... --> ## 测试情况 - [ ] 已通过本地完整测试(单元测试/集成测试) - [ ] 已通过 CI 自动构建与测试 - [x] 已补充/更新对应的测试用例 - [x] 已在目标环境(如 手机/平板)验证功能 - [ ] 已在最低兼容API版本验证可用性 ## 合入前自检 <!-- 请在合入前根据以下条例进行自检 自检完成后在[ ]内填入"x", 例如: - [x] 不涉及非兼容性变更;若涉及,已通过相应评审。 --> - [ ] 不涉及非兼容性变更;若涉及,已通过相应评审。 - [ ] 不涉及性能或已进行性能测试且无性能劣化。 - [ ] 符合对应的编码规范。 - [ ] 无敏感信息泄露,如密码、密钥等。 - [ ] 不涉及文档更新,或已更新了文档。 - [ ] 针对可测试性要求,已增加必要的自测用例、合理的日志记录或Trace信息。 - [ ] 不存在非法的文件引入,包括图片和代码等 See merge request: OpenHarmony-RN/ohos_react_native!27995 天前
docs: Add sample project and docs Co-authored-by: zheng-jun-feng<949815885@qq.com> # message auto-generated for no-merge-commit merge: merge 0.77.1-rc.1-ohos into 0.77.1-rc.1-ohos docs: Add sample project and docs Created-by: zheng-jun-feng Commit-by: zheng-jun-feng Merged-by: huangyouhua Description: Port sample and doc to 77 branch See merge request: openharmony-sig/ohos_react_native!10041 年前
docs: Add sample project and docs Co-authored-by: zheng-jun-feng<949815885@qq.com> # message auto-generated for no-merge-commit merge: merge 0.77.1-rc.1-ohos into 0.77.1-rc.1-ohos docs: Add sample project and docs Created-by: zheng-jun-feng Commit-by: zheng-jun-feng Merged-by: huangyouhua Description: Port sample and doc to 77 branch See merge request: openharmony-sig/ohos_react_native!10041 年前
docs(Docs):update samples update samples Signed-off-by: fangyygw <fang_zhen@hoperun.com> 7 天前
docs(Docs):update samples update samples Signed-off-by: fangyygw <fang_zhen@hoperun.com> 7 天前
README.md

Running a Sample Project

Running Guide

​This demo contains a OpenHarmony project directory SampleApp and a ReactNative project directory SampleProject. You need to use SampleProject to generate a bundle and load the bundle to SampleApp to run the OpenHarmony project.

Configure an environment variable:

​ The default version of SampleApp is CAPI. For this version, you need to set RNOH_C_API_ARCH to 1. For details about how to set environment variables, see Configuring the CAPI Version Environment Variable.

Configure a React Native project:

  1. Run pnpm i in the SampleProject/MainProject directory to install the dependency.

  2. Run pnpm dev:all to generate a local bundle. Run the command to generate the bundle.harmony.js and assets folders in the SampleApp/entry/src/main/resources/rawfile directory.

Configure a OpenHarmony project:

  1. Specify the version of react-native-openharmony in entry/oh-package.json5 and oh-package.json5in the root.
  2. Open SampleApp in DevEco Studio and wait for the automatic project synchronization to complete (for manual synchronization, execute Sync and Refresh Project);
  3. Click File > Project Structure > Signing Configs, log in and complete the signing.
  4. Click run in the upper right corner to start the project.

Project Introduction

​ On the React Native side, an empty project consists of HomePage, Goods, test, and Detail modules. On OpenHarmony, the bundles of the four service modules are loaded to create the corresponding RNSurfaces, which are then embedded into the ArkUI page components to build the OpenHarmony page.

  • HomePage: The third-party library react-native-pager-view is used to implement the split-view layout of tabs.
  • Goods: The scrollbar component on the top is customized by ArkUI and imported and rendered on the RN side. The bottom provides the examples of using multiple TurboModule methods.
  • Test: Multiple common code example pages are provided.
  • Detail: The ArkUI and RN components are used for hybrid rendering. In the RN component, the data transferred from the OpenHarmony side is used for style and content rendering.
HomePage Goods Test Detail
HomePage Goods Test Detail

React Native Project Structure

​ The React Native service code of an empty project is stored in the SampleProject/MainProject/src/bundles directory, including the HomePage, Goods, Detail, basic, and test directories.

  • React Native component code:

    Take the Goods module as an example. Under the SampleProject/MainProject/src/bundles/Goods directory, App() in the GoodsMainPage.tsx file is called to create a root view, and AppRegistry.registerComponent('Goods', () => AppGoods) in the GoodsMainPage.tsx file is called to register the root view and provide a reference API for the generated good.harmony.bundle. In addition, all module components are registered in MainProject/index.js and provided for the Metro server.

  • Configure the local bundle command:

    Under the SampleProject/MainProject directory, the config.js file is created to configure the bundles of all modules. For example, the configuration file of the Goods module is goods.config.js. The package.json file in the same directory implements the bundle commands of all modules, which are encapsulated in dev:all.

    image

OpenHarmony Project Structure

​ The Tabs component is used to build the basic page framework of the OpenHarmony project, and is created in the MultiHome component, containing three TabContents: HomePage, Goods, and Test.

image

​ The HomePage and Goods components contain a BaseRN component (Metro uses the MetroBaseRN component), which is a basic component that encapsulates the RNSurface component and is used to load the specified React Native module view.

image

Using TurboModule

​ Create a RNInstance, transfer the createRNPackages implemented in RNPackagesFactory, and create the corresponding SampleTurboModulePackage.

image

​ Define the API to be implemented by SampleTurboModule in basic/SampleTurboModule.tsx on the React Native side and export the SampleTurboModule instance.

image

​ In GoodsMainPage.tsx, use SampleTurboModule to call the method defined in the protocol for OpenHarmony communication.

image

​ Implement the API defined on the React Native side in the OpenHarmony SampleTurboModule.ts, and use emitter to send the message of redirecting to the Detail page.

image

Using a Custom Component

​ Create a custom component ButtonView in the entry/src/main/cpp/ButtonView directory. The directory contains all code of the component.

​ Add the mapping of the custom component to the src/main/cpp/SampleTurboModulePackage.cpp method.

image

​ Define the JSI API of ButtonView in basic/ButtonView.tsx on the React Native side.

image

​ Use custom components in GoodsMainPage.tsx.

image

Using a Third-Party Library

​ The home page view of this project is developed using the react-native-pager-view library. You need to add the third-party library dependency by following the instructions in Running Guide.

​ You can use a third-party library in either of the following ways:

  • Method 1: Use the third-party library of the ArkTS version in the C API version. Currently, RN supports only the third-party libraries of the ArkTS version of leaf nodes. Third-party libraries of container nodes are not supported. Specifically, add the third-party library component mapping, for example, FastImage, to the buildCustomComponent method on the OpenHarmony side. Note that you need to add a Stack component externally and set position = (0,0) for the mapping.

    image

  • Method 2: Directly use the third-party library of the CPP version. In this method, no other operation is required.

    Use the PagerView component of the third-party library in the SamplePackage/MainProject/src/bundles/HomePage/HomePage.tsx file on the React Native side.

    image

Metro

​ In this project, Metro is used to load bundles. To use Metro, please refer to Running Guide. You can modify the code on the React Native side and save it to refresh the application UI content in real time. For details, see Metro.

image

Reload and LogBox

​ The processing needs to be performed on the service side. For details, see rnoh/src/main/ets/RNApp.ets.

About the Release Version

In this release, a HAR package named rnoh_release.har is added. Compared with rnoh.har (in the debug version), the differences are as follows: Size: In the release version, the C++ source code is converted into a binary .so file. Therefore, the package size is much smaller. Application build speed: The main application build speed is significantly accelerated because the HAR package of the release version is referenced during precompilation. Function: The debugging function is removed from the release version. Therefore, if you want to use the JS breakpoint for debugging, you are advised to use the debug version first. Usage: The usage of the release version is slightly different from that of the debug version. For details, see the following information.

The usage of the release version is basically the same as that in Creating an OpenHarmony Project. The only difference is that, in the section , you need to rename the MyApplicationReplace/entry/src/main/cpp/CMakeLists - release.txt file CMakeLists.txt when replacing the entry folder.

For details about the differences between CMakeLists - release.txt and CMakeLists.txt, see the comments in CMakeLists - release.txt.

NOTE

  1. If a CMake error is reported, check whether the file is of the latest version.
  2. If an include file error is reported, check whether the rnoh.har file is of the latest version.