React Native lets you build mobile apps using JavaScript. It uses a special system to connect your JavaScript code with native mobile parts so your app feels fast and smooth.
React Native architecture (bridge, new architecture)
/* React Native uses a Bridge to connect JavaScript and native code */
// Old architecture:
JavaScript thread <--> Bridge <--> Native thread
// New architecture (Fabric + TurboModules):
JavaScript thread <--> JS Interface <--> Native Modules + Fabric RendererThe Bridge is like a messenger between JavaScript and native code.
The New Architecture improves speed by reducing the bridge and using direct calls.
// Old Bridge example
// JS sends a command to native to show an alert
NativeModules.AlertManager.showAlert('Hello!')// New Architecture uses TurboModules // JS calls native module directly without bridge delay const alertModule = require('AlertModule'); alertModule.showAlert('Hello!')
This simple app shows a button. When you press it, it uses React Native's native alert feature. Behind the scenes, React Native uses its architecture to connect the JavaScript button press to the native alert popup.
import React from 'react'; import {Button, Alert, View} from 'react-native'; export default function App() { const showAlert = () => { Alert.alert('Hello from React Native!'); }; return ( <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}> <Button title="Press me" onPress={showAlert} accessibilityLabel="Show alert button" /> </View> ); }
The old bridge sends messages back and forth, which can slow down complex apps.
The new architecture uses Fabric for UI and TurboModules for faster native calls.
Understanding this helps you write better React Native apps and debug performance issues.
React Native connects JavaScript and native code using a bridge system.
The new architecture improves speed by reducing bridge overhead.
Knowing this helps you build faster and smoother mobile apps.
Practice
bridge in React Native architecture?Solution
Step 1: Understand the bridge concept
The bridge acts as a communication layer between JavaScript and native code in React Native.Step 2: Identify the bridge's role
It allows JavaScript to send commands and receive data from native modules, enabling cross-platform functionality.Final Answer:
It connects JavaScript code with native platform code. -> Option CQuick Check:
Bridge = Connect JS and native [OK]
- Thinking bridge compiles JavaScript
- Confusing bridge with navigation or styling
- Assuming bridge handles UI rendering directly
Solution
Step 1: Recall the new architecture goal
The new React Native architecture aims to make apps faster by optimizing communication.Step 2: Understand how it improves performance
It reduces the overhead caused by the bridge, making interactions between JS and native code more efficient.Final Answer:
It improves performance by reducing bridge overhead. -> Option DQuick Check:
New architecture = less bridge overhead [OK]
- Believing it removes native code completely
- Thinking it replaces JavaScript language
- Confusing it with webview-based rendering
NativeModules.ExampleModule.getData() in React Native's old architecture?Solution
Step 1: Understand NativeModules call behavior
In old React Native, calls to native modules go through the bridge asynchronously.Step 2: Identify the effect of the bridge
The bridge queues and sends messages between JS and native code, causing asynchronous behavior.Final Answer:
The call is sent over the bridge asynchronously. -> Option AQuick Check:
Old architecture calls = async bridge [OK]
- Assuming direct synchronous native calls
- Thinking it causes syntax errors
- Confusing with webview handling
Solution
Step 1: Identify cause of slowness
Many bridge calls cause overhead and slow down the app.Step 2: Choose the right fix
The new architecture uses TurboModules and Fabric to reduce bridge overhead and improve speed.Final Answer:
Switch to the new architecture with TurboModules and Fabric. -> Option BQuick Check:
New architecture reduces bridge calls [OK]
- Thinking TypeScript improves bridge performance
- Removing native modules breaks functionality
- Using webview slows app further
Solution
Step 1: Understand Fabric's role
Fabric is the new rendering system that manages UI components natively.Step 2: Compare with old bridge system
Old system sent UI updates over the bridge causing delays; Fabric reduces this by direct native management.Final Answer:
By using Fabric to directly manage UI components on the native side. -> Option AQuick Check:
Fabric improves UI by native management [OK]
- Thinking JavaScript is compiled to native code
- Believing native code is removed
- Confusing Fabric with webview rendering
Ready to prove it?
Pass the test and this pattern moves unknown
