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:

12 Comments

  1. Thanks for the good article.

  2. Bro i need a react native tutorials from basic level explaining all the concepts

  3. Hey, does this still work? For some reason when I .bind(this, true, item.source) the Modal just refuses to open. If i remove the bind ( this.setModalVisible(true, item.source) ) the Modal opens, but of course it doesn’t display the image.

  4. Thankyou bro your tutorials are owesome.

    Will you please create tutorial on push notification using expo and php myadmin mysql

  5. please send me your database and php file

  6. mustafa arslantaş

    Hello, when I click on the image in the code, the image opens, how do I put the button under the image and I want to download the pdf file? When I click on the flower image I want to tell the pdf button to download and download?

    • Mustafa inside the Modal view just put the your button and to download the PDF you can use react-native-fetch-blob library.

Leave a Reply

Your email address will not be published. Required fields are marked *