Example React Native application for Oniro/OpenHarmony.
The aim of this project is to create a template for new React Native applications for Open Harmony, as well as to present the fundamentals of building cross-platform applications in React Native.
The code is divided into two directories:
- oh-app: OpenHarmony application template serving as a container for the React Native app.
- rnoh-app: The actual React Native app embedded in the OH app.
The code of the sample application has already been prepared and adapted for compilation with RN, it can serve as a template for other apps.
- Download project and dependent libraries:
$ git clone https://github.com/eclipse-oniro4openharmony/app-rnoh-example.git
$ cd app-rnoh-example/rnoh-app
$ npm i @react-native-oh/react-native-harmony
$ cd ../oh-app
$ ohpm i @rnoh/react-native-openharmony
- Create a JS bundle with RN app:
$ cd ../rnoh-app
$ npm run dev
- Copy generated bundle to the OH app:
Copy the entire contents of the directory:
rnoh-app/harmony/entry/src/main/resources/rawfile
to the directory:
oh-app/entry/src/main/src/main/resources/rawfile
- Compile the oh-app with the DevEco. Choose
File > Sync and Refresh Projectbefore compilation.
The project in this repository is already properly configured and adapted. You can use it as a template for your application. However, if you want to create an RNOH application from scratch, you must follow certain steps to embed the React Native application within an Open Harmony application that will serve as a container and bridge between the system and the RN application.
In case of project compilation issues, go directly to the Troubleshooting section.
