React Native theorytheory 0/50 · 0%
Native APIs · hard

38. Bridging native modules

Exposing native code to JavaScript.

When no JS library covers a need (e.g. a native secure enclave signing API), you write a native module: platform code exposing methods that JavaScript can call asynchronously.

// iOS (Swift, simplified)
@objc(SecureSigner)
class SecureSigner: NSObject {
  @objc func sign(_ message: String, resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
    // ... platform signing logic ...
    resolver(signatureHex)
  }
}
// JS side
import { NativeModules } from "react-native";
const { SecureSigner } = NativeModules;
const sig = await SecureSigner.sign("hello");

The newer architecture (TurboModules + Fabric via JSI) replaces the older async bridge with direct, synchronous-capable JS-to-native calls, reducing serialization overhead for performance-sensitive native code.

Check your understanding

  1. 1. Why would you write a custom native module?

  2. 2. What does NativeModules expose?

  3. 3. What does the new architecture (TurboModules/JSI) improve?