npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-pan-pinch-view

v2.0.0

Published

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

Downloads

1,444

Readme

react-native-pan-pinch-view

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

👋 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.

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 v3 and the latest 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. | | onTranslationFinished | Function? | undefined | Function to be called on the JS thread with an object containing current position and whether it was clamped (X/Y) |

🛠 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