文件最后提交记录最后更新时间
[chore]: updated to version 6.1.0.370(0.72.131) Signed-off-by: dengjiangtao <1442949715@qq.com> 2 个月前
fix: version in release note & node version Co-authored-by: gyange<gyange@163.com> # message auto-generated for no-merge-commit merge: !2076 merge master into master fix: version in release note & node version Created-by: gyange Commit-by: gyange Merged-by: openharmony_ci Description: <!-- 请在合并之前删除注释代码,以避免将其包含在GIT历史记录中 --> # 描述 <!-- 简要描述PR的目的,例如: 这条PR主要实现metro局域网内远程调试的功能. --> # 变更日志 <!-- 列出可包含在变更日志中的要点的主要变更。 不要列出内部更改。请以下列开头来写每个变更点: - added - fixed - deprecated - removed 如果是一条新增属性的变更,则以[added]开头,例如: - [added] FlatList组件新增inverted属性 --> # 测试步骤 <!-- 如何测试这条PR。例如: 1. 打开Tester工程. 2. 执行npm run start命令. ... --> # 合入前自检 <!-- 请在合入前根据以下条例进行自检 自检完成后在[ ]内填入"x", 例如: - [x] 不涉及非兼容性变更;若涉及,已通过相应评审。 --> - [x] 不涉及非兼容性变更;若涉及,已通过相应评审。 - [x] 不涉及性能或已进行性能测试且无性能劣化。 - [x] 符合对应的编码规范。 - [x] 不涉及文档更新,或已更新了文档。 - [ ] 针对可测试性要求,已增加必要的自测用例、合理的日志记录或Trace信息。 - [ ] 不存在非法的文件引入,包括图片和代码等 - [ ] 本PR已经在77分支开启PR或不需要在77分支合入 - 如需合入77分支,PR地址: See merge request: openharmony-sig/ohos_react_native!20764 个月前
Capture Bundle and Sample Project Add Preview Signed-off-by: Galen wei <1947612015@qq.com> 1 年前
Add English interface diagram for running the Sample project Signed-off-by: Galen wei <1947612015@qq.com> 1 年前
[doc]: Add the step of obtaining the signature before executing run. Co-authored-by: jarayard<694161290@qq.com> # message auto-generated for no-merge-commit merge: merge master into master [doc]: Add the step of obtaining the signature before executing run. Created-by: jarayard Commit-by: jarayard Merged-by: huangyouhua Description: ## Description Add the step of obtaining the signature before executing run. ## Checklist - [x] Does not involve incompatible changes; if involved, has been reviewed accordingly. - [x] Does not impact performance, or performance testing has been conducted without degradation. - [x] Complies with the relevant coding standards. - [ ] Does not involve documentation updates, or the documentation has been updated. - [x] Meets testability requirements with necessary self-test cases, appropriate logging, or trace information added. - [x] No illegal file inclusions exist, such as images or code. See merge request: openharmony-sig/ohos_react_native!116311 个月前
[doc]: Add the step of obtaining the signature before executing run. Co-authored-by: jarayard<694161290@qq.com> # message auto-generated for no-merge-commit merge: merge master into master [doc]: Add the step of obtaining the signature before executing run. Created-by: jarayard Commit-by: jarayard Merged-by: huangyouhua Description: ## Description Add the step of obtaining the signature before executing run. ## Checklist - [x] Does not involve incompatible changes; if involved, has been reviewed accordingly. - [x] Does not impact performance, or performance testing has been conducted without degradation. - [x] Complies with the relevant coding standards. - [ ] Does not involve documentation updates, or the documentation has been updated. - [x] Meets testability requirements with necessary self-test cases, appropriate logging, or trace information added. - [x] No illegal file inclusions exist, such as images or code. See merge request: openharmony-sig/ohos_react_native!116311 个月前
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 npm i @react-native-oh/react-native-harmony@x.x.x in the SampleProject/MainProject directory to install the dependency.

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

  3. Use Metro to generate a bundle. If you want to use the Metro service to update bundles in real time, connect to a real device and run the following commands:

hdc rport tcp:8081 tcp:8081
npm run start

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 run 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.