Skip to main content

Integrating React Native into Existing Apps

Learn how to integrate React Native into your existing native iOS or Android application. This allows you to gradually adopt React Native without rewriting your entire app.

Overview

React Native can be embedded into existing native applications, allowing you to:
  • Develop new features in React Native while keeping existing native code
  • Gradually migrate native screens to React Native
  • Share code between iOS and Android for new features
  • Leverage native modules and React Native simultaneously

Integration Approach

There are two main approaches:
  1. Full App Integration: Add React Native to your entire app build process
  2. Screen-by-Screen: Integrate React Native for specific screens or features

Android Integration

Prerequisites

  • Existing Android application (Android 6.0+, API level 24+)
  • Node.js installed
  • React Native package

Setup Steps

1

Add React Native to package.json

Create a package.json in your project root:
Install dependencies:
2

Configure build.gradle

Update your app’s build.gradle:
3

Implement ReactApplication

Modify your Application class:
4

Create React Native Activity

5

Launch from native code

From any Activity:

iOS Integration

Prerequisites

  • Existing iOS application (iOS 13.4+)
  • CocoaPods installed
  • Node.js installed

Setup Steps

1

Install React Native dependencies

Create package.json and install:
2

Configure Podfile

Create or update ios/Podfile:
Install pods:
3

Create RCTRootView in ViewController

4

Configure App Transport Security

Update Info.plist for Metro bundler access:

React Native Code

Create index.js in your project root:

Running the Integrated App

1

Start Metro bundler

2

Build and run native app

Android:
iOS: Open Xcode and click Run, or:

Communication Between Native and React Native

Passing Data to React Native

Android:
iOS:

Native Modules

Create custom native modules to expose native functionality to React Native:

Best Practices

  1. Start Small: Begin by integrating one screen or feature
  2. Use Native Modules: Leverage existing native code through native modules
  3. Handle Lifecycle: Properly manage React Native lifecycle in your native app
  4. Test Thoroughly: Test integration points between native and React Native
  5. Performance: Monitor performance impact of the integration

Troubleshooting

Metro Bundler Connection Issues

Ensure your device/emulator can reach Metro:
  • Android: adb reverse tcp:8081 tcp:8081
  • iOS: Check firewall settings

Native Module Not Found

Rebuild native app after adding dependencies:

Next Steps