Skip to content

Commit

Permalink
removed dry code
Browse files Browse the repository at this point in the history
  • Loading branch information
JediWattson committed Jul 20, 2022
1 parent 0e0cdf1 commit 33a8e35
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/components/ImageView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,11 @@ class ImageView extends PureComponent {
}

componentDidMount() {
Image.getSize(this.props.url, (width, height) => {
this.setImageRegion(width, height);
});
if (this.canUseTouchScreen) {
return;
}
document.addEventListener('mousemove', this.trackMovement.bind(this));
this.updateImageSize(true);
}

componentDidUpdate() {
if (this.canUseTouchScreen) {
return;
}
Image.getSize(this.props.url, (width, height) => {
this.setImageRegion(width, height);
});
this.updateImageSize(true);
}

componentWillUnmount() {
Expand Down Expand Up @@ -182,6 +171,22 @@ class ImageView extends PureComponent {
return {offsetX, offsetY};
}

/**
* ideally this is called everytime the prop url changes to update any differences in size
* @param {Boolean} isMounting
*/
updateImageSize(isMounting) {
if (this.canUseTouchScreen) {
return;
}
Image.getSize(this.props.url, (width, height) => {
this.setImageRegion(width, height);
});
if (isMounting) {
document.addEventListener('mousemove', this.trackMovement.bind(this));
}
}

trackMovement(e) {
if (!this.state.isZoomed) {
return;
Expand Down

0 comments on commit 33a8e35

Please sign in to comment.