diff --git a/app/javascript/flavours/glitch/components/media_gallery.js b/app/javascript/flavours/glitch/components/media_gallery.js
index 309308d25ad..5169ead5aaf 100644
--- a/app/javascript/flavours/glitch/components/media_gallery.js
+++ b/app/javascript/flavours/glitch/components/media_gallery.js
@@ -136,16 +136,21 @@ class Item extends React.PureComponent {
let thumbnail = '';
if (attachment.get('type') === 'image') {
- const previewUrl = attachment.get('preview_url');
+ const previewUrl = attachment.get('preview_url');
const previewWidth = attachment.getIn(['meta', 'small', 'width']);
- const originalUrl = attachment.get('url');
- const originalWidth = attachment.getIn(['meta', 'original', 'width']);
+ const originalUrl = attachment.get('url');
+ const originalWidth = attachment.getIn(['meta', 'original', 'width']);
const hasSize = typeof originalWidth === 'number' && typeof previewWidth === 'number';
const srcSet = hasSize ? `${originalUrl} ${originalWidth}w, ${previewUrl} ${previewWidth}w` : null;
- const sizes = hasSize ? `(min-width: 1025px) ${320 * (width / 100)}px, ${width}vw` : null;
+ const sizes = hasSize ? `(min-width: 1025px) ${320 * (width / 100)}px, ${width}vw` : null;
+
+ const focusX = attachment.getIn(['meta', 'focus', 'x']) || 0;
+ const focusY = attachment.getIn(['meta', 'focus', 'y']) || 0;
+ const x = ((focusX / 2) + .5) * 100;
+ const y = ((focusY / -2) + .5) * 100;
thumbnail = (
-
+
);
} else if (attachment.get('type') === 'gifv') {
@@ -225,30 +237,59 @@ export default class MediaGallery extends React.PureComponent {
this.props.onOpenMedia(this.props.media, index);
}
+ handleRef = (node) => {
+ if (node && this.isStandaloneEligible()) {
+ // offsetWidth triggers a layout, so only calculate when we need to
+ this.setState({
+ width: node.offsetWidth,
+ });
+ }
+ }
+
+ isStandaloneEligible() {
+ const { media, standalone } = this.props;
+ return standalone && media.size === 1 && media.getIn([0, 'meta', 'small', 'aspect']);
+ }
+
render () {
- const {
- handleClick,
- handleOpen,
- } = this;
- const {
- fullwidth,
- intl,
- letterbox,
- media,
- sensitive,
- standalone,
- } = this.props;
- const { visible } = this.state;
+ const { media, intl, sensitive, letterbox, fullwidth } = this.props;
+ const { width, visible } = this.state;
const size = media.take(4).size;
+
+ let children;
+
+ const style = {};
+
+ if (this.isStandaloneEligible() && width) {
+ style.height = width / this.props.media.getIn([0, 'meta', 'small', 'aspect']);
+ }
+
+ if (!visible) {
+ let warning =