Why React Native?
Secondly, a significant portion of code written in React Native can be shared between platforms, streamlining concurrent development for both iOS and Android. Thus reducing engineering overhead involved in making separate iOS and Android Applications.
So, spill the beans on how this thing actually works, real quick!
Lets have a 10,000 ft view of how this thing works on different Operating systems.
Ok that makes sense, but how do mobile devices gets groovy with JS?
How JS and native code written in Java/Obj C talk to each other?
The native code for Android (Java/Kotlin) and iOS (Objective-C/Swift) are composed in different programming languages.
A Glimpse of React Native's Build and Runtime
When we're putting together everything to make our app, the native code written in Java or Objective-C becomes binary files in Java and C++.
Threads In React Native
What are Threads?
A thread represents a sequence of instructions executed by the CPU. In simpler terms, it is a pathway of execution.
Essentially, there are three threads of primary importance in React Native carry that takes care of all necessary operations.
Main Thread/Native UI Thread
This is the primary native thread where the app runs. It handles user interactions, showing things on the device screen, and it's the same thread used in all fully native applications.
Demystifying relationship between threads and bridge
Unmasking the Hitches: The Not-So-Cool Side of React Native Bridge
The bridge has some inherent issues and limitations.
1. Asynchronous: It worked like passing notes between two layers, and one had to wait for the other, even when it wasn't necessary.
Although asynchronous information exchange through the bridge is generally extremely fast, there are situations where it may prove insufficient, and opting for a synchronous approach would be more advantageous. Issues may arise in certain edge cases when relying solely on asynchronous communication.
3. Extra Work: When one layer needed to talk to the other, it had to package the information in a certain way (serialize), and the other layer had to unpack it (deserialize). This was like putting things in a box before sending them, and then opening the box to use them. Even though they chose a simple and easy-to-read format (JSON), it added a bit of work.
React Native New Architecture
Now, if one type of code wants to ask the other to do something, it can just directly talk to it without waiting or doing extra work. This has a bunch of cool advantages:
1. No More Waiting: Some things that used to take time and wait around can now happen right away. Now it is possible to synchronously execute functions that should not have been asynchronous in the first place.
2. Less Extra Work: Before, they had to package and unpack the information each time they talked. Now, they can just share info without going through all that trouble i.e the New Architecture doesn't have to serialize/deserialize the data anymore
3. Sharing is Caring: With this new way, they can easily use the same code on different devices without too much hassle. It's like having a set of tools that works well everywhere. By introducing C++, now it is possible to abstract all the platform agnostic code, making it easier to share seamlessly across different platform.