React Native Creating Image Gallery using JSON iOS Android Tutorial

Image Gallery also known as Photo Album is used to show multiple images on user’s screen with Tap to open feature. Image Gallery is a layout on your application where you can see all the application images at a single place and you can open them by tapping. We are using the FlatList in this tutorial to creating image gallery and to show images in Grid format we are using numColumns = {2} prop of FlatList. To show image individually we would use Modal component, this component allow us to create a popup on screen with Fade in and Fade out animation effect. So in this tutorial we would going to Creating Image Gallery using JSON parsing data in iOS Android react native application example tutorial.

Contents in this project Creating Image Gallery using JSON iOS Android Tutorial in React Native App:

1. JSON used in this tutorial is already created inside my previous tutorial Custom JSON ListView with Images and Text. I have explained all the MySQL database and PHP files to creating JSON in my previous tutorial.

2. Screenshot of JSON.


3. Import Platform, StyleSheet, View, FlatList, ActivityIndicator, Image, Modal and TouchableOpacity component in your project.

4. Creating constructor() in your project, Now we would make 3 State named as isLoading, ModalVisibleStatus and TempImageURL .

isLoading : Used to Show and Hide the activity indicator after successfully JSON parsed.

ModalVisibleStatus : Used to show and hide the Modal component.

TempImageURL : Used to hold the single image URL as Source while we show individually image in Modal.

5. Creating componentDidMount() inbuilt method to Parse JSON data and store JSON into dataSource.

6. Creating a function named as ShowModalFunction() with 2 parameters visible and imageURL. visible is used to hold the Modal visibility status which is in True or False and imageURL is used to hold the Image HTTP Path when user click on any image. We would also store both values State.

7. Put a IF condition in render’s block using State value to show or hide the Activity Indicator on data load.

8. Creating a Root View in render’s return block, This view is our main view.

9. Creating FlatList component in Root View to show all the images in Grid Format.

10. Now finally we need to put a Curly brackets block after FlatList and inside this block we would use the Ternary operator with State to show and hide the Modal component. Modal is used to show single image at a time.

10. Creating Style.

11. Complete source code for App.js File :

Screenshots in Android device:

Creating Image Gallery Screenshots in iOS device: