RN integrates with existing native apps

Source: Internet
Author: User

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
    1. Set up a dependency and structure directory for RN
    2. Developing RN components with JS
    3. Add a Reactrootview to the Android app, which will act as a container for the RN component
    4. Open RN server and run native app
    5. Check that the RN component is working properly
Pre-knowledge

According to the official guidelines, set up the RN development environment.

    1. 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)
    2. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.