Skip to content

Commit

Permalink
docs(clickToZoom): add image preview for clickToZoom
Browse files Browse the repository at this point in the history
  • Loading branch information
pitipatdop committed Feb 22, 2017
1 parent 06d7226 commit 339d7b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ all normal `<img />` props can be used
- scale = 1, the image will cover the whole area precisely.
- `clickToZoom` (Boolean: default = false) if true then user can click to zoomIn
- `zoomInScale` determine value of zoomed-in scale when clickToZoom
![img](http://i.giphy.com/3o84TYe7Y9yOFHFnIQ.gif)

Note: If you do not provide resizeMode, `<BetterImg />` will just render normal `<img />`

Expand Down
2 changes: 1 addition & 1 deletion dev/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class App extends Component {
&lt;BetterImg scale={1} focalPoint="50% 50%"/&gt;
</pre>
<BetterImg
src="/img/puppy-line.jpg"
src="/img/puppy.jpg"
height={600}
resizeMode="cover"
scale={1}
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class BetterImg extends Component {
state = {
imgWidth: 0,
imgHeight: 0,
imgLoaded: false,
imgClicked: false,
currentZoomScale: this.props.scale,
focalPoint: this.props.focalPoint,
containerWidth: undefined,
Expand All @@ -119,6 +121,7 @@ class BetterImg extends Component {
this.setState({
imgWidth,
imgHeight,
imgLoaded: true,
containerHeight: this.props.height || imgHeight,
});

Expand Down Expand Up @@ -160,12 +163,14 @@ class BetterImg extends Component {
if (!this.state.isZoomedIn) {
this.setState({
isZoomedIn: true,
imgClicked: true,
currentZoomScale: this.props.zoomInScale,
focalPoint: `${pointX/containerWidth} ${pointY/containerHeight}`
});
} else {
this.setState({
isZoomedIn: false,
imgClicked: true,
currentZoomScale: this.props.scale,
focalPoint: 'center',
});
Expand Down Expand Up @@ -221,8 +226,8 @@ class BetterImg extends Component {
transform: `translate3d(${x}px, ${y}px, 0) scale(${scaleX}, ${scaleY})`,
transformOrigin: '0% 0%',
}
if (this.props.clickToZoom && this.state.imgClicked) imgStyle.transition = 'all .3s ease-out';

if (this.props.clickToZoom) imgStyle.transition = 'all .3s ease-out';
const containerProps = {};
if (this.props.clickToZoom) {
containerProps.onClick = this.handleClick;
Expand Down

0 comments on commit 339d7b7

Please sign in to comment.