Skip to content

Commit

Permalink
Refactored Thumbnail Image
Browse files Browse the repository at this point in the history
  • Loading branch information
allroundexperts committed May 27, 2022
1 parent 26dab7c commit 268d43a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/components/ThumbnailImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ const propTypes = {
/** Do the urls require an authToken? */
isAuthTokenRequired: PropTypes.bool.isRequired,

/** Image size */
/** Width of the thumbnail image */
imageWidth: PropTypes.number,

/** Height of the thumbnail image */
imageHeight: PropTypes.number,

...windowDimensionsPropTypes,
Expand All @@ -37,10 +39,10 @@ class ThumbnailImage extends PureComponent {
super(props);

this.updateImageSize = this.updateImageSize.bind(this);
const {width, height} = this.calculateThumbnailImageSize(props.imageWidth, props.imageHeight);
const {thumbnailWidth, thumbnailHeight} = this.calculateThumbnailImageSize(props.imageWidth, props.imageHeight);
this.state = {
thumbnailWidth: width,
thumbnailHeight: height,
thumbnailWidth,
thumbnailHeight,
};
}

Expand Down Expand Up @@ -70,12 +72,12 @@ class ThumbnailImage extends PureComponent {
} else {
thumbnailScreenHeight = Math.round(thumbnailScreenWidth * aspectRatio);
}
return {width: thumbnailScreenWidth, height: thumbnailScreenHeight};
return {thumbnailWidth: thumbnailScreenWidth, thumbnailHeight: Math.max(40, thumbnailScreenHeight)};
}

updateImageSize({width, height}) {
const {width: thumbnailWidth, height: thumbnailScreenHeight} = this.calculateThumbnailImageSize(width, height);
this.setState({thumbnailWidth, thumbnailHeight: Math.max(40, thumbnailScreenHeight)});
const {thumbnailWidth, thumbnailHeight} = this.calculateThumbnailImageSize(width, height);
this.setState({thumbnailWidth, thumbnailHeight});
}

render() {
Expand Down

0 comments on commit 268d43a

Please sign in to comment.