Skip to content

Commit 1edf080

Browse files
authored
Merge pull request #9 from Moinax/master
Fix example so it uses the right component ReactPinchZoomPan and add initialScale property
2 parents 4b3cc60 + 31efba5 commit 1edf080

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ and open [localhost:3001](http://localhost:3001)
4848
```
4949
import React, {Component} from 'react'
5050
import s from 'react-prefixr'
51-
import {PinchPanZoom} from 'react-pinch-zoom-pan'
51+
import {ReactPinchPanZoom} from 'react-pinch-zoom-pan'
5252
5353
export default class App extends Component {
5454
@@ -76,7 +76,7 @@ export default class App extends Component {
7676
const {height,width} = this.props
7777
const ratio = (height / width) * 100
7878
return (
79-
<PinchPanZoom maxScale={2} render={obj => {
79+
<ReactPinchPanZoom maxScale={2} render={obj => {
8080
return (
8181
<div style={this.getContainerStyle(ratio)}>
8282
<div style={this.getInnerStyle()}>
@@ -110,6 +110,19 @@ The component exposes 2 event listeners: `onPinchStart` and `onPinchStop`. These
110110
}} />
111111
</PinchView>
112112
```
113+
### Usage initial scale
114+
115+
The component exposes a prop to set the `initialScale`. This can be used to display the content with zoomed in by default
116+
117+
```
118+
<PinchView debug backgroundColor='#ddd' initalScale={2} maxScale={4} containerRatio={100}>
119+
<img src={'http://lorempixel.com/400/600/nature/'} style={{
120+
margin: 'auto',
121+
width: 'auto',
122+
height: '100%'
123+
}} />
124+
</PinchView>
125+
```
113126

114127
## Discussion
115128

demo/App.js

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ export default class App extends Component {
3131
height: '100%'
3232
}} />
3333
</PinchView>
34+
<h2>Initial scale</h2>
35+
<p>This allow you to display the content scaled (zoom x2)</p>
36+
<PinchView debug backgroundColor='#ddd' initialScale={2} maxScale={4} containerRatio={100} onPinchStart={() => console.log('pinch started')} onPinchStop={() => console.log('pinch stopped')}>
37+
<img src={'http://lorempixel.com/400/600/nature/'} style={{
38+
margin: 'auto',
39+
width: 'auto',
40+
height: '100%'
41+
}} />
42+
</PinchView>
3443
</div>
3544
)
3645
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-pinch-zoom-pan",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "A react component that lets you add pinch-zoom and pan sub components",
55
"main": "lib/index.js",
66
"scripts": {

src/PinchView.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class PinchView extends Component {
5151
}
5252

5353
render () {
54-
const {debug, maxScale, holderClassName, containerClassName, children, onPinchStart, onPinchStop} = this.props
54+
const {debug, initialScale, maxScale, holderClassName, containerClassName, children, onPinchStart, onPinchStop} = this.props
5555
return (
56-
<ReactPinchZoomPan maxScale={maxScale} render={(obj) => {
56+
<ReactPinchZoomPan initialScale={initialScale} maxScale={maxScale} render={(obj) => {
5757
return (
5858
<div style={this.getHolderStyle()} className={holderClassName}>
5959
<div style={this.getContainerStyle()} className={containerClassName}>
@@ -72,6 +72,7 @@ class PinchView extends Component {
7272
}
7373

7474
PinchView.defaultProps = {
75+
initialScale: 1,
7576
maxScale: 2,
7677
containerRatio: 100,
7778
backgroundColor: '#f2f2f2',
@@ -80,6 +81,7 @@ PinchView.defaultProps = {
8081

8182
PinchView.propTypes = {
8283
containerRatio: PropTypes.number,
84+
initialScale: PropTypes.number,
8385
maxScale: PropTypes.number,
8486
children: PropTypes.element,
8587
containerClassName: PropTypes.string,

src/ReactPinchZoomPan.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ReactPinchZoomPan extends Component {
4545
super(props)
4646
this.state = {
4747
obj: {
48-
scale: 1,
48+
scale: props.initialScale,
4949
x: 0,
5050
y: 0
5151
},
@@ -191,13 +191,15 @@ class ReactPinchZoomPan extends Component {
191191
}
192192

193193
ReactPinchZoomPan.defaultProps = {
194+
initialScale: 1,
194195
maxScale: 2
195196
}
196197

197198
ReactPinchZoomPan.propTypes = {
198199
render: PropTypes.func,
199200
onPinchStart: PropTypes.func,
200201
onPinchStop: PropTypes.func,
202+
initialScale: PropTypes.number,
201203
maxScale: PropTypes.number
202204
}
203205

0 commit comments

Comments
 (0)