Example of Grid Image Gallery in React Native


Here is an Example of Grid Image Gallery in React Native. We will use FastImage component from react-native-fast-image for our Grid Image Gallery in React Native. If you have no idea about the FastImage then you can get the idea about it from Fast Speed Image Loading using React Native Fast Image.

Image Gallery is the most common thing in an application. To make an Image gallery in React Native we have a number of options available and we are using one of them in this example. You can also see our other Example of Slider Image Gallery in React Native.

FastImage Component

    uri: 'https://unsplash.it/400/400?image=1',
    headers: { Authorization: '9876543210' },

It is very easy to use component. We are going to make a grid of image using Flat list (If you want to get the idea how to do that then you can see Example of GridView using FlatList in React Native) and after clicking on the image from the grid view we are going to open it in modal component for the full view. 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

If you want to start a new project with a specific React Native version, you can use the --version argument:

react-native init ProjectName --version X.XX.X
react-native init ProjectName --version react-native@next

This will make a project structure with an index file named App.js in your project directory.

Installation of Dependency

To use FastImage component we need to install react-native-fast-image dependency.

To install these dependencies open the terminal and jump into your project using

cd ProjectName

Run the following commands

npm install react-native-fast-image --save

This command will copy all the dependency into your node_module directory.

CocoaPods Installation

After the updation of React Native 0.60, they have introduced autolinking so we do not require to link the library but need to install pods. So to install pods use

cd ios && pod install && cd ..


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


// Example of Grid Image Gallery in React Native
// https://aboutreact.com/grid-image-gallery/

// import React in our code
import React, {useState, useEffect} from 'react';

// import all the components we are going to use
import {
} from 'react-native';

//import FastImage
import FastImage from 'react-native-fast-image';

const App = () => {
  const [imageuri, setImageuri] = useState('');
  const [
    modalVisibleStatus, setModalVisibleStatus
  ] = useState(false);
  const [dataSource, setDataSource] = useState([]);

  useEffect(() => {
    let items = Array.apply(null, Array(120)).map((v, i) => {
      return {
        id: i,
        src: 'https://unsplash.it/400/400?image=' + (i + 1)
  }, []);

  const showModalFunction = (visible, imageURL) => {
    //handler to handle the click on image of Grid
    //and close button on modal

  return (
    <SafeAreaView style={styles.container}>
      {modalVisibleStatus ? (
          onRequestClose={() => {
            showModalFunction(!modalVisibleStatus, '');
          <View style={styles.modelStyle}>
              source={{uri: imageuri}}
              onPress={() => {
                showModalFunction(!modalVisibleStatus, '');
                style={{width: 35, height: 35}}
      ) : (
        <View style={styles.container}>
          <Text style={styles.titleStyle}>
            Grid Image Gallery in React Native
            renderItem={({item}) => (
              <View style={styles.imageContainerStyle}>
                  style={{flex: 1}}
                  onPress={() => {
                    showModalFunction(true, item.src);
                      uri: item.src,
            //Setting the number of column
            keyExtractor={(item, index) => index.toString()}
export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#ffffff',
  titleStyle: {
    padding: 16,
    fontSize: 20,
    color: 'white',
    backgroundColor: 'green',
  imageContainerStyle: {
    flex: 1,
    flexDirection: 'column',
    margin: 1,
  imageStyle: {
    height: 120,
    width: '100%',
  fullImageStyle: {
    justifyContent: 'center',
    alignItems: 'center',
    height: '100%',
    width: '98%',
    resizeMode: 'contain',
  modelStyle: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'rgba(0,0,0,0.4)',
  closeButtonStyle: {
    width: 25,
    height: 25,
    top: 50,
    right: 20,
    position: 'absolute',

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 (macOS only)

react-native run-ios

Download Source Code

Output Screenshots

This is how you can make Grid Image Gallery in React Native. If you have any doubts 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. 🙂

4 thoughts on “Example of Grid Image Gallery in React Native”

  1. I want to build something similar but, instead of images, each square should contain another react component. Coincidentally, part of the component I want to display is an image but also there is text information so, ideally, just a responsive grid of components. Any suggestions on ideas of how to start?


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.