React Native Plant App UI #1 : Getting Started

Krissanawat Kaewsanmuang
Nov 10 · 12 min read

This React Native Plant App UI clone tutorial series was inspired by the React Native Templates that provides a wide variety of mobile application templates written in React Native and powered by universal features and design. These app templates allow us to implement our own apps and even start our own startups. Some of the examples of apps that we can build using these templates are real estate properties, restaurants, bars, cars, dealerships, e-commerce products, marketplace used products, hotels, travel locations, etc.

This tutorial series replicates the coding implementations and designs from the Youtube video tutorial by React UI Kit for the Plant App UI Clone. The video tutorial delivers the coding implementation of the overall app very thoroughly. This tutorial series is the implementation of the same coding style and designs in the form of the article. Through this written article tutorial series, the learners can look into the code and implementation of different UI sections of the app more clearly. It negates one of the disadvantages of learning from a video tutorial that is having to pause the video in different sections to understand the implementation. In the written tutorial series, the learners can go through each step and take their time understanding the implementations.

Overview

In this first part of this tutorial series, we are going to set up the starter project for the upcoming tutorial parts. This first part will form the base for the overall tutorial by organizing different files and folders required in this tutorial series. Here, the idea is to start with a new React Native starter project using expo. After that, we will establish a basic project directory structure for the overall project including navigator configuration. Then, we will also set up the different theme constants and configure the App.js file to cache the assets.

So, let us begin!!

Note that, in this tutorial, we are going to use the EXPO as the React Native project development tool. So first, we are going to create a boilerplate React Native application using expo client.

Creating Starter React Native project

First and foremost, since we are going to use the expo as a development engine, we need to install it into our system. To install expo globally into our system, we need to have Node Package Manager(NPM) installed first. Then, we need to run the following command:

Now, we need to create a boilerplate react native application using expo. In order to do this, we need to run following command in the desired project directory:

After running the above command, we will be asked to choose the template for the boilerplate app. Here, we are going to choose the blank template. The blank template provides a very minimal app template as clean as an empty canvas. The selection screenshot is provided below:

As we can see, we choose the blank template and hit enter. Then, we need to enter the project name and after that, the boilerplate react native app is configured into our directory.

Now in the App.js file, we are going to use the template from the following code snippet:

Now, we need to enter the project directory and then run the command:

Then, we will get the following boilerplate app in our emulator screen:

As we can see, we have got the starter template running in the emulator. The screen is not configured with too many styles and layout designs. Just a simple white screen with text in the middle.

Configuring project files and folders

Now, in the project folder, we need to create four new directories named ‘screens’, ‘navigation’, ‘components’, and ‘constants’. For the ‘./screens/’ directory, we need to create eight JavaScript files. In the ‘/navigation/’ directory, we need to create a JavaScript file called ‘index.js’ which will hold our navigator configurations. In the ‘./constants/’ folder, we are going to keep the default constants that we are going to use in this app. The overall project folder structure is provided in the screenshot below:

Here, we need to set up all the files in the required folders as shown in the screenshot above.

Component files

Now, we also need to add ten component files in the ‘./components/’ folder as shown in the screenshot below:

Here, we have just created the files for the components that we are going to use in this tutorial series. We are going to implement these components in our next tutorial.

But, we can see that we have ‘index.js’ file in the ‘./components/’ folder. In this index.js file, we are going to import all the components and return them as a whole. The configuration in the index.js file is provided in the code snippet below:

Setting up React Navigation

Here, we are going to set up our navigation configurations so that we will be able to navigate from screen to screen in our app. For that, we need to install the react-navigation package along with its supporting dependent packages as shown in the code snippet below:

Now, that we have installed the required packages, we can now set up our navigator in the index.js file of ‘./navigation’ folder. In index.js file, we will set up a stack navigator with all the screen as shown in the code snippet below:

Here, we have imported the createStackNavigator function from the react-navigation-stack package. This createStackNavigator function enables us to stack our screens in other to configure an app container with screens to navigate. Then, we have also imported the screens from the './screens/' directory. Then, all the screens are included in the createStackNavigator function as the 1st parameter. In the 2nd parameter, we have configured the defaultNavigationOptions. The navigation options configured to this defaultNavigationOptions object are applied by default to all the screens. Here, in the defaultNavigationOptions object we have initialized different options for the header which are not configured yet.

Lastly, we have made use of the createAppContainer function from the react-navigation package. In this function, we have passed the screens navigator constant that we have defined as a stack navigator. This function will create a container for our app binding all the screens stacked together.

Download Necessary Assets

Here, we need to download the necessary assets which include images and icons for our project. The icons and images are kept in separate folders inside the assets folder. The idea is to download the assets folder and then copy the images and icons folder to the ‘./assets/’ folder of our project.

The link to download the required assets is provided here.

Configuring the constants

Now, we are going to configure our constants in the ‘./constants/’ folder. In the constants folder, we have three files which are mock.js, theme.js and index.js. The mock.js will contain the mock data that is required in the different UI sections of the app. So, if we require the use of any mock data for any screens, we are just going to import it from the mock.js file and use it in the screen UI. The theme.js file will contain the default style properties that we are going to use throughout this app.

The required mock data to be added to mock.js file are provided in the code snippet below:

Here, we have got the mock data for each screen which includes profile, explore, products and categories.

Now, the required default style configurations to be added in the theme.js file are provided in the code snippet below:

Here, we have predefined the color, size and font style properties that we are going to use in this project.

Now, we are going to export the constants from both mock.js and theme.js file through index.js file of the ‘./constants’ folder. For that, we need to import the mock.js and theme.js files into the index.js file and export theme as shown in the code snippet below:

Here we have exported all the exports from both theme.js and mock.js file through a single file i.e. index.js. Now, we can simply import the index.js file into our screens and components to use the theme and mock data.

Configuring App.js

Here, we are going to configure the App.js file so that we can cache our assets. Since we have too many images and icons files in this project, caching these files would make the app run faster. For that, we need to install a new package called expo-asset. This package provides an Expo universal module to download assets and pass them into other APIs. In order to install this package, we need to run the following command:

Now, we need to import this package along with some other package in the App.js file as shown in the code snippet below:

Here, we have imported the expo-asset package as Asset module. We have also imported AppLoading which tells Expo to keep the app loading screen open if it is the first and only component rendered in your app. And, we have also imported the index.js file of './navigation/' folder as Navigation. This Navigation component holds the app container that we created in the index.js file.

Now, we need to import all the images that are required in this project so that we can cache them:

Here, we have imported all the images from the assets folder and stored them in images constant as an array.

Handling the Caching of Images

Here, we are going to configure a function called handleResourcesAsync(). In this function, we are going to configure the code necessary for caching the images. The overall coding implementation of this function is provided in the code snippet below:

Here, we have defined a constant called cacheImages which is initialized to the map() array function of images constant. This map() array function iterates through each item in the images array and then returns each image synced to cache download. Lastly, this function returns the cacheImages constant as a Promise.

Now, the overall configuration of the App.js file is provided in the code snippet below:

Here, in the render() function, we have returned the AppLoading component on the basis of isLoadingComplete state. The isLoadingComplete state is defined to handle the loading state of the app. If this state is false then AppLoading component is returned else the Navigation component is returned.

Implementing a Simple Welcome Screen

In this last step, we are going to implement a simple template in the Welcome.js screen in order to show that our app runs perfectly in the emulator with all the configurations.

Since we have just created the files in the screen folders and have not implemented any templates to them, the app may throw the error. Here, we are just going to create a template for Welcome.js screen, so we need to comment out all the other imports in the index.js file of our ‘./navigation/’ folder as shown in the screenshot below:

Now, our navigator has only a Welcome screen.

Templating Welcome screen

Here, we are going to add the React Native template to the Welcome.js file. The overall coding implementation of the Welcome screen is provided in the code snippet below:

Hence, we will get the following result in our emulator screen:

Hence, we have got the Welcome screen on our emulator screen. With this, we have come to the end of this part of our tutorial.

Finally, we have successfully set up and configured all the files and folders necessary for the implementation of the React Native Plant App UI clone.

Conclusion

This is the first part of our tutorial series to clone the React Native Plant App UI. In this part of the tutorial, we first learned how to set up a stater react native app project by using expo. Then, we learned how to configure different directories and files in order to form the base of our overall project. After that, we got step by step guide on how to set up the navigator for our app screens.

We also set up default constants in our ‘/constants’ folder which we will use in our screens and components in upcoming tutorials. Then, we configured the App.js in order to cache the image assets and also display the app loading state and app Welcome screen. Lastly, we implemented a simple template for the Welcome screen and run the app in an Android emulator to show that the app runs fine with all the configurations.

Well, this tutorial just paves the foundation for upcoming tutorials. In the next part, we are going to set the predefined components by implementing all the components in the ‘./components’ folder.

So, Stay Tuned folks!!!


Originally published at Kriss.

Quick Code

Find the best tutorials and courses for the web, mobile, chatbot, AR/VR development, database management, data science, web design and cryptocurrency. Practice in JavaScript, Java, Python, R, Android, Swift, Objective-C, React, Node Js, Ember, C++, SQL & more.

Krissanawat Kaewsanmuang

Written by

React native passionate developer, Coffee addict https://kriss.io

Quick Code

Find the best tutorials and courses for the web, mobile, chatbot, AR/VR development, database management, data science, web design and cryptocurrency. Practice in JavaScript, Java, Python, R, Android, Swift, Objective-C, React, Node Js, Ember, C++, SQL & more.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade