Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 1436f23

Browse files
authored
Fix image preview sizing for edge cases (#8322)
1 parent ffeab40 commit 1436f23

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

res/css/views/messages/_MImageBody.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ $timeline-image-border-radius: 8px;
3838
// Necessary for the border radius to apply correctly to the placeholder
3939
overflow: hidden;
4040
contain: paint;
41+
42+
min-height: $font-44px;
43+
min-width: $font-44px;
44+
display: flex;
45+
justify-content: center;
46+
align-items: center;
4147
}
4248

4349
.mx_MImageBody_thumbnail {

res/css/views/rooms/_EventBubbleTile.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ limitations under the License.
114114
padding-right: 48px;
115115
}
116116

117+
.mx_MImageBody_thumbnail_container {
118+
min-height: calc(1.8rem + var(--gutterSize) + var(--gutterSize));
119+
min-width: calc(1.8rem + var(--gutterSize) + var(--gutterSize));
120+
}
121+
117122
.mx_CallEvent {
118123
background-color: unset;
119124

src/components/views/messages/MImageBody.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,12 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
364364

365365
let infoWidth: number;
366366
let infoHeight: number;
367+
let infoSvg = false;
367368

368369
if (content.info?.w && content.info?.h) {
369370
infoWidth = content.info.w;
370371
infoHeight = content.info.h;
372+
infoSvg = content.info.mimetype.startsWith("image/svg");
371373
} else {
372374
// Whilst the image loads, display nothing. We also don't display a blurhash image
373375
// because we don't really know what size of image we'll end up with.
@@ -449,6 +451,11 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
449451
'mx_MImageBody_placeholder--blurhash': this.props.mxEvent.getContent().info?.[BLURHASH_FIELD],
450452
});
451453

454+
// many SVGs don't have an intrinsic size if used in <img> elements.
455+
// due to this we have to set our desired width directly.
456+
// this way if the image is forced to shrink, the height adapts appropriately.
457+
const sizing = infoSvg ? { maxHeight, maxWidth, width: maxWidth } : { maxHeight, maxWidth };
458+
452459
const thumbnail = (
453460
<div className="mx_MImageBody_thumbnail_container" style={{ maxHeight, maxWidth, aspectRatio: `${infoWidth}/${infoHeight}` }}>
454461
<SwitchTransition mode="out-in">
@@ -463,7 +470,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
463470
</CSSTransition>
464471
</SwitchTransition>
465472

466-
<div style={{ maxHeight, maxWidth }}>
473+
<div style={sizing}>
467474
{ img }
468475
{ gifLabel }
469476
</div>

0 commit comments

Comments
 (0)