JavaScript to Native Communication in React Native

Frameworks like React Native enable JavaScript code to control native platform features on iOS and Android by bridging two distinct runtime environments. This article explains the mechanisms behind this communication, detailing the traditional JSON-based asynchronous bridge, the transition to the modern JavaScript Interface (JSI), and how these systems coordinate JavaScript threads with native platform threads to execute native APIs and render user interfaces.

The Dual-Runtime Architecture

React Native applications execute in two primary environments running side-by-side:

  1. The JavaScript Runtime: Executes application business logic using an engine such as Hermes, V8, or JavaScriptCore on a dedicated JavaScript thread.
  2. The Native Platform: Executes platform-specific code (Objective-C/Swift on iOS, Java/Kotlin on Android) on the main UI thread and background native threads.

Because these two runtimes use completely different memory spaces and instruction sets, direct function calls between them require a specialized communication layer.

The Legacy Approach: The React Native Bridge

Historically, React Native relied on a centralized, asynchronous message-passing system known as The Bridge.

How the Bridge Works

Limitations of the Bridge

The Modern Architecture: JavaScript Interface (JSI)

Modern React Native replaces the serialized bridge with the JavaScript Interface (JSI), a lightweight, general-purpose C++ layer that allows the JavaScript engine to interact directly with native code.

Direct Host Object References

JSI exposes native C++ objects directly to the JavaScript runtime as HostObjects.

Instead of sending serialized messages through a pipe: * Native modules are implemented in C++ or wrapped in a C++ interface. * JavaScript holds a direct memory reference to the C++ HostObject. * JavaScript can invoke native methods directly using standard JavaScript function call syntax (global.nativeModule.method()).

Key Benefits of JSI

TurboModules and Fabric: JSI in Practice

The modern communication pipeline relies on two systems built on top of JSI: