Setting Up Development Environment For React Native v1.1
Setting Up Development Environment For React Native v1.1
Setting Up Development
Environment for React
Native
React-Native with RN Navigation and Paper
Prepared by Ronnie Peh
Content
Content 1
1 v1.1
Setting Up Development Environment for React Native
Download Dockers 11
Install Dockers 11
2 v1.1
Setting Up Development Environment for React Native
The easiest way to get started is to use the online Expo development platform. Here, you can
make use of the cloud to develop and test your application using the online simulator for web,
iOS and Android.
3 v1.1
Setting Up Development Environment for React Native
3. Once you have finished registration, you should be able to see the following Welcome
screen.
Let’s try to develop a React Native mobile application using Snack, the online version of the
Expo Go. This is the easiest way to start developing and testing for React Native.
1. Look for Snacks on the left side of the menu and click on it.
4 v1.1
Setting Up Development Environment for React Native
2. Click on +New Snack to create a quick online React Native snack project.
3. You will see the development environment as shown below. The left panel is the list of
react native files in the project. The middle panel is the code editor. The right panel is the
simulator for the app to run on with your device, iOS, Android or on the Web. We will
come to that in a short while.
a. Click on the default given name at the left hand top corner of the screen and
change it to a more meaningful name.
b. Click on the Save button near the top right hand corner.
5 v1.1
Setting Up Development Environment for React Native
4. The right panel actually shows the result of the codes in the code editor. Let’s try to
modify the code in the middle panel to see the changes in the right. Open up the
AssetExample.js files in the components folder as shown below.
and you will see that instead of a cube with a sphere, the react native logo is loaded.
6. Now click on the iOS tab and click on Tap to Play as shown below:
6 v1.1
Setting Up Development Environment for React Native
You will see that your application actually runs in the simulator.
7. Try the Android Emulator yourself. Note that these simulators are run in a VM powered
by appetize.io.
8. Now try running the application on your own mobile device. Although we cannot install
the application like what we usually did from the App Store or Google Play store, we use
the Expo Go mobile app that we have installed earlier to run the app.
9. Click on the My Device tab and follow the instructions on the screen. For iOS users, you
will need to use the default QR code scanner that comes with iOS.
7 v1.1
Setting Up Development Environment for React Native
10. There are many times where we need to add dependency libraries for other frameworks
such as react navigation or other functionalities such as expo-camera. For that, we need
to add dependency libraries.
11. For Expo snack, the dependencies library is automatically detected when you import the
library. Go to the file App.js and add the following line to use the react navigation library.
Note that the Expo will detect each of the libraries one by one. You will need to click and
confirm each of them one by one.
8 v1.1
Setting Up Development Environment for React Native
12. So at the end of the day, where did Expo store all the dependency settings? The settings
are stored in the file called package.json. Open up the package.json file and you will see
the newly added libraries.
You can also modify the version of the libraries that you want to use.
13. So we have completed setting up a fast and easy way to start developing mobile
9 v1.1
Setting Up Development Environment for React Native
applications using Expo Snack. This method is used usually under following
circumstances:
a. Sharing a running version of your application
b. Your PC cannot run expo locally
c. Collaboration
Note that the debugging process is very inefficient when developing in Snack.
[Reference]
1. You must first enable the "Windows Subsystem for Linux" optional feature before
installing any Linux distributions on Windows.
2. Open PowerShell as Administrator and run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all
/norestart
5. Before installing WSL 2, you must enable the Virtual Machine Platform optional feature.
6. Open PowerShell as Administrator and run:
10 v1.1
Setting Up Development Environment for React Native
7. Restart your machine to complete the WSL install and update to WSL 2.
Download Dockers
Install Dockers
11. Ensure you have completed the steps described in the Prerequisites section before
installing the Docker Desktop release.
12. Follow the usual installation instructions to install Docker Desktop. If you are running a
supported system, Docker Desktop prompts you to enable WSL 2 during installation.
Read the information displayed on the screen and enable WSL 2 to continue.
13. Start Docker Desktop from the Windows Start menu. You must see the green dot and
besides it says “Docker running”
14. From the Docker menu, select Settings > General.
11 v1.1
Setting Up Development Environment for React Native
12 v1.1
Setting Up Development Environment for React Native
13 v1.1
Setting Up Development Environment for React Native
21. A dialog box will prompt you to open vscode. Click Open Visual Studio Code.
The purpose of creating these 3 files is to customize our development environment. The
Dockerfile contains information on which base image to use for the container and other
essential libraries for development.
24. Open up the Dockerfile and fill it with the following code.
14 v1.1
Setting Up Development Environment for React Native
We will be using node version 16 as our base image and set initialisation for VS Code.
After which, we install 4 libraries. Can you try to find out the purpose of each library?
25. Next, open up the docker-compose.yml file and fill in the following code.
services:
expo-dev:
image: io.ghcr.navneetkarnani.vscode-expo-starter
build:
dockerfile: ./Dockerfile
volumes:
- code:/root/workspace
# https://code.visualstudio.com/docs/remote/containers-advanced#_avoiding-
extension-reinstalls-on-container-rebuild
- vs-server:/root/.vscode-server
volumes:
vs-server: {}
code: {}
The docker-compose contains the instruction to spawn a new container from the
Dockerfile with additional information such as directories mapping between the host and
container.
26. Finally, open up the .devcontainer.json file and fill in the following code.
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.191.0/containers/docker-
existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-
compose.yml.
15 v1.1
Setting Up Development Environment for React Native
{
"name": "expo-dev",
// Update the 'dockerComposeFile' list if you have more compose files or use different
names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to
make.
"dockerComposeFile": [
"docker-compose.yml"
],
// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service
name.
"service": "expo-dev",
// The optional 'workspaceFolder' property is the path VS Code should open by default
when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/root/workspace",
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
// expo and react native extensions
"bycedric.vscode-expo",
"msjsdiag.vscode-react-native",
"eg2.vscode-npm-script",
// ESLint
"dbaeumer.vscode-eslint",
// git extensions that are highly recommended
"eamodio.gitlens",
"mhutchie.git-graph",
16 v1.1
Setting Up Development Environment for React Native
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [ 19000, 19001, 19002 ],
// Uncomment the next line if you want start specific services in your Docker Compose
config.
// "runServices": [],
// Uncomment the next line if you want to keep your containers running after VS Code
shuts down.
// "shutdownAction": "none",
// Uncomment the next line to run commands after the container is created - for example
installing curl.
// "postCreateCommand": "apt-get update && apt-get install -y curl",
This file contains information when VS Code opens up the container and attaches itself.
27. Goto Terminal and run the following command to build the image and run the container:
docker compose up -d
17 v1.1
Setting Up Development Environment for React Native
28. Close your VS Code, goto Docker Desktop, hover your cursor until you see a button that
says Open in Visual Studio Code.
18 v1.1
Setting Up Development Environment for React Native
This will open up a VS Code and you will be prompted if you want this folder to be
opened in the container. Click Ok to open in the new container.
29. VS Code will relaunch and open an empty folder for your React Native development.
Congratulations! You have successfully set up a basic environment for React Native.
30. In the event that this method does not work and Docker Desktop gave an error during
the launch, please proceed with the following steps:
a. From Visual Studio Code (make sure that you have Remote Development
Extension installed), goto Remote Explorer .
b. Look for the container and Click Open Folder in Container
19 v1.1
Setting Up Development Environment for React Native
31. Use the following command to generate Follow the steps in this practical to set up the
SSH key for the Gitlab. Remember to also set the global user name and email for Git
32. Once you have the key setup, goto File ➤Open File. Select the id file as shown below:
33. Continue to register this key to gitlab and so a final test to ensure that your connection to
gitlab is established using the following:
$ root~\ssh -T [email protected]
Welcome to GitLab, @developer.soc.sp!
$ root~\
If the ssh command is not found in the container, use the following steps to install the open ssh
client.
$ root~\apt-get update
$ root~\apt-get upgrade
$ root~\apt-get install openssh-client
20 v1.1
Setting Up Development Environment for React Native
~/workspace# cd rnproject/
~/workspace/rnproject# expo start --tunnel
Starting project at /root/workspace/rnproject
Developer tools running on http://localhost:19002
Starting Metro Bundler
Successfully ran `adb reverse`. Localhost URLs should work on the connected Android
device.
Tunnel connected.
Tunnel ready.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
█ ▄▄▄▄▄ █▄▀▀▄▄█▄█▄▀▄▀▄█ ▄▄▄▄▄ █
█ █ █ ███▄█ █▄▄▀▄███ █ █ █
█ █▄▄▄█ ██▄▀▄▀█ █ ▄▀▄▀█ █▄▄▄█ █
█▄▄▄▄▄▄▄█ █ ▀▄▀ █▄█ ▀▄█▄▄▄▄▄▄▄█
█ ▄▀ █▄█▀ ▄▄▀▀ ▀█ ▀ ▄█▄█▀██▀▄█
█▄▄▄▄ ▄▄▀█▀ ▀█ ▄▄▀▀▀▀█▄▀ ██▄▀█
█▄ ▀▄▄▄▄▀ ▄█▄▄▀█ ███▄█ ▀▀▄█ █
█▀ ▀█▀ ▄ ▄▄ ▄█▀ ▄█ ▄▄ ▄▄█ █ █
█▀█▄▄ ▄▄█ ▄▀▀ ▄█▀▀▀█ ██▀▀▀▀ ▄█
█ ▀ ▀▀▄ ▄▀▄ █▄ █ ▀█▀█▀█▀▀▄█
█▄▄▄▄▄▄▄▄▀██▀▀█ █ ▀▀ ▄▄▄ █▄█▄█
█ ▄▄▄▄▄ ██ ▀ ▄ ▀█ █▄█ ▄███
█ █ █ █ ▀▀▀▀█ ▀▀ ▄ ▄ ▄█▀█▀█
█ █▄▄▄█ █▀▄█▀ ▄ ▄█▄ █▄ █ ▄ ▄ █
█▄▄▄▄▄▄▄█▄▄▄██▄▄▄███▄▄█▄███████
You can now scan and use either your mobile device or web to run your program.
39. Now let’s add a debugger configuration for React Native. Click the menu titled “Run” in
the main application menu bar and then select the option “Add Configuration.”
21 v1.1
Setting Up Development Environment for React Native
This will create a folder called .vscode and a file called launch.json.
41. Set a breakpoint, and restart your application. Connect your mobile device. Now give
your mobile device a shake and the context menu will appear. Select Debug Remote JS.
This will enable the debugging process.
22 v1.1
Setting Up Development Environment for React Native
43. However, in order for the 2 packages to work with Web Pack which runs the Expo, open
up the babel.config file and add the following:
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: ['react-native-reanimated/plugin'],
env: {
production: {
plugins: ['react-native-paper/babel','react-native-reanimated/plugin'],
23 v1.1
Setting Up Development Environment for React Native
},
},
};
};
The purpose of the babel.config is to add the plugins that are needed to run the paper
and react navigation in the web pack.
Congratulations, you have successfully set up the environment for developing React
Native Apps using Paper and React Navigation.
~ End of Instructions ~
24 v1.1