From 33a8e350bce5735537568ea6dea60822bbbf0ce4 Mon Sep 17 00:00:00 2001 From: JediWattson Date: Sun, 5 Jun 2022 12:18:56 -0400 Subject: [PATCH] removed dry code --- src/components/ImageView/index.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/components/ImageView/index.js b/src/components/ImageView/index.js index 0c4ff813fb4..fd203075de5 100644 --- a/src/components/ImageView/index.js +++ b/src/components/ImageView/index.js @@ -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() { @@ -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;