Https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
RN is well-supported for adding RN components to a native app. With simple steps, we can add features, components, etc. of the RN base. Follow the example of Android.
Key ideas
- Set up a dependency and structure directory for RN
- Developing RN components with JS
- Add a Reactrootview to the Android app, which will act as a container for the RN component
- Open RN server and run native app
- Check that the RN component is working properly
Pre-knowledge
According to the official guidelines, set up the RN development environment.
- Sets the directory structure. Copy the Android project to the Android folder in the RN project root directory (there is already a folder in the initialized RN project with the initial Android project content)
- Install JS dependency. Create a Package.json in the RN project, as follows (the initial RN project also has this content)
{ "name": "Myreactnativeapp", "version": "0.0.1", true, "Scripts": { "start": "Node node_modules/react-native/local-cli/cli.js start" }}
Then install react and react-native dependencies
NPM install--save [email protected] react-native
Add RN to the app to configure the MAVEN repository
Add RN dependency to Build.gradle (if you want to use the specified version of RN, you can replace + with the corresponding RN version number in NPM):
Dependencies { ' com.android.support:appcompat-v7:23.0.1 ' ... // From node_modules.}
Light and light above so configured, Gradle will (?) This dependency cannot be found, and a repository in Build.gradle is required to tell Gradle where to look for dependencies (make sure to add to the Allproject block, and above all other maven repositories. Also make sure that the following URLs are correct):
allprojects { repositories { maven { // all of React Native (JS, Android binaries) Is installed from npm url "$rootDir/.. /node_modules/react-native/android " } ... } ...}
Configure permissions
Add the following to the Androidmanifest.xml manifest file:
<uses-permission android:name= "Android.permission.INTERNET"/>
If you need to open the Developer menu in the native app, you also need to add it to the manifest file (if you want to publish it, remove the following line):
<activity android:name= "Com.facebook.react.devsupport.DevSettingsActivity"/>
Code integration
RN integrates with existing native apps