React Native 0.76 is here with a huge upgrade known as the New Architecture. This overhaul brings exciting changes and more efficient ways to build fast, responsive, and user-friendly mobile apps.
Here’s a breakdown of what this New Architecture brings and what it means for developers:
Why a New Architecture?
The original React Native structure used a JavaScript Bridge to connect JavaScript code with native code on mobile platforms (iOS and Android). This bridge was asynchronous, which could cause delays in updates, especially when many updates were needed quickly. This led to performance issues, as apps had trouble maintaining smooth frames per second (FPS) or handling real-time updates seamlessly.
The New Architecture in 0.76 addresses these issues by enabling synchronous and asynchronous updates. It’s designed to be faster and better at handling complex interactions, and it lets React Native apps act even more like native apps.
Key Components of the New Architecture
New Native Module System
- React Native now has a Native Module System that connects JavaScript with the native code directly, without using the bridge. This enables faster data transfer and synchronous communication between JavaScript and native layers.
- Native Modules are also type-safe. This means the system will check that the right types of data are being sent and received between JavaScript and native code, which reduces bugs and crashes.
- Modules are lazily loaded, meaning they’re only loaded into memory when needed, which speeds up app startup.
New Renderer
- The new Renderer allows React Native to simultaneously process multiple updates on different threads. It’s designed to handle high-priority tasks (like user inputs) and lower-priority tasks (like animations) independently, so the app remains smooth and responsive.
-
Concurrent React features, like
Suspense
andstartTransition
, are now fully supported, making it easy to separate immediate updates (such as typing) from background updates (like animations), improving the user experience. - The Renderer is now written in C++ and is shared across all platforms, making it consistent and optimized across iOS, Android, Windows, and macOS.
Event Loop and Browser-Like Features
- The New Architecture includes a well-defined Event Loop that aligns React Native’s behaviour more closely with web standards. Now, React Native can support web-like features, including
MutationObserver
andIntersectionObserver
, for better browser compatibility. - The event loop prioritizes urgent events over other tasks, which helps maintain smooth animations and interactions in the app.
Removing the Bridge
- By removing the bridge that previously connected JavaScript with the native code, the New Architecture minimizes delays in communication, reduces crashes, and improves error reporting.
- For backward compatibility, a lightweight interop layer is provided to support older libraries while moving apps to the New Architecture gradually.
New Features and Improvements
- Automatic Batching: React Native now automatically batches updates together, which reduces the number of renders and improves performance. With React 18’s automatic batching, many updates are grouped in a single render cycle, helping avoid lag and rendering delays.
- useLayoutEffect for Synchronous Layout: Previously, layout updates were asynchronous, causing delays. Now, with useLayoutEffect, you can read and update layout information in the same frame, ensuring tooltips and popups appear in the correct position immediately.
-
Transitions and startTransition API: React Native now distinguishes between
urgent
updates (like clicks) andnon-urgent
updates (like animations). ThestartTransition
API helps manage this, allowing smoother animations and updates that don’t interfere with immediate user interactions. -
Full Support for Suspense: The
Suspense
component is now fully supported in React Native, enabling developers to create smooth loading states for parts of their app while the rest of the app continues running normally.
The Road Ahead
With these changes, React Native apps can now handle concurrent tasks more efficiently, improve responsiveness, and use modern React features. The New Architecture represents a significant step towards making React Native even faster and more versatile across all major platforms.
React Native’s future is shaping up to be very exciting, with more improvements on the way for smoother user interfaces, better animations, and faster, more reliable apps!
Thank you for reading! Feel free to connect with me on LinkedIn or GitHub.
Top comments (0)