Skip to content

Commit

Permalink
correctly fix up thumbnail height onload.
Browse files Browse the repository at this point in the history
fixes element-hq/element-web#6492, although popping is inevitable in
the current implementation as it only fixes up the thumbnail size once the image has loaded.
  • Loading branch information
ara4n committed Apr 29, 2018
1 parent 731f1fa commit 551d3eb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/views/messages/MImageBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class extends React.Component {

this.onAction = this.onAction.bind(this);
this.onImageError = this.onImageError.bind(this);
this.onImageLoad = this.onImageLoad.bind(this);
this.onImageEnter = this.onImageEnter.bind(this);
this.onImageLeave = this.onImageLeave.bind(this);
this.onClientSync = this.onClientSync.bind(this);
Expand Down Expand Up @@ -137,6 +138,11 @@ export default class extends React.Component {
});
}

onImageLoad() {
this.fixupHeight();
this.props.onWidgetLoad();
}

_getContentUrl() {
const content = this.props.mxEvent.getContent();
if (content.file !== undefined) {
Expand Down Expand Up @@ -170,7 +176,6 @@ export default class extends React.Component {

componentDidMount() {
this.dispatcherRef = dis.register(this.onAction);
this.fixupHeight();
const content = this.props.mxEvent.getContent();
if (content.file !== undefined && this.state.decryptedUrl === null) {
let thumbnailPromise = Promise.resolve(null);
Expand All @@ -192,7 +197,6 @@ export default class extends React.Component {
decryptedThumbnailUrl: thumbnailUrl,
decryptedBlob: decryptedBlob,
});
this.props.onWidgetLoad();
});
}).catch((err) => {
console.warn("Unable to decrypt attachment: ", err);
Expand Down Expand Up @@ -244,7 +248,7 @@ export default class extends React.Component {

// FIXME: It will also break really badly for images with broken or missing thumbnails

//console.log("trying to fit image into timelineWidth of " + this.refs.body.offsetWidth + " or " + this.refs.body.clientWidth);
// console.log("trying to fit image into timelineWidth of " + this.refs.body.offsetWidth + " or " + this.refs.body.clientWidth);
let thumbHeight = null;
if (content.info) {
thumbHeight = ImageUtils.thumbHeight(content.info.w, content.info.h, timelineWidth, maxHeight);
Expand All @@ -259,7 +263,7 @@ export default class extends React.Component {
<img className="mx_MImageBody_thumbnail" src={thumbUrl} ref="image"
alt={content.body}
onError={this.onImageError}
onLoad={this.props.onWidgetLoad}
onLoad={this.onImageLoad}
onMouseEnter={this.onImageEnter}
onMouseLeave={this.onImageLeave} />
</a>
Expand Down

0 comments on commit 551d3eb

Please sign in to comment.