Translation | "JavaScript Everywhere" Chapter 21 Using React Native to Create Mobile Applications
Write at the top
Hello everyone, I am Mao Xiaoyou, a front-end development engineer. An English technical book is being translated.
In order to improve everyone's reading experience, the structure and content of sentences have been slightly adjusted. If you find any flaws in this article, or if you have any comments or suggestions, you can leave a message in the comment area, or add my WeChat: code_maomao, welcome to communicate and learn from each other.
(σ゚∀゚)σ…:*☆Oh, good
Chapter 21 Creating Mobile Applications with React Native
1980
One day in the late decade, when I was shopping with my parents, I found a small portable TV, which was a battery-powered square box with antenna, small speakers and a small black and white screen.
In the yard on Saturday morning, I was shocked by the cartoons I saw.
Although I may never own such a TV, as long as I know that such a device exists, I will feel like I am living in the future world of science fiction.
I had no idea that I would carry a device in my pocket when I was an adult, so that I could not only watch the Master of the Universe, but also access unlimited information, listen to music, play games, take notes, and take photos. Call a car, buy things, check the weather and complete countless other tasks.
2007
In 1991, Steve Jobs ( Steve Jobs
) launched iPhone
, he said: "Every once in a while, there will be revolutionary products, which change everything. Of course, smart phones 2007
existed before the year, but until iPhone
the rise (and The subsequent Android
rise), they really become smart. In the past few years, smart phone applications have surpassed the initial "everything is" gold rush stage, and have become a thing that users demand quality and have high hopes for.
Today's applications have high standards of functionality, interaction and design.
To make matters worse, modern mobile application development dispersed Apple iOS
and Android
on the platform, each platform using a different programming language and tool chain.
You may have guessed it (it's in the title of the book), but it JavaScript
allows our developers to write cross-platform mobile applications.
In this chapter, I will introduce cross-platform libraries: React Native
and Expo
toolchains.
We will also clone the sample project code, which will be built in the next few chapters.
What we are building
In the next few chapters, we will Notedly
build a mobile client version of the social note-taking application. The goal is to use JavaScript
and Web
technology to develop applications that users can install on their mobile devices. We will implement part of the function to avoid Web
too much repetition in the application chapter. Specifically, our application will:
-
Can be used on
iOS
andAndroid
operating system -
GraphQL API
Load note summaries and individual user notes from our -
Stylize with
CSS
and styled components -
Implement standard and dynamic routing
These features will give a comprehensive overview React Native
of the core concepts used to develop mobile applications. Before we begin, let's take a closer look at the technology that will be used.
How we will build it
React Native
It is the core technology that we will use to develop applications. React Native
Allows us JavaScript
to React
write applications in and present them for the local mobile platform. For users, this means React Native
that there is no obvious difference between an application and an application written in the programming language of the platform. This is the main advantage over React Native
other popular Web
technology-based mobile frameworks, which usually Web
wrap the view in an application shell
. Facebook
, , Instagram
Bloomberg, Tesla, Skype
Wal-Mart, Pinterest
and many other companies have used React Native
to develop applications for.
The second key part of our application development workflow is Expo
that this set of tools and services simplifies React Native
development through truly useful features , such as on-device preview, application building, and core React Native
library expansion . Before starting our development, it is recommended that you do the following:
-
Access
expo.io
and create anExpo
account. -
npm install expo-cli --global
Install theExpo
command line tool by typing in the terminal application . -
expo login
Log in to yourExpo
account locally by typing in the terminal application . -
Install the
Expo Client
app for your mobile device . You canexpo.io/tools
find links toExpo Client iOS
andAndroid
applications in it. -
Expo Client
Log in to your account in the app.
Finally, we will re-use Apollo Client
and GraphQL API
interact with data. Apollo Client
Contains GraphQL
a series of open source tools for use .
getting Started
Before starting development, you need to copy the project starter file to your computer. The source code of this project contains all scripts and references to third-party libraries, which are required for our application development.
To clone the code to the local computer, open a terminal, navigate to the directory where you saved the project, then git clone
the project repository.
If you've browsed API
, Web
and desktop
chapters, it may have created a notedly
rational directory to keep the project code:
$ cd Projects
$ # type the `mkdir notedly` command if you don't yet have a notedly directory
$ cd notedly
$ git clone git@github.com:javascripteverywhere/mobile.git
$ cd mobile
$ npm install
Install third-party dependencies
By making a copy of the starter code for this book and running it in the directory npm install
, you don't need to run it again for any third-party dependencies npm install
.
The structure of the code is as follows:
-
/
src
This is the directory where you develop with the book.
-
/
solutions
The catalog contains solutions for each chapter.
If you get stuck, these can be for your reference. -
/
final
This directory contains the final work items.
The rest of the files and project settings are adapted expo-cli React Native
to the standard output of the generator, and you can expo init
run the output by typing in the terminal .
App.js?
Due Expo
to the working mode of the build chain, the App.js
files in the root of the project directory are usually the entry points of the application. In the rest of the book, in order to standardize the code of our mobile project, the App.js
document only as a / src/Main.js
reference file.
Now that we have installed the code on the local computer and installed the dependencies, let's run the application. To start the application, in the terminal application, type the following:
$ npm start
This will open Expo
the " Metro Bundler
" Web
application on the browser's local port . Here, you can start the local device simulator by clicking one of the "Run on..." links. You can also Expo Client
start the application by scanning the QR code on the (picture 21-1
).
Figure 21-1
. After starting our application, Expo
theMetro Bundler
Install device simulator
To run the iOS
device simulator, you will need to download and install Xcode
(only macOS
). For Android
, download Android Studio
, and follow the Expo
guidelines set device simulator. (See the diagram 21-2
for comparison.) However, if you are just starting mobile application development, it is recommended that you start with your own phone.
Figure 21-2
. Our app runs side by side iOS
with the Android
device simulator
If you have Expo Client
logged in from the terminal application on your computer and the application on your mobile device Expo
, you only need to open the Expo Client
application and click the Projects
tab to open the application (picture 21-3
).
Figure 21-3
. With the help Expo Client
, we can preview our application on the phone
With the ability to clone the code to your local computer and be able to use the Expo Client
preview application, you can develop mobile applications.
in conclusion
This chapter introduces React Native
and Expo
. We cloned the sample project code, ran it locally, and previewed it on the phone or simulator. React Native
Enables Web
and JavaScript
developers to use their familiar skills and tools to build fully functional native mobile applications. Expo
Simplifies the tool chain and lowers the entry barrier for native mobile development. Using these two tools, novices can easily start mobile development, and web-savvy teams can quickly introduce mobile application development skills. In the next chapter, we will take a closer look at React Native
the features and introduce routing and styles for our application.
If there is any inadequate understanding, please correct me. If you think it's okay, please like to collect or share it, hoping to help more people.