GithubHelp home page GithubHelp logo

moonjava2005 / react-native-pinch-zoom-layout Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 99 KB

Zoom content view as native

License: MIT License

Java 60.60% JavaScript 39.40%
react-native pinch-to-zoom pinchimageview

react-native-pinch-zoom-layout's Introduction

react-native-pinch-zoom-layout

Getting started

$ npm install react-native-pinch-zoom-layout --save

Or

$ yarn add react-native-pinch-zoom-layout

Mostly automatic installation

$ react-native link react-native-pinch-zoom-layout

Manual installation

iOS

No action required

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import info.moonjava.RNPinchZoomLayoutPackage; to the imports at the top of the file
  • Add new RNPinchZoomLayoutPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-pinch-zoom-layout'
    project(':react-native-pinch-zoom-layout').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-pinch-zoom-layout/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      implementation project(':react-native-pinch-zoom-layout')
    

Dependencies

Install and link react-native-gesture-handler. To install and link it, run:

yarn add react-native-gesture-handler
react-native link react-native-gesture-handler

Usage

import React,{Component} from 'react';
import PinchZoomLayout from 'react-native-pinch-zoom-layout';
import {
    Image
} from 'react-native';

export default class ImageViewer extends Component {
    pinZoomLayoutRef=React.createRef();
    render() {
       return(<PinchZoomLayout
                          style={{flex:1}}
                          ref={this.pinZoomLayoutRef}
                          onZoom={this.onZoom}
                          onTap={this.onTap}
                      >
                          <Image
                                style={{width:56,height:56}}
                                source={{
                                  uri:'https://facebook.github.io/react-native/img/header_logo.png'
                              }}
                          />
                      </PinchZoomLayout>)
    }
    
    onZoom=event=>{
        const {
            containerWidth,
            containerHeight,
            contentWidth,
            contentHeight,
            zoomScale
        }=event;
    }
    
    onTap=()=>{
        
    }
}

Configurable props

Event props

Methods

Configurable props

enabled

Indicates whether the layout allows zoom.

  • true (default) - allow zoom
  • false - Disable zoom

panEnabled

Indicates whether the layout can pan when the zoomed content is bigger than the container.

  • true (default) - Allow pan
  • false - Disable pan

zoomDuration

Animation duration of zoom.

  • default - 400 Platforms: Android

minimumZoomScale

The minimum zoom level.

  • default - 1

maximumZoomScale

The maximum zoom level.

  • default - 3

onZoom

Callback function that is called when the view is zoomed. The event params is

const { 
  containerWidth,
  containerHeight,
  contentWidth,
  contentHeight,
  zoomScale
} = event;

onTap

Callback function that is called when the view is taped

zoom()

zoom({zoomScale, animated})

Zoom the content view to specific value.

Example:

this.pinZoomLayoutRef.current.zoom({zoomScale:2.5, animated:true}); // Zoom content view to 2.5 with animation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.