🔍 A view component for React Native with pinch to zoom and drag to pan functionality.

Overview

react-native-pan-pinch-view

npm (scoped)

A view component for React Native with pinch to zoom and drag to pan functionality.

iOS Example App Gif Android Example App Gif

👋 Introduction

Even though the demo shows the library used with images, it was initially designed to show <View>s representing blueprints of rooms.

  • Pinch to zoom with two fingers
  • Drag one finger to pan
  • Keep content inside container boundaries
  • Configurable minimum and maximum scale
  • Methods for programmatically updating position and scale

Thanks to react-native-reanimated all animations are running on the UI thread, so no fps drops are experienced.

AFAIK, Expo users should be able to use it once Expo updates to[email protected].

If you want to zoom in on images exclusively, in a gallery-like UI, I recommend these packages, rather than my library:

👀 Prerequisites

This library uses react-native-reanimated v2 and the new API of react-native-gesture-handler.

Before installing it, you need to install those two libraries and set them up in your project:

⚙️ Installation

npm install react-native-pan-pinch-view

✂️ Usage

import PanPinchView from "react-native-pan-pinch-view";

// ...

const CONTAINER = {
  width: 300,
  height: 300,
};

const CONTENT = {
  width: 900,
  height: 400,
};
// ...

<PanPinchView
  minScale={1}
  initialScale={1}
  containerDimensions={{
    width: CONTAINER.width,
    height: CONTAINER.height,
  }}
  contentDimensions={{ width: CONTENT.width, height: CONTENT.height }}
>
  <Image
    style={[styles.image]}
    source={require('./assets/photo.jpg')}
  />
</PanPinchView>

// ...

const styles = StyleSheet.create({
  image: {
    width: CONTENT.width,
    height: CONTENT.height,
  },
});

Props

Property Type Default Description
containerDimensions Object {width: number, height:number} Width and height of the viewable area.
contentDimensions Object {width: number, height:number} Width and height of the zoomable view.
minScale Number? 0.5 Minimum value of scale.
maxScale Number? 4 Maximum value of scale.
initialScale Number? 1 Initial value of scale.

🛠 Methods

Method Params Return Description
scaleTo value: number, animated: boolean void Sets sharedValue scale to value,
if animated is true uses withTiming
setContentSize width: number, height: number void Updates sharedValue contentSize and overrides prop: contentDimensions
translateTo x: number, y: number, animated: boolean void Updates content translateX / translateY,
if animated is true uses withTiming
setMinScale value: number void Updates minScale value
setMaxScale value: number void Updates maxScale value
getScale number Returns current value of sharedValue scale

You can also refer to the app inside example/ for a running demo of this library.

Contributing

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

License

MIT

You might also like...

A plugin for Strapi CMS that adds a preview button and live view button to the content manager edit view.

A plugin for Strapi CMS that adds a preview button and live view button to the content manager edit view.

Strapi Preview Button A plugin for Strapi CMS that adds a preview button and live view button to the content manager edit view. Get Started Features I

Dec 30, 2022

Simple jQuery plugin that will allow users to zoom in your images, perfect for product images and galleries.

Simple jQuery plugin that will allow users to zoom in your images, perfect for product images and galleries.

Image Zoom (jQuery) Plugin Simple jQuery plugin that will allow users to zoom in your images, perfect for product images and galleries that is less th

Aug 3, 2022

A command-line tool to convert Project Zomboid map data into Deep Zoom format

A command-line tool to convert Project Zomboid map data into Deep Zoom format

pzmap2dzi pzmap2dzi is a command-line tool running on Windows to convert Project Zomboid map data into Deep Zoom format. Features Supports both python

Dec 31, 2022

My very own fantastic jQuery ZOOM plugin.

My very own fantastic jQuery ZOOM plugin.

jQuery ZOOM plugin Coded by Robert Koteles, Senior Frontend Developer, 2015. This plugin was coded by me while worked as senior web developer/web mana

Oct 13, 2022

ezoom.js is a jQuery plugin for simple Image with zoom effect.

ezoom.js ezoom.js is a jQuery plugin for simple Image with zoom effect. This plugin in under development to support Next/Prev a gallery Images/SVG lat

Sep 3, 2022

Dependency-free implementation of zoom.js (no jQuery or Bootstrap)

Dependency-free implementation of zoom.js (no jQuery or Bootstrap)

ZOOM.JS Repo status Nov 2020: Maintained, but bug fixes only. No new features currently, please. There may eventually be a new major version with new

Jan 3, 2023

Next-level academia! Repository for the Native Overleaf project, attempting to integrate Overleaf with native OS features for macOS, Linux and Windows.

Next-level academia! Repository for the Native Overleaf project, attempting to integrate Overleaf with native OS features for macOS, Linux and Windows.

Native Overleaf Overleaf is a fantastic webtool for writing and cooperating on LaTeX documents. However, would it not be even better if it were to beh

Dec 18, 2022

View component and controller of YouTube Player API, for fresh framework.

View component and controller of YouTube Player API, for fresh framework.

fresh-youtube View component and controller of YouTube Player API, for fresh framework. Try it now! git clone [email protected]:otiai10/fresh-youtube.git

Nov 2, 2022

Digispark Overmaster : free IDE TOOL allows to create and edit Digispark Scripts by the drag and drop technique,with cool GUI and easy to use it

Digispark Overmaster : free IDE TOOL allows to create and edit Digispark Scripts by the drag and drop technique,with cool GUI and easy to use it

Digispark_Overmaster Digispark Overmaster : free IDE TOOL allows to create and edit Digispark Scripts by the drag and drop technique,with cool GUI and

Nov 14, 2022
Comments
  • Question about coordinate system of translateTo

    Question about coordinate system of translateTo

    I'm trying to use this library to perform pans, but am having the hardest time figuring out what coordinate system the translateTo method is expecting?

    As far as I can tell, it is dependent on the current scale, but I can't seem to figure out what coordinates it is expecting to make logical sense.

    Would it be possible to get a more concrete example, perhaps using the following variables:

      const logicalX = 0.5; // logical X coordinate, from [0,1];
      const logicalY = 0.5; // logical Y coordinate, from [0,1];
      // scale, contentWidth, contentHeight, containerWidth, containerHeight
      ref.translateTo(???,???, true);
    

    My goal is to get the point represented by logicalX/logicalY to be 'centered' on the screen, at the current zoom level.

    If it matters, my contentWidth/contentHeight are always larger than both containerWidth/containerHeight.

    good first issue 
    opened by zzorba 2
  • Not rendering when using 100% as width

    Not rendering when using 100% as width

    Hi

    I've been trying to use this component instead of https://github.com/likashefqet/react-native-image-zoom due to the reason that the zoom does not snap back when releasing the pinch move. But it seems I can not use 100% as a width for the content dimension and/or container dimension property. It just leads to the <Image /> not loading.

    Example code:

    <PanPinchView
      minScale={1}
      maxScale={3}
      contentDimensions={{width: '100%', height: 500}} // <-- 100% here does not work
      containerDimensions={{width: '100%', height: calculatedHeight}} // <-- 100% here does not work either
    >
    	  <Image
    	    borderRadius={5}
    	    source={{uri: imageUrl}}
    	    resizeMode="contain"
    	    style={{width: '100%', height: imageScaledHeight}}
    	  />
    </PanPinchView>
    
    opened by carestad 2
  • Support for React 17?

    Support for React 17?

    I am trying to install the package for my React Native (v0.67) project, but I am getting an error about the react depenceny as it seems to rely on React 16.x.x. Is it possible to adapt to React 17 and possibly 18 as well?

    opened by carestad 1
Releases(v1.0.1)
Owner
Ivanka Todorova
Ivanka Todorova
Easy Pan and Zoom JS Library

EasyPZ Use this Javascript library to make your web visualization interactive via pan and zoom, for mobile and desktop! EasyPZ supports many interacti

Micha Schwab 129 Nov 21, 2022
This repository contains an Advanced Zoom Apps Sample. It should serve as a starting point for you to build and test your own Zoom App in development.

Advanced Zoom Apps Sample Advanced Sample covers most complex scenarios that you might be needed in apps. App has reference implementation for: Authen

Zoom 11 Dec 17, 2022
Make drag-and-drop easier using DropPoint. Drag content without having to open side-by-side windows

Make drag-and-drop easier using DropPoint! DropPoint helps you drag content without having to open side-by-side windows Works on Windows, Linux and Ma

Sudev Suresh Sreedevi 391 Dec 29, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Fancytree - JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading

Fancytree Fancytree (sequel of DynaTree 1.x) is a JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkb

Martin Wendt 2.6k Jan 9, 2023
It's a simple Leaderboard with the functionality to add and view leaderboard with API calls

It's a simple Leaderboard with the functionality to add and view leaderboard with API calls. This project follows GitFlow instead of GitHub flow and it's built with JavaScript, CSS and HTML.

Robertson Arthur 4 Jul 6, 2022
Conveyer adds Drag gestures to your Native Scroll.

Conveyer Demo / Documentation / Other components Conveyer adds Drag gestures to your Native Scroll. ?? ?? ?? ✨ Features You can use Native Scroll-like

NAVER 70 Dec 15, 2022
StarkNet support extension for VSCode. Visualize StarkNet contracts: view storage variables, external and view functions, and events.

StarkNet Explorer extension This VSCode extension quickly shows relevant aspects of StarkNet contracts: Storage variables of the current contract, and

Crytic 6 Nov 4, 2022