In this lesson, you will learn how JavaScript objects act as "remote control" proxies to trigger logic residing in the native (iOS/Android) layer.
The Problem: Language Isolation
As we’ve discussed in previous lessons, JavaScript runs in its own thread, completely isolated from the native environment. Because JavaScript cannot directly talk to Objective-C, Swift, or Java/Kotlin, it needs a middleman. This is where the Native Module Proxy System comes into play.
What is a Proxy?
Think of a proxy like a diplomatic translator. When you call a native feature from your JavaScript code—like accessing the device camera or the file system—you aren’t actually talking to the camera hardware. Instead, you are calling a plain JavaScript object that represents the native module.
When you write:
import { NativeModules } from 'react-native';
const MyCustomModule = NativeModules.MyCustomModule;
MyCustomModule.doSomethingNative();
The MyCustomModule object is a Proxy. It doesn’t contain the logic for doSomethingNative(). When the code executes, the proxy records the method name and the arguments you passed. It then packages these up into a JSON-like message and sends them across the Bridge to the native side.
How the Bridge Completes the Link
- Registration: During the Host Platform Bootstrapping phase, the native side registers a list of available modules and their methods with the JavaScript engine.
- Proxy Creation: The JavaScript side creates empty "shell" objects (proxies) for each of these registered modules.
- Execution: When you call a method on the proxy, the proxy doesn't run code; it triggers the bridge to serialize the request, which then travels to the native layer. The native layer performs the actual work and returns the result (if any) back through the bridge.
In essence, the proxy system allows your JavaScript codebase to interact with native hardware as if it were just another local object, hiding the complexity of the bridge communication behind a familiar interface.
Key Takeaway: The Native Module Proxy is a JavaScript placeholder that translates your function calls into messages sent across the bridge, allowing the JavaScript thread to remotely trigger execution in the native environment.