Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@duocvo/react-native-gesture-image

VoDucDuoc302MIT1.1.10TypeScript support: included

This library provides a highly customizable and performant image viewer component for React Native applications. Itsupport advanced gestures such as pinch-to-zoom, panning, and double-tap to zoom in and out, making it ideal for creating rich, interactive

react-native, ios, android, image, viewer, gesture, zoom, pan, double-tap, pinch-to-zoom, image-viewer, react-native-image-viewer, react-native-image-zoom, react-native-image-pan-zoom, react-native-image-gesture, react-native-image-gesture-viewer, gesture-image

readme

@duocvo/react-native-gesture-image

This library provides a highly customizable and performant image viewer component for React Native applications. It supports advanced gestures such as pinch-to-zoom, panning, and double-tap to zoom in and out, making it ideal for creating rich, interactive image viewing experiences. Built with react-native-gesture-handler for handling advanced touch gestures like pinch and pan, and react-native-reanimated for providing smooth animations for zooming and panning.

Prerequisites

This library relies on the following dependencies to enable gesture and animation support (you need to setup these library below)

Installation

npm install @duocvo/react-native-gesture-image
#or
yarn add @duocvo/react-native-gesture-image

Usage

import React, { useRef } from 'react';
import { View, StyleSheet, TouchableOpacity, Image } from 'react-native';
import Gallery from '@duocvo/react-native-gesture-image';

export default function App() {
  const galleryRef = useRef(null);

  const images = [
    { uri: 'https://picsum.photos/200/300' },
    { uri: 'https://picsum.photos/200/300' },
    { uri: 'https://picsum.photos/200/300' },
  ];

  return (
    <View style={styles.container}>
      {/* Thumbnail images that open the gallery when tapped */}
      <View style={styles.thumbnails}>
        {images.map((image, index) => (
          <TouchableOpacity 
            key={index} 
            onPress={() => galleryRef.current?.show(index)}
          >
            <Image source={image} style={styles.thumbnail} />
          </TouchableOpacity>
        ))}
      </View>

      {/* Gallery component */}
      <Gallery 
        ref={galleryRef}
        data={images} 
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  thumbnails: {
    flexDirection: 'row',
    flexWrap: 'wrap',
    padding: 10,
  },
  thumbnail: {
    width: 100,
    height: 100,
    margin: 5,
  },
});

Props

Prop Type Default Description Required
data array [] Array of image sources Yes
style object | Custom style for the gallery container No
imageStyle object | Custom style for each image No
containerStyle object | Custom style for the gallery container No
contentContainerStyle object | Custom style for the content container No
backdropColor string black Background color of the gallery No
initialIndex number 0 Initial index of the image to display No
enablePanDownToClose boolean false Enable closing the gallery by panning down No
renderHeader function | Custom header component No
renderFooter function | Custom footer component No
Method Parameters Description
show index?: number Show the gallery, optionally at a specific index
hide - Hide the gallery

Examples

import React, { useRef } from 'react';
import { View, StyleSheet, TouchableOpacity, Image, Text } from 'react-native';
import Gallery from '@duocvo/react-native-gesture-image';

export default function App() {
  const galleryRef = useRef(null);

  const images = [
    { uri: 'https://picsum.photos/200/300' },
    { uri: 'https://picsum.photos/200/300' },
    { uri: 'https://picsum.photos/200/300' },
  ];

  return (
    <View style={styles.container}>
      {/* Thumbnail images that open the gallery when tapped */}
      <View style={styles.thumbnails}>
        {images.map((image, index) => (
          <TouchableOpacity 
            key={index} 
            onPress={() => galleryRef.current?.show(index)}
          >
            <Image source={image} style={styles.thumbnail} />
          </TouchableOpacity>
        ))}
      </View>

      {/* Gallery component with custom header and footer */}
      <Gallery 
        ref={galleryRef}
        data={images}
        renderHeader={() => (
          <View style={styles.header}>
            <TouchableOpacity onPress={() => galleryRef.current?.hide()}>
              <Text style={styles.headerText}>Close</Text>
            </TouchableOpacity>
          </View>
        )}
        renderFooter={() => (
          <View style={styles.footer}>
            <Text style={styles.footerText}>Image Caption</Text>
          </View>
        )}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  thumbnails: {
    flexDirection: 'row',
    flexWrap: 'wrap',
    padding: 10,
  },
  thumbnail: {
    width: 100,
    height: 100,
    margin: 5,
  },
  header: {
    padding: 16,
    flexDirection: 'row',
    justifyContent: 'space-between',
  },
  headerText: {
    color: 'white',
    fontSize: 16,
  },
  footer: {
    padding: 16,
  },
  footerText: {
    color: 'white',
    fontSize: 14,
  },
});

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

changelog

Changelog

1.1.6 (2025-04-21)

  • chore: update package.json and add types for ImageViewer and Gallery components (9cce4cb)

1.1.5 (2025-04-21)

  • chore: update dependencies and configuration (30b4a77)

1.1.4 (2025-04-21)

  • chore: refactor type imports and add types file (217a0ea)

1.1.3 (2025-04-20)

  • chore: update component name (7e06642)

1.1.2 (2025-04-20)

  • chore: update import path for Gallery component and enhance type definitions (88bce23)

1.1.1 (2025-04-20)

  • chore: update ts config (853cfd0)

1.1.0 (2025-04-20)

  • chore: remove console.log (baa51af)
  • chore: update version and add header/footer (4d6614f)
  • feat(gallery): enhance gallery and image viewer components (f9bf5fe)

1.0.3 (2025-03-31)

1.0.2 (2025-03-31)

  • chore: bump package version to 1.0.2 and update README demo (08ab8b8)

1.0.1 (2025-03-12)

  • chore: bump package version to 1.0.0 and update README example (c859694)
  • chore: set package version and simplify README (2bcd15e)

0.4.2 (2025-03-12)

  • chore: downgrade react-native-gesture-handler and react-native-reanimated (68e6e43)

0.4.1 (2025-03-11)

  • chore: upgrade react-native-gesture-handler and react-native-reanimated dependencies (b0d6b16)

0.4.0 (2025-03-11)

  • chore: remove exports configuration from package.json (436782f)
  • feat: wrap Gallery component with GestureHandlerRootView for gesture handling (dc967b2)

0.3.1 (2025-03-11)

  • chore: remove deprecated type definitions file (8229155)

0.3.0 (2025-03-11)

  • feat: improve TypeScript configuration and add type definitions (5c048ae)

0.2.0 (2025-03-11)

  • chore: initial commit (b481dbc)
  • chore: update example project dependencies and import path (3c5454e)
  • chore: update release-it configuration for conventional commits and changelog (95f29cf)
  • fix: rename package to @duocvo/react-native-gesture-image and update dependencies (8e7e415)
  • Update README.md (4f78ba3)
  • feat: add image gallery component and related assets (e30c21d)