React Native Add Search Bar Filter on JSON Listview Example

Search Bar Filter is a real time filtering technique used in almost all Android and iOS applications to filter the JSON data in FlatList and ListView by typing text in TextInput component. It will filter the ListView according to user typed value and set the newly filter result again in ListView. So in this tutorial we would going to make a react native app with Real Time Search Bar Filter on JSON Parsing ListView. So let’s get started .

Contents in this project Add Search Bar Filter on JSON Listview Android iOS Tutorial :

1. Read my previous tutorial about JSON Parsing FlatList. Because we are using same JSON in current tutorial as i was used in this tutorial. So reading this tutorial is must to understand, how we are converting the MySQL data to JSON.

JSON Screenshot:


2. Import Text, StyleSheet, View, ListView, TextInput, ActivityIndicator and Alert component in your project.

3. Create constructor() in your class. Now make 2 State variables named as isLoading and text. isLoading state is used to show and hide the ActivityIndicator and text state is used to set text inside TextInput. Now we would make a Global Array named as arrayholder=[] .We would use this Array Array to Filter the ListView.

4. Create Fetch() API in componentDidMount() method. The Fetch() Web API is used in this project to Parse JSON from given HTTP URL. We would also store the Parsed JSON inside arrayholder Array.

5. Create function named as GetListViewItem() for retrieve selected ListView item and show inside Alert message.

6. Create SearchFilterFunction() and pass Text inside it as argument. Now we would filter the JSON array according to given value pass as argument. After filtering data we would set the newly data in dataSource state.

7. Create ListViewItemSeparator() function to show a horizontal line between each ListView element .

8. Add IF condition in render’s block, which is used to Show and Hide the ActivityIndicator component after parsing the JSON.

9. Now create a Root View in render’s return block.

10. Create a TextInput and ListView component in root view. This is used to get search input from user.

11. Create Style classes :

12. Complete source code for App.js File :

Screenshot in Android device :

Search Bar FilterScreenshot in iOS Application :