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

v1.0.1

Published

"Pan and pinch (zoom) component for React Native, based on reanimated"

Downloads

14

Readme

Intro

This is a pan and pinch component for React Native that

  • handles touch inputs (zooming and panning)
  • limits panning and zooming to boundaries (min and max movements on x and y axis, min and max zoom levels) and
  • sets all required attributes on children to transform them correspondingly.

Prerequisites

  • Your React Native setup must be linked to React Native Reanimated.
  • If you use an up-to-date version of Expo, React Native Reanimated is preinstalled and already linked.

Usage

  1. Create a child element that will be transformed:

    // Box.js
    import React from 'react';
    import { StyleSheet } from 'react-native';
    import Animated from 'react-native-reanimated';
    
    export default class Box extends React.Component {
    
        render() {
            return (
                 <Animated.View 
                    style={[styles.box, {
                        // props.animatedLeft, props.animatedTop and props.animatedZoom were added
                        // to this component by PanPinch. They are all of type Animated.Node.
                        transform: [{
                            translateX: this.props.animatedLeft,
                        }, {
                            translateY: this.props.animatedTop,
                        }, {
                            scale: this.props.animatedZoom,
                        }],
                    }]}
                />
            );
        }
    
    }
    
    const styles = StyleSheet.create({
        box: {
            backgroundColor: "tomato",
            width: 200,
            height: 200,
        },
    });
    
  2. Create a parent component that renders PanPinch and children you'd like to transform.

    // App.js
    
    import React from 'react';
    import PanPinch from 'react-native-pan-pinch';
    import { StyleSheet, View } from 'react-native';
    import Box from './Box';
    
    export default class App extends React.Component {
    
        state = {
            dimensions: [],
        }
    
        handleLayout(ev) {
            const {width, height} = ev.nativeEvent.layout;
            this.setState({ dimensions: [width, height] });
        }
    
        render() {
            return (
                { /* In this case, we want this view to serve as the boundaries for Box. Therefore
                     we have to view its layout change and update containerDimensions on PanPinch
                     accordingly */ }
                <View
                    style={styles.container}
                    onLayout={(ev) => this.handleLayout(ev)}
                >
                    <PanPinch containerDimensions={this.state.dimensions}>
                        <Box />
                    </PanPinch>
                </View>
            );
        }
    
    }
    
    const styles = StyleSheet.create({
        container: {
            width: '80%',
            height: '80%'
        },
    });

API

Props

  • containerDimensions: Takes an array of 2 numbers (width and height of the boundaries in which the PanPinch's content can move), e.g. [200, 400] if we want to restrict x pan to 200 and y pan to 400 px.

Limitations

  • Boundaries cannot yet be set; will be added as soon as Expo uses a newer version of React Native Reanimated (setValue doesn't work yet).
  • Zoom level is not yet respected for movement boundaries on x and y axis.