123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Technology,-Gadget-and-Science >> View Article

Deep Dive Into React Native’s New Architecture

Profile Picture
By Author: Jignen Pandya
Total Articles: 2
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

The React Native team has announced that the new architecture will be rolled out in 2022. Checkout their full blog here.

“2022 is going to be the year of the New Architecture in open source”

Since the release is just around the corner, this is a good time to understand what changes are taking place under the hood and how they might affect your React Native App.

This article aims to cover the most important changes bought by the re-architecture:

JavaScript Interface(JSI)
Fabric
Turbo Modules
CodeGen

Current Architecture

Before we get to the new architecture, let’s recap how the current one works.

Please note that I am only covering points that are relevant to understanding this blog, If you want to learn more about the current architecture, you can checkout this blog by Bianca Dragomir.
In a nutshell:

When you run a RN app, all you JavaScript code is bundled together into a package called the JS Bundle. The Native Code is kept separately.

The Execution of React Native apps happens over three threads:

1) The JavaScript thread: used ...
... by the JS Engine, to run the JS Bundle

2) The Native/UI thread: used to run the Native Modules and to handle operations like UI Rendering, user gesture events etc.

3) Additionally there is a 3rd thread called the shadow thread, which is used to calculate the Layout of Elements before rendering them on the host screen

The Communication between the JS and Native Threads is carried over an entity called the bridge. When sending data through the bridge it has to be batched(optimized) and serialized as JSON. This bridge can only handle asynchronous communication.

JavaScriptCore: It is the name of a JavaScript Engine, which is used by React Native to execute JS code.
Yoga: It is the name of a Layout engine, which is used to calculate positions of UI elements for the user’s screen.

1. JavaScript Interface (JSI)

In the current architecture, React Native uses the Bridge Module to make communication possible between the JS and Native threads. Every time data is sent across the bridge, it has to be serialized as JSON. When the data is received on the other side it must be decoded as well.

This means that the JavaScript and Native worlds are unaware of each other (ie. the JS thread cannot directly call a method on the Native thread)

Another important point to note is; messages send over the bridge are asynchronous in nature, which is a good thing for most use cases, but there are certain instances when JS code and native code needs to be in sync.

2. Fabric

Fabric is the rendering system, which will replace the current UI Manager.

In order to understand the advantages of Fabric, first let’s look at how UI is currently rendered in React Native:

When your app is run, React executes your code and creates a ReactElementTree in JavaScript. Based on this tree, the Renderer creates a ReactShadowTree in C++.

This shadow Tree is used by the Layout Engine to calculate positions of UI elements for the host screen. Once the results of Layout calculation are available, the shadow tree is transformed into HostViewTree, which comprises of Native Elements. (For example: The ReactNative element will be translated into ViewGroup in Android & UIView in iOS respectively)

Read Also:- https://www.expertappdevs.com/blog/iot-based-smart-mobile-parking-system

3. Turbo Modules

In the current architecture, all the Native Modules used by JavaScript (e.g. Bluetooth, Geo Location, File Storage etc) have to be initialized before the app is opened. This means, even if the user doesn’t require a particular module, it still has to be initialized at start-up.

Turbo Modules are basically an enhancement over these old Native modules. As we have seen in the previous part of this article, now JavaScript will be able to hold a reference to these modules, which will allow JS Code to load each module only when it is required. This will significantly improve start-up time for React Native apps.

4. CodeGen

All this talk of Turbo Modules and Fabric sounds promising, but JavaScript is a Dynamically typed language, and JSI is written in C++, which is a Statically Typed Language. Consequently, there is a need to ensure smooth communication between the two.

That’s why the new architecture will also include a static type checker called CodeGen.

By using the typed JavaScript as the source of truth CodeGen will define interface elements used by Turbo Modules and Fabric. It will also generate more native code at build time, instead of run time.


Reference https://medium.com/coox-tech/deep-dive-into-react-natives-new-architecture-fb67ae615ccd

More About the Author

Experienced chief executive officer @expertappdevs with a demonstrated history of working in the information technology and services industry.

Total Views: 52Word Count: 719See All articles From Author

Add Comment

Technology, Gadget and Science Articles

1. Digital Commerce Platform Market- Global Industry Analysis And Forecast (2023-2029)
Author: Puja

2. Unlocking Efficiency And Collaboration With Project Management Software
Author: Rudra

3. Network Encryption Market Top Companies, Trends And Future Prospects Details For Business Development 2029
Author: Puja

4. 7 Key Trends In Online Form Builder Software You Need To Know
Author: MakeForms

5. An Ultimate Guide To Start A Taxi Business Like Uber
Author: adrianevans

6. Unleashing The Power Of Face Swap Ai: A Game-changer In Digital Imaging
Author: fototweak

7. The Ultimate Guide To Choosing The Right Shopware Plugin Development Partner
Author: Hire Shopware Developer

8. Glance Is Beyond Best Lock Screen App: It’s A Feature That’s Changing The Rules Of Engagement
Author: Jaykant P

9. How Does Movie Reviews Data Scraping Help In Sentiment Analysis?
Author: datazivot

10. The Crucial Role Of Crm Software In The Automotive Industry
Author: Focus Softnet Pvt. Ltd

11. How Can Quotation Management Software Streamline Your Business?
Author: nagaraj

12. 5 Manufacturing Business Challenges Odoo Erp Software Resolves
Author: Alex Forsyth

13. Common Iphone Problems You Should Know About
Author: Charlie Wollstonecraft

14. Are You Maximizing Your Compliance Management System's Potential?
Author: nagaraj

15. The Ultimate Guide To Industrial Thermocouple Applications
Author: ADVAN

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: