React Native for React Developers [Part 1: React Native and the new Architecture]
Nikola Gorgiev
Software Developer | Flutter Enthusiast | React | React Native | Electron | JavaScript | TypeScript
Introduction
This Guide is written to help ReactJS developers easily adopt React Native.
Make sure that you fully understand the purpose of this guide, as a guide, meaning that it does not cover all the topics from start to finish, instead there will be some useful links included, and you need to research further more on your own.
Mobile apps vs Web
There are many advantages to creating a mobile app instead of a Website for a mobile device. First of all, with html you can not replicate the same experience of some mobile native elements, like the mobile OS does. For example custom made DatePicker made with HTML will never look and work the same as the one the mobile OS provides. Next, the interaction on the mobile devices differs from the interaction on the web, which assumes that you have a mouse, but on the mobile devices we have the ability to use finger gestures that opens a lot of new possibilities.
What is React Native?
*Explain what is React Native, and the difference between React Native CLI and Expo, and what are some alternatives (Flutter, Xamarin, Kotlin Multiplatform)
React Native is a cross-platform mobile SDK, developed by Meta (former Facebook), and released as an open source project for everyone in 2015.
Since its release, React Native became the most popular framework for building mobile apps, mostly because of the ease of use of the JavaScript programming language, and the single code base for building the app for multiple platforms with a single code.
How does React Native work?
As we have mentioned previously, React Native is a Framework for building cross-platform mobile apps. Unlike some older frameworks like Ionic, which is basically and empty mobile app, with builtin web browser and is running our web app as a standalone mobile app, React Native generates a real Native app, which is using the same components provided by the mobile OS (iOS and Android), not replicating them to look the same, like Flutter does for example, which is rendering every component “pixel by pixel”, and works like a game engine, meaning that in its core it has a replicas of all the System components, iOS and Android provides, which means, when the OS receives an Update, and some of the components are changed, Flutter needs to make that change internally, and then you need to update your Flutter version, make some changes in the code if needed, than push a new update to your app, and when the user updates the app, he will see the new Button, unlike React Native, that uses System provided components, which means when new OS changes some component, the Button for Example, with the update of the OS on your device your app will automatically render the new button.
React Native architecture
With the latest RN version 0.70, React Native has brought the promised new architecture to life (although you were able to try it since 0.68 by changing some flag in the code). In the picture bellow, you can see the differences between the old and the architecture, the old being on the left side, and the new on the right side, and the most important thing to notice is the absence of the famous “bridge” from the new architecture, and some new things like JSI, CodeGen, Fabric and Turbo Modules, and in the following text I will try to explain the problem with the bridge, and all those new things:
领英推荐
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 references to these modules, which will allow JS Code to load each module only when it is required. This will significantly improve startup time for React Native apps
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.
React Native for React Developers [Part 1: React Native and the new Architecture]