Example of Expandable List View in React Native

This is an Example of Expandable List View in React Native. To make an Expandable List View we will create an Expandable Component with the help of stylesheet.

Expandable list view is like a sectioned list view but with hidden section content. The heading of the list will always be visible and after clicking the heading you will see the subheading of the list view.

In this example, we will make the Expandable ListView which is similar to an accordion view.

For those who have heard Accordion for the first time; Accordion is frequently used in HTML which is like the expandable list in mobile development.

In this example, we will create an expandable component called ExpandableItemComponent in which will be used as a single expandable item and will take the value dynamically using the prop. In our Main App class, according to the data, we will add this expandable component to a scroll view by passing the data with the help a loop.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Now jump into the project directory using

Open App.js in any code editor and replace the code with the following code.

App.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

         

This is how you can make an Expandable List View in React Native. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

Example of Infinite Loading Listview in React Native using FlatList

This is an Example of Infinite Loading Listview in React Native using FlatList. A React Native list view that supports infinite scroll. In mobile application development, ListView has a very important part as we use ListView in almost all applications. If we have to load a huge amount of data in a listview we have to use pagination for the seamless performance. A ListView with Load More Button in the bottom to load data can be an option but what if we load the data automatically when the user reaches at the end of the list? This feature will give a good user experience to your application users.

For those who don’t know what is pagination?
Let’s take a case where you can simply imagine what if Facebook loads all the Facebook posts from the Facebook database on your Facebook wall? Doesn’t it sound nasty? It will take hundreds of hours even more than that so what is the best way to load the data? Simply paging. When you open the Facebook they just show you 10-20 post and while you scroll the Facebook they load next 10-20 posts in background. That is what the paging is.

In our example,

  1. We are loading the first 10 posts from the web API call in componentDidMount.
  2. While the user reaches the bottom of the list we call the Web API again to get the next 10 posts.

We are using a variable offset to manage the index on upcoming Data. We will increase the offset by 1 after the successful call of the web API so that when we call the web API next time we will get the next data-set. So let’s get started with the example.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Now Open App.js in any code editor and replace the code with the following code.

App.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

     

That was the example of Infinite Loading Listview in React Native. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

Vertical and Horizontal Scroll View Like Google Play Store in React Native

This is an Example to make Vertical and Horizontal Scroll View Like Google Play Store in React Native. You can easily scroll vertically or horizontally and can click view more to see more items of that category.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Open App.js in any code editor and replace the code with the following code.

App.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

          

This is how you can make Vertical and Horizontal Scroll View Like Google Play Store in React Native. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

React Native Show Message for empty FlatList

Here is an example of React Native Show Message for empty FlatList. As the topic name describes we will show the Message for the empty list. We can use this while we are making a dynamic list and the data is coming from the server. After loading the data from the server we can directly set the DataSource to the list by defining the props ListEmptyComponent of FlatList. This will show the error message which you have set for the empty list but if the DataSource has some value it will render the List.

Here is some line of code which we have used to show the message for the empty List.

To start with this example

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Open App.js in any code editor and replace the code with the following code.

App.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

This is how you can show the message for empty FlatList. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

Scroll to the Top or Bottom of the ListView in React Native

Here is an example to Scroll to the Top or Bottom of the ListView in React Native on the Click of Button. We have often seen this type of things in websites where you scroll towards the button and suddenly a button pop up to take you at the top of the page. It provides a very good user experience. So here is the same example with the React Native FlatList.

In this example, We will  make two buttons

1. To take you to the Top of the ListView by using :

2. To take you to the Bottom of the ListView by using :

We are using a simple React Native FlatList for this example. So let’s get started.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Open App.js in any code editor and replace the code with the following code.

App.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

This is how you can Scroll to the Top or Bottom of the ListView in React Native. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

React Native Add Header Footer in ListView / FlatList

Here is an example of React Native Add Header Footer in ListView / FlatList. As the topic name describes we will add the header and footer in FlatList. To add header and footer in FlatList we will use ListHeaderComponent and ListFooterComponent props of the FlatList same as we use ItemSeparatorComponent while adding FlatList Item Separator.

Add Header Footer in FlatList

Here is the code which we have used to add header and footer in ListView

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Open App.js in any code editor and replace the code with the following code.

App.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

This is how you can add header footer in ListView / FlatList in React Native. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂

React Native FlatList Pagination to Load More Data dynamically – Infinite List

Here is an example of React Native FlatList Pagination to Load More Data dynamically – Infinite List. In this example, we will make a FlatList in which we will load the data in the form of pagination on a Click of a button.

For those who don’t know what is pagination?

Let’s take a case where you can simply imagine what if Facebook loads all the Facebook posts from the Facebook database on your Facebook wall? Doesn’t it sound nasty? It will take hundreds of hours even more than that so what is the best way to load the data?  Simply paging. When you open the Facebook they just show you 10-20 post and while you scroll the Facebook they load next 10-20 posts in background. That is what the paging is.

In our example,

  1. We are loading the first 10 posts from the web API call in componentDidMount.
  2. We have added load more button on the footer of the list.
  3. While clicking on the Load More Button we call the Web API again to get the next 10 posts.

We are using a variable offset to manage the index on upcoming Data. We will increase the offset by 1 after the successful call of the web API so that when we call the web API next time we will get the next dataset. So let’s get started with the example.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
This will make a project structure with an index file named App.js in your project directory.

Open App.js in any code editor and the Replace the code with the following code.

App.js

To Run the React Native App

Open the terminal again and jump into your project using.
cd ProjectName
To run the project on an Android Virtual Device or on real debugging device
react-native run-android
or on the iOS Simulator by running
react-native run-ios (macOS only).

After Clicking on Load More It will load the data with the loader in Button

That was the React Native FlatList with Pagination to Load More Data dynamically. If you have any doubt or you want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. 🙂