• This repository has been archived on 29/Sep/2021
  • Stars
    star
    636
  • Rank 70,723 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

react native image pan and zoom

Show Cases

All Contributors

Zoom while sliding

3.gif

Intelligent zoom

2.gif

Getting Started

Installation

npm i react-native-image-pan-zoom --save

Basic Usage

  • Install create-react-native-app first
$ npm install -g create-react-native-app
  • Initialization of a react-native project
$ create-react-native-app AwesomeProject
  • Then, edit AwesomeProject/App.js, like this:
import { Image, Dimensions } from 'react-native';
import ImageZoom from 'react-native-image-pan-zoom';

export default class App extends React.Component {
    render: function() {
        return (
            <ImageZoom cropWidth={Dimensions.get('window').width}
                       cropHeight={Dimensions.get('window').height}
                       imageWidth={200}
                       imageHeight={200}>
                <Image style={{width:200, height:200}}
                       source={{uri:'http://v1.qzone.cc/avatar/201407/07/00/24/53b9782c444ca987.jpg!200x200.jpg'}}/>
            </ImageZoom>
        )
    }
}

Document

Props Type Description DefaultValue
cropWidth(required) number operating area width 100
cropHeight(required) number operating area height 100
imageWidth(required) number picture width 100
imageHeight(required) number picture height 100
onClick (eventParams: IOnClick)=>void onClick ()=>{}
onDoubleClick (eventParams: IOnClick)=>void onDoubleClick ()=>{}
panToMove boolean allow to move picture with one finger true
pinchToZoom boolean allow scale with two fingers true
clickDistance number how many finger movement can also trigger onClick 10
horizontalOuterRangeOffset (offsetX?: number)=>void horizontal beyond the distance, the parent to do picture switching, you can listen to this function. When this function is triggered, you can do the switch operation ()=>{}
onDragLeft ()=>void trigger to switch to the left of the graph, the left sliding speed exceeds the threshold when triggered ()=>{}
responderRelease (vx: number)=>void let go but do not cancel ()=>{}
maxOverflow number maximum sliding threshold 100
longPressTime number long press threshold 800
onLongPress (eventParams: IOnClick)=>void on longPress ()=> {}
doubleClickInterval number time allocated for second click to be considered as doublClick event 175
onMove ( position: IOnMove )=>void reports movement position data (helpful to build overlays) ()=> {}
centerOn { x: number, y: number, scale: number, duration: number } if given this will cause the map to pan and zoom to the desired location undefined
enableSwipeDown boolean for enabling vertical movement if user doesn't want it false
enableCenterFocus boolean for disabling focus on image center if user doesn't want it true
onSwipeDown () => void function that fires when user swipes down null
swipeDownThreshold number threshold for firing swipe down function 230
minScale number minimum zoom scale 0.6
maxScale number maximum zoom scale 10
useNativeDriver boolean Whether to animate using useNativeDriver false
onStartShouldSetPanResponder () => boolean Override onStartShouldSetPanResponder behavior () => true
onMoveShouldSetPanResponder () => boolean Override onMoveShouldSetPanResponder behavior undefined
onPanResponderTerminationRequest () => boolean Override onMoveShouldSetPanResponder behavior () => false
useHardwareTextureAndroid boolean for disabling rendering to hardware texture on Android true
Method params Description
reset Reset the position and the scale of the image
resetScale Reset the scale of the image
centerOn ICenterOn Centers the image in the position indicated. ICenterOn={ x: number, y: number, scale: number, duration: number }

Development pattern

Step 1, run TS listener

After clone this repo, then:

npm install
npm start

Step 2, run demo

cd demo
npm install
npm start

Then, scan the QR, use your expo app.

Contributors

Thanks goes to these wonderful people (emoji key):


Darius

💻

Thomas P.

💻

Juan Di Toro

💻

Alhaytham Elhassan

💻

Alexander Pataridze

💻

Peter Xu

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

More Repositories

1

weekly

前端精读周刊。帮你理解最前沿、实用的技术。
JavaScript
28,194
star
2

react-native-image-viewer

🚀 tiny & fast lib for react native image viewer pan and zoom
TypeScript
2,439
star
3

gaea-editor

Design websites in your browser. A smart web editor!
TypeScript
1,339
star
4

syntax-parser

Light and fast 🚀parser! With zero dependents. - Sql Parser Demo added!
TypeScript
469
star
5

alipay

golang SDK for alipay
Go
458
star
6

blog

博客
263
star
7

avatar

avalon开源中文社区
JavaScript
41
star
8

isomorphic-react-redux-app

react react-hot-loader redux redux-devtools react-router-redux immutable isomorphic
JavaScript
16
star
9

inject-instance

powerful inject instance
TypeScript
12
star
10

dependency-inject

Powerful dependency injection tool
TypeScript
10
star
11

as

基于 martini 的 go语言框架
Go
10
star
12

gaea-render

Render engine for gaea-editor
TypeScript
8
star
13

egg-typeorm

egg plugin for typeorm
JavaScript
8
star
14

woku

我酷官网~
JavaScript
5
star
15

run-react

Integrate webpack
TypeScript
5
star
16

gaea-basic-components

gaea-basic-components
TypeScript
4
star
17

client-ssr

JavaScript
3
star
18

kingdoms

三国军争服务端源代码
Go
3
star
19

gaea-web-components

Gaea 网页端基础组件
TypeScript
3
star
20

vscode-medusa

medusa plugin for vscode
TypeScript
2
star
21

woku-react

我酷科技
JavaScript
2
star
22

rc-stream

react reactive stream
TypeScript
2
star
23

woku_old

我酷旧版
JavaScript
2
star
24

machine-learning

Demos of machine learning
TypeScript
2
star
25

typed-store

Typed React bindings for Redux
TypeScript
2
star
26

shallow-eq

shallow equal
TypeScript
1
star
27

bi-designer

TypeScript
1
star
28

ascoders-tslint-config

ascoders-tslint-config
1
star
29

monaco-editor-commonjs

commonjs monaco-editor
JavaScript
1
star