React Native is a framework for building mobile applications using React.
-
Native Development
- Objective-C/Swift for iOS
- Java/Kotlin for Android
-
Hybrid Development (using HTML, CSS, and JS) -Example frameworks: Cordova, Ionic
- Performance and UX can be concerns when using hybrid solutions.
- Cross-platform development can address some of these issues, enabling you to write code once and deploy it on both iOS and Android.
React Native is used in this context, as it allows building mobile apps using just JavaScript.
- ReactDOM is used for the web.
- React Native is used for mobile apps (iOS and Android).
"Learn once, write anywhere."
- in React Native is converted to UIView on iOS or android.view on Android.
- React Native uses JavaScript with all of its functionalities, libraries, and community-driven packages.
In web development, we bundle all JavaScript files into a single bundle.js file for the application (using Webpack).
In React Native, a similar process happens but with Metro bundler.
- Applications built with React Native include the bundle.js file along with iOS and Android native code.
-
Hermes is the JavaScript engine responsible for interpreting and optimizing JavaScript code in React Native.
-
The JS file contains the business logic, while the native side controls the UI and handles user events.
- In React Native, JavaScript runs in a single thread within the JavaScript VM (e.g., Hermes).
- This means JavaScript operations are executed one after another, ensuring the predictable flow of code execution.
- The native side (iOS/Android) runs on multiple threads, which allows for concurrent execution of tasks.
- The UI thread is dedicated to rendering the user interface, which helps to ensure smooth and responsive UI updates.
- React Native uses Yoga, a layout engine, to calculate the layout of components.
- Yoga runs on a separate thread called the shadow thread.
- The shadow thread performs layout calculations using flexbox, enabling cross-platform layout building.
- Yoga allows React Native to create responsive layouts that adapt to both iOS and Android using the same codebase.
They communicate via the Bridge.
- In the JavaScript file, there is a handlePress() function.
- When triggered, the information is sent via the Bridge.
- The native side listens for this data from the Bridge and executes the press action triggered by the user.
The Bridge is asynchronous and uses a simple JSON structure to transfer data.
The new RN architecture adopted. The main reason to create new architecture is performance.
The code create in RN using BRIDE and FABRIC is the same.