Fix some image/video scroll jumps (#8182)
* Fix some image/video scroll jumps * Fix aspect ratio formatting * Fix videos not being responsive to timeline width
This commit is contained in:
parent
afa60acbf1
commit
af6bd63ac7
5 changed files with 90 additions and 86 deletions
|
@ -27,7 +27,7 @@ import MFileBody from './MFileBody';
|
|||
import Modal from '../../../Modal';
|
||||
import { _t } from '../../../languageHandler';
|
||||
import SettingsStore from "../../../settings/SettingsStore";
|
||||
import InlineSpinner from '../elements/InlineSpinner';
|
||||
import Spinner from '../elements/Spinner';
|
||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||
import { Media, mediaFromContent } from "../../../customisations/Media";
|
||||
import { BLURHASH_FIELD, createThumbnail } from "../../../ContentMessages";
|
||||
|
@ -427,15 +427,6 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
|
|||
className="mx_MImageBody_thumbnail"
|
||||
src={thumbUrl}
|
||||
ref={this.image}
|
||||
// Force the image to be the full size of the container, even if the
|
||||
// pixel size is smaller. The problem here is that we don't know what
|
||||
// thumbnail size the HS is going to give us, but we have to commit to
|
||||
// a container size immediately and not change it when the image loads
|
||||
// or we'll get a scroll jump (or have to leave blank space).
|
||||
// This will obviously result in an upscaled image which will be a bit
|
||||
// blurry. The best fix would be for the HS to advertise what size thumbnails
|
||||
// it guarantees to produce.
|
||||
style={{ height: '100%' }}
|
||||
alt={content.body}
|
||||
onError={this.onImageError}
|
||||
onLoad={this.onImageLoad}
|
||||
|
@ -456,44 +447,32 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
|
|||
}
|
||||
|
||||
const classes = classNames({
|
||||
'mx_MImageBody_thumbnail': true,
|
||||
'mx_MImageBody_thumbnail--blurhash': this.props.mxEvent.getContent().info?.[BLURHASH_FIELD],
|
||||
'mx_MImageBody_placeholder': true,
|
||||
'mx_MImageBody_placeholder--blurhash': this.props.mxEvent.getContent().info?.[BLURHASH_FIELD],
|
||||
});
|
||||
|
||||
// This has incredibly broken types.
|
||||
const C = CSSTransition as any;
|
||||
const thumbnail = (
|
||||
<div className="mx_MImageBody_thumbnail_container" style={{ maxHeight, maxWidth, aspectRatio: `${infoWidth}/${infoHeight}` }}>
|
||||
<SwitchTransition mode="out-in">
|
||||
<C
|
||||
<CSSTransition
|
||||
classNames="mx_rtg--fade"
|
||||
key={`img-${showPlaceholder}`}
|
||||
timeout={300}
|
||||
>
|
||||
{ /* This weirdly looking div is necessary here, otherwise SwitchTransition fails */ }
|
||||
<div>
|
||||
{ showPlaceholder && <div
|
||||
className={classes}
|
||||
style={{
|
||||
// Constrain width here so that spinner appears central to the loaded thumbnail
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
aspectRatio: `${infoWidth}/${infoHeight}`,
|
||||
}}
|
||||
>
|
||||
{ placeholder }
|
||||
</div> }
|
||||
</div>
|
||||
</C>
|
||||
{ showPlaceholder ? <div className={classes}>
|
||||
{ placeholder }
|
||||
</div> : <></> /* Transition always expects a child */ }
|
||||
</CSSTransition>
|
||||
</SwitchTransition>
|
||||
|
||||
<div style={{
|
||||
height: '100%',
|
||||
}}>
|
||||
<div style={{ maxHeight, maxWidth }}>
|
||||
{ img }
|
||||
{ gifLabel }
|
||||
</div>
|
||||
|
||||
{ /* HACK: This div fills out space while the image loads, to prevent scroll jumps */ }
|
||||
{ !this.state.imgLoaded && <div style={{ height: maxHeight, width: maxWidth }} /> }
|
||||
|
||||
{ this.state.hover && this.getTooltip() }
|
||||
</div>
|
||||
);
|
||||
|
@ -514,14 +493,12 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
|
|||
|
||||
if (blurhash) {
|
||||
if (this.state.placeholder === Placeholder.NoImage) {
|
||||
return <div className="mx_no-image-placeholder" style={{ width: width, height: height }} />;
|
||||
return null;
|
||||
} else if (this.state.placeholder === Placeholder.Blurhash) {
|
||||
return <Blurhash className="mx_Blurhash" hash={blurhash} width={width} height={height} />;
|
||||
}
|
||||
}
|
||||
return (
|
||||
<InlineSpinner w={32} h={32} />
|
||||
);
|
||||
return <Spinner w={32} h={32} />;
|
||||
}
|
||||
|
||||
// Overidden by MStickerBody
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue