Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
React and React Native - Fifth Edition

You're reading from  React and React Native - Fifth Edition

Product type Book
Published in Apr 2024
Publisher Packt
ISBN-13 9781805127307
Pages 508 pages
Edition 5th Edition
Languages
Authors (2):
Mikhail Sakhniuk Mikhail Sakhniuk
Profile icon Mikhail Sakhniuk
Adam Boduch Adam Boduch
Profile icon Adam Boduch
View More author details

Table of Contents (33) Chapters

Preface 1. Part I: React
2. Why React? 3. Rendering with JSX 4. Understanding React Components and Hooks 5. Event Handling in the React Way 6. Crafting Reusable Components 7. Type-Checking and Validation with TypeScript 8. Handling Navigation with Routes 9. Code Splitting Using Lazy Components and Suspense 10. User Interface Framework Components 11. High-Performance State Updates 12. Fetching Data from a Server 13. State Management in React 14. Server-Side Rendering 15. Unit Testing in React 16. Part II: React Native
17. Why React Native? 18. React Native under the Hood 19. Kick-Starting React Native Projects 20. Building Responsive Layouts with Flexbox 21. Navigating Between Screens 22. Rendering Item Lists 23. Geolocation and Maps 24. Collecting User Input 25. Responding to User Gestures 26. Showing Progress 27. Displaying Modal Screens 28. Using Animations 29. Controlling Image Display 30. Going Offline 31. Other Books You May Enjoy
32. Index

React Native under the Hood

The previous chapter briefly touched on what React Native is and the differences that users experience between the React Native UI and mobile browsers.

In this chapter, we will dig deeper into React Native, becoming well-versed on how it performs on mobile devices and what we should attain before commencing any efforts with this framework. We will also look at what options we can execute for the native functionality of JavaScript and what restrictions we will be up against.

We will cover the following topics:

  • Exploring the React Native architecture
  • Explaining JavaScript and Native modules
  • Exploring React Native components and APIs

Exploring the React Native architecture

Before understanding how React Native works, let’s revisit some historical points about the React architecture and the differences between web and native mobile apps.

The state of web and mobile apps in the past

Meta released React in 2013 as a monolith tool for creating apps, using a component approach and a virtual DOM. It gave us the opportunity to develop web applications without thinking about browser processes, such as parsing JS code, creating the DOM, and handling layers and rendering. We just had to create interfaces using state and props for data and CSS for styling, fetch data from the backend, save it in local storage, and so on.

React, together with browsers, allowed us to create a performance application in less time. At that time, the architecture of React looked like this:

Figure 16.1: React architecture in 2013

The new declarative approach to developing interfaces became more favorable because...

React Native current architecture

The React Native library allows you to create native applications with React and JS by utilizing native building blocks. For instance, the <Image/> component represents two other native components, ImageView on Android and UIImageView on iOS. This is viable because of the architecture of React Native, which includes two dedicated layers, represented by JS and Native threads:

Figure 16.4: React Native threads

In the next sections, we will explore each thread and see how they can communicate, ensuring that JS is integrated into the native code.

JS as part of React Native

As the browser executes JS through JS engines such as V8, SpiderMonkey, and others, React Native also contains a JS virtual machine. There, our JS code is executed, API calls are made, touch events are processed, and many other processes occur.

Initially, React Native only supported Apple’s JavaScriptCore virtual machine. With iOS devices, this...

Explaining JS and Native modules

React Native does not cover all the native capabilities out of the box. It only provides the most common features that you will need in a basic application. Also, the Meta team itself has recently moved some functions into its own modules in an effort to reduce the size of the overall application. For example, AsyncStorage, for storing data on a device, was moved into a separate package and must be installed if you plan to use it.

However, React Native is an extendable framework. We can add our own native modules and expose the JS API using the same bridge or JSI. Our focus in this book will not be on developing native modules, since we need prior experience with Objective-C or Java. Also, it is not necessary, since the React community has created an enormous number of ready-to-use modules for all cases. We will learn how to install native packages in subsequent chapters.

The following are a few of the most popular native modules, without which...

Exploring React Native components and APIs

The main modules and components will be discussed in detail in each new chapter, but for now, let’s familiarize ourselves with them. A number of core components are available in the React Native framework for use in an app.

Almost all apps use at least one of these components. These are the fundamental building blocks of React Native apps:

  • View: The main brick of any app. This is the equivalent of <div>, and on mobiles, it is represented as UIView or android.view. Any <View/> component can nest inside another <View/> component and can have zero or many children of any type.
  • Text: This is a React component for displaying text. As with View, <Text/> supports nesting, styling, and touch handling.
  • Image: This displays images from a variety of sources, such as network images, static resources, temporary local images, and images from the camera roll.
  • TextInput: This allows users to...

Summary

In this chapter, we looked at the history of the cross-platform framework React Native and what problems it solved for companies. With it, companies can use a single universal developer team to build one business logic and apply it to all platforms simultaneously, thus saving a lot of time and money. Considering, in detail, how React Native works under the hood allows us to identify potential issues at the planning stage and resolve them.

Additionally, we started to examine React Native’s basic components, and with each new chapter, we will learn more about them.

In the next chapter, you’ll learn how to get started with new React Native projects.

lock icon The rest of the chapter is locked
You have been reading a chapter from
React and React Native - Fifth Edition
Published in: Apr 2024 Publisher: Packt ISBN-13: 9781805127307
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}