React Native Image Gallery with Thumbnails

Overview

React Native Image Gallery with Thumbnails

npm version npm License: MIT GitHub package.json version Platform - Android and iOS

Features

  • Image gallery with thumbnails
  • Made with PanResponder, no external dependencies
  • Written in Typescript

If you're looking for Image caching visit @georstat/react-native-image-cache

Default Gallery Preview:

@georstat:react-native-image-gallery default_demo

Custom Gallery Preview:

@georstat:react-native-image-gallery default_demo

Installation

yarn:

yarn add @georstat/react-native-image-gallery

npm:

npm i @georstat/react-native-image-gallery

Usage

Simple Gallery with thumbs:

import { ImageGallery } from '@georstat/react-native-image-gallery';

const images = [
  {
    id: 1,
    url: 'https://...',
    // any other extra info you want
  },
  ...
]

const MyGallery = () => {
    const [isOpen, setIsOpen] = useState(false);
    const openGallery = () => setIsOpen(true);
    const closeGallery = () => setIsOpen(false);

    return (
        <View>
            <Button onPress={openGallery} title="Open Gallery" />
            <ImageGallery close={closeGallery} isOpen={isOpen} images={images} />
        </View>
    )
}

Custom Gallery without thumbs:

For more info check example

This example uses georstat/react-native-image-cache for image caching

import { CacheManager, CachedImage } from '@georstat/react-native-image-cache';
import { Dirs } from 'react-native-file-access';

CacheManager.config = {
  baseDir: `${Dirs.CacheDir}/images_cache/`,
  blurRadius: 15,
  sourceAnimationDuration: 1000,
  thumbnailAnimationDuration: 1000,
};

const MyGallery = () => {
  const [isOpen, setIsOpen] = useState(false);
  const openGallery = () => setIsOpen(true);
  const closeGallery = () => setIsOpen(false);

  const renderHeaderComponent = (image: any, currentIndex: number) => {
    return <Header currentIndex={currentIndex} />;
  };

  const renderFooterComponent = (image: any, currentIndex: number) => {
    return <Footer total={images.length} currentIndex={currentIndex} />;
  };

  const renderCustomImage = (image: Image) => {
    return (
      <View style={styles.customImageContainer}>
        <CachedImage
          resizeMode="cover"
          source={image.url}
          style={styles.customImage}
          thumbnailSource="https://via.placeholder.com/350x150"
        />
      </View>
    );
  };
  return (
    <View>
      <Button onPress={openGallery} title="Open Gallery" />
      <ImageGallery
        close={closeCustomGallery}
        hideThumbs
        images={images}
        isOpen={isCustomGalleryOpen}
        renderCustomImage={renderCustomImage}
        renderFooterComponent={renderFooterComponent}
        renderHeaderComponent={renderHeaderComponent}
      />
    </View>
  );
};

Props

CachedImage accepts the following props:

Properties PropType Description
isOpen Boolean (Required) when to show the gallery.
images Array (Required) array of objects. Every image must have a url (required), a thumbUrl (optional) and id (optional) and any other info you need
resizeMode string React Native Image component resizeMode defaults to contain, used on images
close Func (Required) function to close the gallery image
initialIndex Number Initial index of image to snap when opening the gallery
thumbSize Number Height and width of the thumb, defaults to 48
thumbColor string Outline color of selected thumb, defaults to #d9b44a
thumbResizeMode string React Native Image component resizeMode defaults to cover, used on thumbnails
hideThumbs Boolean Set to true to hide the thumbs defaults to false
renderCustomThumb Func Function to render a custom thumb. Accepts image, index and if the thumb is selected, eg. (image:Image, index:number, isSelected:boolean) => ...
renderCustomImage Func Function to render a custom Image. Accepts image, index and if the thumb is selected, eg. (image:Image, index:number, isSelected:boolean) => ...
renderHeaderComponent Func Function to render a custom header at the top of the screen. Accepts image and current index, eg. (image:Image, currentIndex:number) => ...
renderFooterComponent Func Function to render a custom header at the top of the screen. Accepts image and current index eg. (image:Image, currentIndex:number) => ...

Todo:

  • Add zoom factor
  • Add prop to keep zoom and double tap to zoom out

Authors:

Comments
  • Disable swipe down gesture

    Disable swipe down gesture

    Hi

    Thanks for the library

    We found out that the swipe down gesture is not stable. We try render the gallery inside a navigation stack, now we can close the gallery via the navigation header/mechanism.

    Do we have an option to disable swipe down gesture? It is pretty unstable and useless now.

    opened by namnm 2
  • ThumbScrollView lags when using customThumb

    ThumbScrollView lags when using customThumb

    renderCustomThumb={(item, index, isSelected) => ( <ZStack justifyContent="center" alignItems="center" m={1} w={20} h={20}> <Image borderColor={isSelected ? 'yellow' : 'white'} borderRadius={borderRadius} borderWidth={2} alt="sdfs" source={{uri: item.url}} width={20} height={12} /> {images[index].liked && <FontAwesomeIcon color={COLORS.primary} size={24} icon={faThumbsUp}/> } )}

    When using a customThumb the thumb no longer matches the current image. The yellow borderRadius is applied to the right image in the scrollView, but the scrollView doesn't scroll to the selected image. Any idea why this is?

    opened by JcbPrn 0
  • Gallery lags after vicious swiping

    Gallery lags after vicious swiping

    Hey all.

    First off I really appreciate the effort you've put into this thing. The UI looks pretty clean and the library does function well.

    One thing I did notice is when you start swiping fast, it's like the gallery can't keep up and then just stalls. It's unable to swipe anymore and I can't press on a thumb to take me to another picture.

    I saw some discussion on migrating to react-native-reanimated to solve some gesture issues. Perhaps that would solve this?

    I tested the same swiping on another library react-native-swiper-flatlist and theirs doesn't stall. Maybe you could look into what they did for inspiration?

    opened by lundjrl 2
  • To remove the modal around the images component

    To remove the modal around the images component

    You could consider removing the modal around the images component and adding a style to the props... I, for example, use fullModal and open the images in it, as it is today it opens another modal that occupies the entire screen. In this way, isOpen would no longer be necessary and the opening would be controlled from outside, by route in fullModal, for example.

    opened by adrielschmitz 0
  • Custom style of the gallery (background colour)

    Custom style of the gallery (background colour)

    Currently the background colour of the gallery is using the defined const styles in ImageGallery. Is it possible to take styles from caller so that I can change the background to other colours such as white?

    opened by iners-max 0
Releases(v1.1.0)
Owner
null
vThumb.js - The smallest library to generate video thumbnails on client side.

This package will generate n numbers of thumbnails at different positions in a given video file.

Rajesh Royal 32 Dec 20, 2022
React carousel image gallery component with thumbnail support 🖼

React Carousel Image Gallery Live Demo (try it on mobile for swipe support) linxtion.com/demo/react-image-gallery React image gallery is a React compo

Xiao Lin 3.3k Jan 7, 2023
React for Upload Image Gallery. Drag & Drop, Sortable, Customize.

React Upload Gallery A simple library that lets you create an image gallery, change the order of images, select the highlighted image, and customize i

Minan 66 Oct 14, 2022
Justified image gallery component for React

React Grid Gallery Justified image gallery component for React inspired by Google Photos and based upon React Images. ?? Maintainers wanted ?? As reac

Ben Howell 778 Dec 25, 2022
Minimalistic image gallery for react. Responsive with all important features and smooth animations.

imager Minimalistic image gallery for REACT. Responsive with all important features and smooth animations. DEMO Desktop Phone Slow internet connection

Gaidadei Vladimir 11 Nov 12, 2022
Tutorial for building an image gallery with Supabase (Postgres), Tailwind CSS, Next.js, and Vercel.

Image Gallery with Next.js, Supabase, and Tailwind CSS Learn how to create an image gallery with dynamic content from a PostgreSQL database, with supp

Lee Robinson 134 Dec 31, 2022
React-image-viewer - An image viewer example for react.js

React Image Viewer Demo Installation npm i react-image-viewer-dv Usage import {

Danila Voronkov 10 Nov 17, 2022
🌈 A React image component. Simple realization of image shadow.

?? react-image-shadow A React image component. Simple realization of image shadow.

null 21 Aug 28, 2022
A react component that renders image tag only if the image source is found without error.

Img-or-alt This react component that will render image tag only if the image source is found without error, otherwise it renders only the alt text in

Radi 1 Dec 14, 2021
React Image and Background Image Preloader and Fade in. Load those images in smooth!

React Image and Background Image Fade Fade in images AND background images easily in React ?? ! Demo and Docs are live! react-image-and-background-ima

Nick Porter 27 Dec 4, 2022
Recreate one image using the tiles from another image.

Mosaic Recreate one image using the tiles from another image. https://mosaic.constraint.systems About the algorithm The image proccessing works like t

Constraint Systems 12 Sep 29, 2022
nextjs-image-generation is a POC on how to do server-side image generation.

nextjs-image-generation is a POC on how to do server-side image generation.

Keisuke Nakayama 9 Nov 22, 2022
React Photo Album - a responsive photo gallery component for React

React Photo Album React Photo Album is a responsive photo gallery component for React. React Photo Album supports rows, columns, and masonry layouts.

Igor Danchenko 109 Dec 30, 2022
React Photo Gallery

React Photo Gallery Responsive, accessible, composable, and customizable image gallery component Maintains the original aspect ratio of your photos Cr

Sandra Gonzales 1.8k Dec 27, 2022
A React component to render any Ethereum address's NFTs as a gallery

React NFT Gallery ?? Playground (Storybook) React NFT Gallery is a React component to render any Ethereum address's NFTs as a gallery. The NFT assets

null 7 Jul 19, 2022
A Beautiful And Nice theme React Gallery Template 🔥🎨🎉

Gallery Template Using React ✨ ?? I'm currently learning and working ReactJs and this is my first React project.as you know It's a Gallery Template wi

Arash 31 Dec 17, 2022
lightGallery - A customizable, modular, responsive, lightbox gallery plugin

lightGallery - A customizable, modular, responsive, lightbox gallery plugin

Sachin N 5.6k Dec 30, 2022
Gallery images similar facebook

Gallery images similar facebook

Coding By Jerez 5 Sep 30, 2022
GSwap - Create a gallery of images with ease.

GSwap ?? Create a gallery of images with ease. Working: To get started, in your project folder, run: npm i @dpouris/gswap Usage ?? First, import the l

dpouris 2 May 16, 2022