React Native Car Parking Finder App UI Clone #6: Implementing Modal View

Krissanawat Kaewsanmuang
Nov 2 · 11 min read

This tutorial is the sixth part of our React Native Car Parking App UI clone series. In the last part, we successfully implemented the Header section in our map screen as well as organized our code. In this part of the tutorial series, we are going to continue from where we left off in the last part. So, it is recommended to go through all the previous parts of this tutorial series in order to get the full insight and development of the project.

In case anyone wants to learn from the beginning, all the parts for this tutorial series are available below:

As mentioned in the previous parts, the motivation for this tutorial series came from the React Native Store Locator App template that provides us with a dynamic, fully-coded starter kit written in React Native that anyone can use to build their own store locator React Native application or initiate their own startup. And, this fifth part is also the continuation of coding implementations and designs from the YouTube video tutorial by React UI Kit for the Car parking Finder App UI clone. The video tutorial seems to deliver the implementations of different UI sections using a fast coding style that may be difficult to understand for any developer especially the beginners. However, this tutorial gives step by step guidance on the implementation of each UI section. Hence, the readers can relax and take time to learn and implement the UI.

Overview

In this sixth part of the tutorial series, we are going to implement a Modal that displays extended information of the parking card section with different UI sections. The idea is to install the react-native-modal package and integrate it into the map screen. Then, we are going to configure the Modal in order to make it look like in the actual app. Lastly, we will implement different sections inside the Modal view and style them.

So, let us begin!!

Installing Modal Package

Here we are going to install the react-native-modal package into our project. This package provides an enhanced, animated and customizable react-native modal. The main aim of this package is to is expanding the original react-native Modal component by adding animations and styles customization options while still providing a plain-simple API. Now in order to install this package into our project, we need to run the following command:

Then, we need to import this package as Modal component in the Map.js file as shown in the code snippet below:

Implementing modal

In this step, we are going to implement the modal into our Map screen. For that, we need to define a state called activeModal in order to handle the opening and closing of the modal. The activeModal should be defined as shown in the code snippet below:

Now, we need to activate the modal when pressing the buy button on our parking spot card. For that, we need to change the state of activeModal in the onPress event of TouchableOpacity component as shown in the code snippet below:

Here, we have just implemented a trigger to open the modal but have not implemented the actual Modal component yet. So now, we are going to implement the actual modal.

Defining a new function for modal

Here, we are going to define a new function called renderModal(). This function will return the template with the Modal component. The overall implementation of this function is provided in the code snippet below:

Here, inside the renderModal() method, we have defined activeModal constant from the state variable. Then, if the activeModal state is empty then the renderModal() function will return null which will not show the Modal on the app screen. However, if the activeModal state is not empty, the function will return the template with Modal component. The Modal component here is configured with different props.

The isVisible prop is used to show the modal on the screen. In the onBackButtonPress and onBackdropPress events of the Modal component we have changed the activeModal state to null in order to hide the Modal from the screen. We have also integrated some View component wrapping Text component with some inline styles.

Now, we need to call the renderModal() method in the render() function of our Map.js file as shown in the code snippet below:

Now, the required style used in the renderModal() function is provided in the code snippet below:

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

As we can see, a modal appears on the screen. But the modal is too small, so we need to configure it with more props and style in order to make the modal more appealing.

Configuring Modal properties and styles

Here, we are going to configure the Modal component with some additional props and styles. For that, we need to use the code from the following code snippet:

Here, we have included a prop called useNativeDriver which uses the native driver configurations and properties to handle the workings of Modal. We have also included a inSwipeComplete event which changes the activeModal state to null. Then, we have also provided a style property to the Modal component which is provided in the code snippet below:

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

As we can see, the Modal component now covers more than half of the lower part of the screen.

Adding Modal content

Now, we are going to add some content inside the Modal view. We have added the trigger to open the Modal when we press the buy button in each car parking spot. When triggering, we have set the activeModal state to the particular parking spot data from the parkingsSpots data array. Now, we are going to use the value stored in the activeModal state in order to add the different parking spot information to the Modal. For that, we need to use the code from the following code snippet in the renderModal function:

Here, we have added different View and Text component to display the information in the parkingsSpots data array. We have also used the TouchableOpacity component which wraps the View and Text component for the final buy button in the Modal. The components are bound to different styles which are provided in the code snippet below:

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

As we can see, some content has appeared on the screen but are out of place. Now, we need to style them properly in order to make the Modal content look appealing as in the actual app.

Here, we can also notice that we have added the additional distance and description data in the Modal content. But these data are not included in the parkingsSpots data array. So, we need to include that first.

Adding addition data

Here, we are going to add the distance and description data to each item in the parkingsSpots data array as shown in the code snippet below:

Styling the content

Here, we are going to style the components inside the Modal component in order to make the Modal content appear as in the actual app. For that, we need to use the code in the following code snippet:

Here, we have added different inline style properties as well as styles from the StyleSheet component. The required styles from the StyleSheet component is provided in the code snippet below:

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

As we can see, we have got all the components in the proper positions which makes the Modal look more appealing. Now, we need to add icons to the Modal.

Adding Icons

Here, we are going to add the icons to the respective UI sections in the Modal content. We have already imported the Ionicons package from the vector-icons package provided by the expo client. Now, we are going to include the Ionicons component as shown in the code snippet below:

Here, we have provided the size and color props to the Ionicons component. The props are in accordance to our COLORS and SIZES variable from the theme.js file.

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

As we can see, we have got the icons in our Modal view. But we can see there is something missing in section with ‘Choose your Bookings Period’. In this section, we need to add the hours section as in the parking spot cards.

Adding hours section to Modal

Here, we are simply going to add the hours section to modal. We are going to add this section using below the Text component having ‘Choose your Booking Period’ text as shown in the code snippet below:

Here, the View component wraps the Text component with text showing hours. The required style is provided in the code snippet below:

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

As we can see, we have got the hours section in our Modal. With this, we have come to the end of this part of our tutorial.

Finally, we have successfully completed the implementation of Modal in our Map screen.

Conclusion

This tutorial is the sixth part of the React Native Car Parking Finder App UI clone tutorial series. In this part, we continued from where we left off in the fourth part of this tutorial series. In this part of the tutorial, we learned how to set up the react-native-modal package in order to implement the Modal in our Map screen. We also learned how to configure the Modal component in order to make it look as well as transition better. Then, we also got insight into adding different UI sections inside the Modal component. Finally, we were successful in implementing the Modal view just as in the actual app design.

In the next part of this tutorial series, we are going to implement a time dropdown in our parking spot card section.

JavaScript in Plain English

Learn the web's most important programming language.

Krissanawat Kaewsanmuang

Written by

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

JavaScript in Plain English

Learn the web's most important programming language.

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