Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resizes on image upload #8928

Merged
merged 11 commits into from
Jun 3, 2022
11 changes: 9 additions & 2 deletions src/components/ThumbnailImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ class ThumbnailImage extends PureComponent {
* @param {Number} height - Height of the original image.
* @returns {Object} - Object containing thumbnails width and height.
*/

calculateThumbnailImageSize(width, height) {
if (!width || !height) { return {}; }
if (!width || !height) {
return {};
}

// Width of the thumbnail works better as a constant than it does
// a percentage of the screen width since it is relative to each screen
Expand All @@ -75,6 +76,12 @@ class ThumbnailImage extends PureComponent {
return {thumbnailWidth: thumbnailScreenWidth, thumbnailHeight: Math.max(40, thumbnailScreenHeight)};
}

/**
* Update the state with the computed thumbnail sizes.
*
* @param {{ width: number, height: number }} Params - width and height of the original image.
* @returns {void}
allroundexperts marked this conversation as resolved.
Show resolved Hide resolved
*/
updateImageSize({width, height}) {
allroundexperts marked this conversation as resolved.
Show resolved Hide resolved
const {thumbnailWidth, thumbnailHeight} = this.calculateThumbnailImageSize(width, height);
this.setState({thumbnailWidth, thumbnailHeight});
Expand Down