Join us
@bangadam ・ Aug 23,2022 ・ 3 min read ・ 1092 views
React
The calculator application is a simple application that is always available on every device such as android, ios, and desktops. In this article we will build a calculator application using React Native and Expo, why do we use React Native and Expo?
React Native is a JavaScript-based framework that is used to develop mobile applications on two operating systems simultaneously, namely Android and iOS. React Native itself was first launched in 2015 by Facebook and is open source.
You can find out more information about React Native here
Expo itself is a set of tools, libraries, and services that are used to simplify the code of React Native apps. So you can run React Native apps on the Expo emulator.
You can find out more information about Expo here.
maybe that’s enough about the introduction of React Native and Expo. Before we start making a calculator application, first install node js, react native, and expo on your computer.
Prerequisite
Step 1: Create New Project
The first step is to create a new project using the Expo CLI to create the React Native code base with the following command:
then we will be given the choice of starting the project we want, here we choose the blank option and use Javascript as below:
after that the process will continue by downloading all the dependencies.
Step 2: Create Button Component
In the process of developing applications using React Native, it is important to pay attention to breaking down UI components into small components so that the component code that we create can be reusable. First, create a new folder called “components” to store our component code, the first component we will create is Button, create a new file called Button.js. Here is the source code for the Button component:
explanation :
after we make the code from the component don’t forget to make the styling code from this button component. Here is the code for the component’s button styling:
so the complete code of our button component is as follows:
Step 3: Create Row Component
The component that we will create is a Row component, this component is useful for creating rows when we want to process layouts. Here is the code for the Row component and its styling code:
explanation:
Step 4: Create calculator logic
Create a new folder called util and a new file calculator.js, here we will create a function logic in the calculator application which we will implement later in the App.js file, here is the complete code:
explanation :
Step 5: Refactor App.js
After we have created all the components and the logic process, the next step is to make adjustments to the code in the App.js file. Here is the full code:
explanation:
Step 6: Running App
In this step we will try to run the calculator application on the device or can use an emulator, here I use the iPhone simulator from MacOS. Run the command below to run the program:
The running process here uses Expo as shown below:
if the compiling process is complete then the display of the calculator application that we programmed earlier will be like this:
Conclusion
That’s enough for this article, so far you already know about styling, components, props, and states in React Native. If you need the full source code, you can visit my Github repository here https://github.com/bangadam/calculator-app
Join other developers and claim your FAUN account now!
Influence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.