Blog Details
Sheikh Rownakul Islam Miraj
25 Oct 2024
6 min read
React Native has just released a massive update to its core software. This update introduces a new architecture, which is now the default in version 0.76. This is one of the biggest changes ever made to React Native, and it's going to change how we build mobile apps.
Before we dive into the new stuff, let's quickly recap what React Native is. React Native is a way to build mobile apps using JavaScript and React. It lets web developers create apps for both Android and iOS without learning new programming languages.
In the old React Native setup, there was something called a "bridge." This bridge was like a messenger between two worlds:
Every time your app needed to do something on the screen, it had to send a message across this bridge. This was slow and could cause problems, especially for things that needed to happen quickly, like animations.
The big change in the new architecture is that it gets rid of the bridge. Now, the JavaScript part of your app can talk directly to the native part. This is much faster and solves a lot of problems that developers used to face.
In the previous architectural design, implementing universal functions accessible from the JavaScript layer required a specific initialization process. This process involved setting up a module within the JavaScript environment during the application's launch phase. As a consequence, users might experience a slight lag when starting the app, as this initialization step added a small but noticeable delay to the startup sequence.
This approach, while functional, wasn't ideal from a performance standpoint. The need to initialize modules at startup time created a trade-off between functionality and app responsiveness, potentially impacting the user's first impression of the application's speed and efficiency.
The new system makes it easier to spot and fix errors, especially when your app is starting up. It also reduces crashes caused by unclear code. If your app does crash, the new React Native DevTools make it simpler to find and fix the problem.
The old system is still there for now, so you can update your app bit by bit. You don't have to change everything at once. In the future, the old system will be removed completely to make things even simpler and faster.
This new setup brings several important improvements:
a) Better Performance: Everything runs faster now. Animations are smoother, and the app feels more responsive.
b) Synchronous Operations: Before, everything had to wait for messages to cross the bridge. Now, some things can happen right away, which is great for certain types of app features.
c) More Like Web React: If you know how to use React for websites, it's now easier to use React Native for mobile apps. The two are becoming more similar.
d) Fixing Old Problems: Some issues that developers complained about for years are now fixed. For example, there was a problem with how text inputs worked that's now solved in the new architecture.
a) Layout Effect: There's a thing called useLayoutEffect that web React developers use. Now it works properly in React Native too. This helps make sure your app's layout is correct before users see it.
b) Automatic Batching: When your app needs to update multiple things at once, it now does it more efficiently. This means less work for your phone and a smoother experience for users.
Old way:
New way
c) Suspense Support: This is a feature from React that helps manage loading states in your app. It now works fully in React Native, making it easier to handle things like showing loading spinners.
d) Transition: How Transitions Work:
Urgent updates: These handle immediate interactions like typing or pressing buttons. They need to be instant to feel natural.
Transition updates: These manage larger UI changes that don't need to show every step.
The new system can handle these two types of updates separately, making your app feel smoother and more responsive.
Using Transitions:
You can use the 'startTransition' API to tell React which updates are less urgent:
import {startTransition} from 'react';
// Urgent: Update right away
setCount(input);
// Less urgent: Can be done in the background
startTransition(() => {
setNumberOfTiles(input);
});
The React Native team shared some examples of how the new architecture improves things:
a) Tooltip Example: In the old setup, if you had a tooltip (those little info boxes that pop up), it might appear in the wrong place at first and then jump to the right spot. Now, it appears in the right place immediately.
Old Way.
New way:
b) Slider Example: With a slider (like a volume control), the old setup might show jerky updates when you move it quickly. The new setup makes this much smoother. As you saw previous slider batch updates example.
If you're already using React Native, here's what you need to know:
a) Update React Native: Make sure you're using version 0.76 or newer.
b) Check Your Libraries: The React Native team has created a website where you can check if the libraries you use support the new architecture. Many already do!
c) Custom Native Code: If you wrote any custom native code (stuff in languages other than JavaScript), you might need to update it. But don't worry - there's a system in place to help your old code work with the new setup.
Looking to the Future
This new architecture is a big step forward, but the React Native team isn't stopping here. They plan to keep improving things:
a) Removing Old Code: In the future, they'll completely remove the old bridge code, making React Native even lighter and faster.
b) More Library Support: As time goes on, more and more libraries will update to fully support the new architecture.
c) Easier Native Development: The new setup makes it easier for JavaScript developers to work with native mobile features, potentially reducing the need for separate native developers on many projects.
This update to React Native is a big deal for several reasons:
a) Better Apps: The apps you build with React Native will be faster and smoother.
b) Easier Development: It's now easier for web developers to build great mobile apps.
c) Solving Old Problems: Many long-standing issues with React Native have been fixed.
d) Future Growth: This change sets up React Native for even more improvements in the future.
Whether you're a seasoned React Native developer or just thinking about getting into mobile app development, this new architecture makes React Native an even more attractive option. It brings the ease of web development closer to the performance of native mobile apps, opening up exciting possibilities for the future of mobile development.
Don’t worry, we don’t spam!