1.1.8 • Published 6 months ago

@duocvo/react-native-gesture-image v1.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@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

Gallery

PropTypeDefaultDescriptionRequired
dataarray[]Array of image sourcesYes
styleobjectCustom style for the gallery containerNo
imageStyleobjectCustom style for each imageNo
containerStyleobjectCustom style for the gallery containerNo
contentContainerStyleobjectCustom style for the content containerNo
backdropColorstringblackBackground color of the galleryNo
initialIndexnumber0Initial index of the image to displayNo
enablePanDownToClosebooleanfalseEnable closing the gallery by panning downNo
renderHeaderfunctionCustom header componentNo
renderFooterfunctionCustom footer componentNo

Gallery Ref Methods

MethodParametersDescription
showindex?: numberShow the gallery, optionally at a specific index
hide-Hide the gallery

Examples

Basic Usage with Header and Footer

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

1.1.8

6 months ago

1.1.7

6 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.4

6 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago

0.4.2

7 months ago

0.4.1

8 months ago

0.4.0

8 months ago

0.3.1

8 months ago

0.3.0

8 months ago

0.2.0

8 months ago

0.1.0

8 months ago