2018-04-09 00:15:25 +03:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-11-02 22:16:38 +02:00
|
|
|
import IconButton from 'flavours/glitch/components/icon_button';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
compress: { id: 'lightbox.compress', defaultMessage: 'Compress image view box' },
|
|
|
|
expand: { id: 'lightbox.expand', defaultMessage: 'Expand image view box' },
|
|
|
|
});
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
const MIN_SCALE = 1;
|
|
|
|
const MAX_SCALE = 4;
|
2020-11-02 22:16:38 +02:00
|
|
|
const NAV_BAR_HEIGHT = 66;
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
const getMidpoint = (p1, p2) => ({
|
|
|
|
x: (p1.clientX + p2.clientX) / 2,
|
|
|
|
y: (p1.clientY + p2.clientY) / 2,
|
|
|
|
});
|
|
|
|
|
|
|
|
const getDistance = (p1, p2) =>
|
|
|
|
Math.sqrt(Math.pow(p1.clientX - p2.clientX, 2) + Math.pow(p1.clientY - p2.clientY, 2));
|
|
|
|
|
|
|
|
const clamp = (min, max, value) => Math.min(max, Math.max(min, value));
|
|
|
|
|
2020-11-02 22:16:38 +02:00
|
|
|
// Normalizing mousewheel speed across browsers
|
|
|
|
// copy from: https://github.com/facebookarchive/fixed-data-table/blob/master/src/vendor_upstream/dom/normalizeWheel.js
|
|
|
|
const normalizeWheel = event => {
|
|
|
|
// Reasonable defaults
|
|
|
|
const PIXEL_STEP = 10;
|
|
|
|
const LINE_HEIGHT = 40;
|
|
|
|
const PAGE_HEIGHT = 800;
|
|
|
|
|
|
|
|
let sX = 0,
|
|
|
|
sY = 0, // spinX, spinY
|
|
|
|
pX = 0,
|
|
|
|
pY = 0; // pixelX, pixelY
|
|
|
|
|
|
|
|
// Legacy
|
|
|
|
if ('detail' in event) {
|
|
|
|
sY = event.detail;
|
|
|
|
}
|
|
|
|
if ('wheelDelta' in event) {
|
|
|
|
sY = -event.wheelDelta / 120;
|
|
|
|
}
|
|
|
|
if ('wheelDeltaY' in event) {
|
|
|
|
sY = -event.wheelDeltaY / 120;
|
|
|
|
}
|
|
|
|
if ('wheelDeltaX' in event) {
|
|
|
|
sX = -event.wheelDeltaX / 120;
|
|
|
|
}
|
|
|
|
|
|
|
|
// side scrolling on FF with DOMMouseScroll
|
|
|
|
if ('axis' in event && event.axis === event.HORIZONTAL_AXIS) {
|
|
|
|
sX = sY;
|
|
|
|
sY = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pX = sX * PIXEL_STEP;
|
|
|
|
pY = sY * PIXEL_STEP;
|
|
|
|
|
|
|
|
if ('deltaY' in event) {
|
|
|
|
pY = event.deltaY;
|
|
|
|
}
|
|
|
|
if ('deltaX' in event) {
|
|
|
|
pX = event.deltaX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pX || pY) && event.deltaMode) {
|
|
|
|
if (event.deltaMode === 1) { // delta in LINE units
|
|
|
|
pX *= LINE_HEIGHT;
|
|
|
|
pY *= LINE_HEIGHT;
|
|
|
|
} else { // delta in PAGE units
|
|
|
|
pX *= PAGE_HEIGHT;
|
|
|
|
pY *= PAGE_HEIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall-back if spin cannot be determined
|
|
|
|
if (pX && !sX) {
|
|
|
|
sX = (pX < 1) ? -1 : 1;
|
|
|
|
}
|
|
|
|
if (pY && !sY) {
|
|
|
|
sY = (pY < 1) ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
spinX: sX,
|
|
|
|
spinY: sY,
|
|
|
|
pixelX: pX,
|
|
|
|
pixelY: pY,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default @injectIntl
|
|
|
|
class ZoomableImage extends React.PureComponent {
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
alt: PropTypes.string,
|
|
|
|
src: PropTypes.string.isRequired,
|
|
|
|
width: PropTypes.number,
|
|
|
|
height: PropTypes.number,
|
|
|
|
onClick: PropTypes.func,
|
2020-11-02 22:16:38 +02:00
|
|
|
zoomButtonHidden: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
alt: '',
|
|
|
|
width: null,
|
|
|
|
height: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
scale: MIN_SCALE,
|
2020-11-02 22:16:38 +02:00
|
|
|
zoomMatrix: {
|
2020-11-04 21:43:31 +02:00
|
|
|
type: null, // 'width' 'height'
|
|
|
|
fullScreen: null, // bool
|
2020-11-02 22:16:38 +02:00
|
|
|
rate: null, // full screen scale rate
|
|
|
|
clientWidth: null,
|
|
|
|
clientHeight: null,
|
|
|
|
offsetWidth: null,
|
|
|
|
offsetHeight: null,
|
|
|
|
clientHeightFixed: null,
|
|
|
|
scrollTop: null,
|
|
|
|
scrollLeft: null,
|
2020-11-04 21:43:31 +02:00
|
|
|
translateX: null,
|
|
|
|
translateY: null,
|
2020-11-02 22:16:38 +02:00
|
|
|
},
|
|
|
|
zoomState: 'expand', // 'expand' 'compress'
|
|
|
|
navigationHidden: false,
|
|
|
|
dragPosition: { top: 0, left: 0, x: 0, y: 0 },
|
|
|
|
dragged: false,
|
|
|
|
lockScroll: { x: 0, y: 0 },
|
2020-11-04 21:43:31 +02:00
|
|
|
lockTranslate: { x: 0, y: 0 },
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
removers = [];
|
|
|
|
container = null;
|
|
|
|
image = null;
|
|
|
|
lastTouchEndTime = 0;
|
|
|
|
lastDistance = 0;
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
let handler = this.handleTouchStart;
|
|
|
|
this.container.addEventListener('touchstart', handler);
|
|
|
|
this.removers.push(() => this.container.removeEventListener('touchstart', handler));
|
|
|
|
handler = this.handleTouchMove;
|
|
|
|
// on Chrome 56+, touch event listeners will default to passive
|
|
|
|
// https://www.chromestatus.com/features/5093566007214080
|
|
|
|
this.container.addEventListener('touchmove', handler, { passive: false });
|
|
|
|
this.removers.push(() => this.container.removeEventListener('touchend', handler));
|
2020-11-02 22:16:38 +02:00
|
|
|
|
|
|
|
handler = this.mouseDownHandler;
|
|
|
|
this.container.addEventListener('mousedown', handler);
|
|
|
|
this.removers.push(() => this.container.removeEventListener('mousedown', handler));
|
|
|
|
|
|
|
|
handler = this.mouseWheelHandler;
|
|
|
|
this.container.addEventListener('wheel', handler);
|
|
|
|
this.removers.push(() => this.container.removeEventListener('wheel', handler));
|
|
|
|
// Old Chrome
|
|
|
|
this.container.addEventListener('mousewheel', handler);
|
|
|
|
this.removers.push(() => this.container.removeEventListener('mousewheel', handler));
|
|
|
|
// Old Firefox
|
|
|
|
this.container.addEventListener('DOMMouseScroll', handler);
|
|
|
|
this.removers.push(() => this.container.removeEventListener('DOMMouseScroll', handler));
|
|
|
|
|
|
|
|
this.initZoomMatrix();
|
2018-04-09 00:15:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
this.removeEventListeners();
|
|
|
|
}
|
|
|
|
|
2020-11-02 22:16:38 +02:00
|
|
|
componentDidUpdate () {
|
2020-11-04 21:43:31 +02:00
|
|
|
this.setState({ zoomState: this.state.scale >= this.state.zoomMatrix.rate ? 'compress' : 'expand' });
|
|
|
|
|
|
|
|
if (this.state.scale === MIN_SCALE) {
|
|
|
|
this.container.style.removeProperty('cursor');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UNSAFE_componentWillReceiveProps () {
|
|
|
|
// reset when slide to next image
|
2020-11-02 22:16:38 +02:00
|
|
|
if (this.props.zoomButtonHidden) {
|
2020-11-04 21:43:31 +02:00
|
|
|
this.setState({
|
|
|
|
scale: MIN_SCALE,
|
|
|
|
lockTranslate: { x: 0, y: 0 },
|
|
|
|
}, () => {
|
2020-11-02 22:16:38 +02:00
|
|
|
this.container.scrollLeft = 0;
|
|
|
|
this.container.scrollTop = 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-09 00:15:25 +03:00
|
|
|
removeEventListeners () {
|
|
|
|
this.removers.forEach(listeners => listeners());
|
|
|
|
this.removers = [];
|
|
|
|
}
|
|
|
|
|
2020-11-02 22:16:38 +02:00
|
|
|
mouseWheelHandler = e => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
const event = normalizeWheel(e);
|
|
|
|
|
2020-11-04 21:43:31 +02:00
|
|
|
if (this.state.zoomMatrix.type === 'width') {
|
2020-11-02 22:16:38 +02:00
|
|
|
// full width, scroll vertical
|
2020-11-03 07:06:45 +02:00
|
|
|
this.container.scrollTop = Math.max(this.container.scrollTop + event.pixelY, this.state.lockScroll.y);
|
2020-11-02 22:16:38 +02:00
|
|
|
} else {
|
|
|
|
// full height, scroll horizontal
|
2020-11-03 07:06:45 +02:00
|
|
|
this.container.scrollLeft = Math.max(this.container.scrollLeft + event.pixelY, this.state.lockScroll.x);
|
2020-11-02 22:16:38 +02:00
|
|
|
}
|
2020-11-03 07:06:45 +02:00
|
|
|
|
|
|
|
// lock horizontal scroll
|
|
|
|
this.container.scrollLeft = Math.max(this.container.scrollLeft + event.pixelX, this.state.lockScroll.x);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2020-11-02 22:16:38 +02:00
|
|
|
|
|
|
|
mouseDownHandler = e => {
|
|
|
|
this.container.style.cursor = 'grabbing';
|
|
|
|
this.container.style.userSelect = 'none';
|
|
|
|
|
|
|
|
this.setState({ dragPosition: {
|
|
|
|
left: this.container.scrollLeft,
|
|
|
|
top: this.container.scrollTop,
|
|
|
|
// Get the current mouse position
|
|
|
|
x: e.clientX,
|
|
|
|
y: e.clientY,
|
|
|
|
} });
|
|
|
|
|
|
|
|
this.image.addEventListener('mousemove', this.mouseMoveHandler);
|
|
|
|
this.image.addEventListener('mouseup', this.mouseUpHandler);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2020-11-02 22:16:38 +02:00
|
|
|
|
|
|
|
mouseMoveHandler = e => {
|
|
|
|
const dx = e.clientX - this.state.dragPosition.x;
|
|
|
|
const dy = e.clientY - this.state.dragPosition.y;
|
|
|
|
|
2020-11-03 07:06:45 +02:00
|
|
|
this.container.scrollLeft = Math.max(this.state.dragPosition.left - dx, this.state.lockScroll.x);
|
|
|
|
this.container.scrollTop = Math.max(this.state.dragPosition.top - dy, this.state.lockScroll.y);
|
2020-11-02 22:16:38 +02:00
|
|
|
|
|
|
|
this.setState({ dragged: true });
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2020-11-02 22:16:38 +02:00
|
|
|
|
|
|
|
mouseUpHandler = () => {
|
|
|
|
this.container.style.cursor = 'grab';
|
|
|
|
this.container.style.removeProperty('user-select');
|
|
|
|
|
|
|
|
this.image.removeEventListener('mousemove', this.mouseMoveHandler);
|
|
|
|
this.image.removeEventListener('mouseup', this.mouseUpHandler);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2020-11-02 22:16:38 +02:00
|
|
|
|
2018-04-09 00:15:25 +03:00
|
|
|
handleTouchStart = e => {
|
|
|
|
if (e.touches.length !== 2) return;
|
|
|
|
|
|
|
|
this.lastDistance = getDistance(...e.touches);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
handleTouchMove = e => {
|
|
|
|
const { scrollTop, scrollHeight, clientHeight } = this.container;
|
|
|
|
if (e.touches.length === 1 && scrollTop !== scrollHeight - clientHeight) {
|
|
|
|
// prevent propagating event to MediaModal
|
|
|
|
e.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (e.touches.length !== 2) return;
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
const distance = getDistance(...e.touches);
|
|
|
|
const midpoint = getMidpoint(...e.touches);
|
2020-11-02 22:16:38 +02:00
|
|
|
const _MAX_SCALE = Math.max(MAX_SCALE, this.state.zoomMatrix.rate);
|
|
|
|
const scale = clamp(MIN_SCALE, _MAX_SCALE, this.state.scale * distance / this.lastDistance);
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
this.zoom(scale, midpoint);
|
|
|
|
|
|
|
|
this.lastMidpoint = midpoint;
|
|
|
|
this.lastDistance = distance;
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
zoom(nextScale, midpoint) {
|
2020-11-04 21:43:31 +02:00
|
|
|
const { scale, zoomMatrix } = this.state;
|
2018-04-09 00:15:25 +03:00
|
|
|
const { scrollLeft, scrollTop } = this.container;
|
|
|
|
|
|
|
|
// math memo:
|
|
|
|
// x = (scrollLeft + midpoint.x) / scrollWidth
|
|
|
|
// x' = (nextScrollLeft + midpoint.x) / nextScrollWidth
|
|
|
|
// scrollWidth = clientWidth * scale
|
|
|
|
// scrollWidth' = clientWidth * nextScale
|
|
|
|
// Solve x = x' for nextScrollLeft
|
|
|
|
const nextScrollLeft = (scrollLeft + midpoint.x) * nextScale / scale - midpoint.x;
|
|
|
|
const nextScrollTop = (scrollTop + midpoint.y) * nextScale / scale - midpoint.y;
|
|
|
|
|
|
|
|
this.setState({ scale: nextScale }, () => {
|
|
|
|
this.container.scrollLeft = nextScrollLeft;
|
|
|
|
this.container.scrollTop = nextScrollTop;
|
2020-11-04 21:43:31 +02:00
|
|
|
// reset the translateX/Y constantly
|
|
|
|
if (nextScale < zoomMatrix.rate) {
|
|
|
|
this.setState({
|
|
|
|
lockTranslate: {
|
|
|
|
x: zoomMatrix.fullScreen ? 0 : zoomMatrix.translateX * ((nextScale - MIN_SCALE) / (zoomMatrix.rate - MIN_SCALE)),
|
|
|
|
y: zoomMatrix.fullScreen ? 0 : zoomMatrix.translateY * ((nextScale - MIN_SCALE) / (zoomMatrix.rate - MIN_SCALE)),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2018-04-09 00:15:25 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClick = e => {
|
|
|
|
// don't propagate event to MediaModal
|
|
|
|
e.stopPropagation();
|
2020-11-02 22:16:38 +02:00
|
|
|
const dragged = this.state.dragged;
|
|
|
|
this.setState({ dragged: false });
|
|
|
|
if (dragged) return;
|
2018-04-09 00:15:25 +03:00
|
|
|
const handler = this.props.onClick;
|
|
|
|
if (handler) handler();
|
2020-11-02 22:16:38 +02:00
|
|
|
this.setState({ navigationHidden: !this.state.navigationHidden });
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2020-11-02 22:16:38 +02:00
|
|
|
|
|
|
|
handleMouseDown = e => {
|
|
|
|
e.preventDefault();
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2020-11-02 22:16:38 +02:00
|
|
|
|
|
|
|
initZoomMatrix = () => {
|
|
|
|
const { width, height } = this.props;
|
|
|
|
const { clientWidth, clientHeight } = this.container;
|
|
|
|
const { offsetWidth, offsetHeight } = this.image;
|
|
|
|
const clientHeightFixed = clientHeight - NAV_BAR_HEIGHT;
|
|
|
|
|
2020-11-04 21:43:31 +02:00
|
|
|
const type = width / height < clientWidth / clientHeightFixed ? 'width' : 'height';
|
|
|
|
const fullScreen = type === 'width' ? width > clientWidth : height > clientHeightFixed;
|
|
|
|
const rate = type === 'width' ? Math.min(clientWidth, width) / offsetWidth : Math.min(clientHeightFixed, height) / offsetHeight;
|
|
|
|
const scrollTop = type === 'width' ? (clientHeight - offsetHeight) / 2 - NAV_BAR_HEIGHT : (clientHeightFixed - offsetHeight) / 2;
|
2020-11-02 22:16:38 +02:00
|
|
|
const scrollLeft = (clientWidth - offsetWidth) / 2;
|
2020-11-04 21:43:31 +02:00
|
|
|
const translateX = type === 'width' ? (width - offsetWidth) / (2 * rate) : 0;
|
|
|
|
const translateY = type === 'height' ? (height - offsetHeight) / (2 * rate) : 0;
|
2020-11-02 22:16:38 +02:00
|
|
|
|
|
|
|
this.setState({
|
|
|
|
zoomMatrix: {
|
|
|
|
type: type,
|
2020-11-04 21:43:31 +02:00
|
|
|
fullScreen: fullScreen,
|
2020-11-02 22:16:38 +02:00
|
|
|
rate: rate,
|
|
|
|
clientWidth: clientWidth,
|
|
|
|
clientHeight: clientHeight,
|
|
|
|
offsetWidth: offsetWidth,
|
|
|
|
offsetHeight: offsetHeight,
|
|
|
|
clientHeightFixed: clientHeightFixed,
|
|
|
|
scrollTop: scrollTop,
|
|
|
|
scrollLeft: scrollLeft,
|
2020-11-04 21:43:31 +02:00
|
|
|
translateX: translateX,
|
|
|
|
translateY: translateY,
|
2020-11-02 22:16:38 +02:00
|
|
|
},
|
|
|
|
});
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2020-11-02 22:16:38 +02:00
|
|
|
|
|
|
|
handleZoomClick = e => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
const { scale, zoomMatrix } = this.state;
|
|
|
|
|
|
|
|
if ( scale >= zoomMatrix.rate ) {
|
2020-11-03 07:06:45 +02:00
|
|
|
this.setState({
|
|
|
|
scale: MIN_SCALE,
|
|
|
|
lockScroll: {
|
2020-11-02 22:16:38 +02:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
2020-11-03 07:06:45 +02:00
|
|
|
},
|
2020-11-04 21:43:31 +02:00
|
|
|
lockTranslate: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
},
|
2020-11-03 07:06:45 +02:00
|
|
|
}, () => {
|
|
|
|
this.container.scrollLeft = 0;
|
|
|
|
this.container.scrollTop = 0;
|
2020-11-02 22:16:38 +02:00
|
|
|
});
|
|
|
|
} else {
|
2020-11-03 07:06:45 +02:00
|
|
|
this.setState({
|
|
|
|
scale: zoomMatrix.rate,
|
|
|
|
lockScroll: {
|
2020-11-02 22:16:38 +02:00
|
|
|
x: zoomMatrix.scrollLeft,
|
|
|
|
y: zoomMatrix.scrollTop,
|
2020-11-03 07:06:45 +02:00
|
|
|
},
|
2020-11-04 21:43:31 +02:00
|
|
|
lockTranslate: {
|
|
|
|
x: zoomMatrix.fullScreen ? 0 : zoomMatrix.translateX,
|
|
|
|
y: zoomMatrix.fullScreen ? 0 : zoomMatrix.translateY,
|
|
|
|
},
|
2020-11-03 07:06:45 +02:00
|
|
|
}, () => {
|
|
|
|
this.container.scrollLeft = zoomMatrix.scrollLeft;
|
|
|
|
this.container.scrollTop = zoomMatrix.scrollTop;
|
2020-11-02 22:16:38 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.container.style.cursor = 'grab';
|
|
|
|
this.container.style.removeProperty('user-select');
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
setContainerRef = c => {
|
|
|
|
this.container = c;
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
setImageRef = c => {
|
|
|
|
this.image = c;
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
render () {
|
2020-11-02 22:16:38 +02:00
|
|
|
const { alt, src, width, height, intl } = this.props;
|
2020-11-04 21:43:31 +02:00
|
|
|
const { scale, lockTranslate } = this.state;
|
|
|
|
const overflow = scale === MIN_SCALE ? 'hidden' : 'scroll';
|
|
|
|
const zoomButtonShouldHide = this.state.navigationHidden || this.props.zoomButtonHidden || this.state.zoomMatrix.rate <= MIN_SCALE ? 'media-modal__zoom-button--hidden' : '';
|
2020-11-02 22:16:38 +02:00
|
|
|
const zoomButtonTitle = this.state.zoomState === 'compress' ? intl.formatMessage(messages.compress) : intl.formatMessage(messages.expand);
|
2018-04-09 00:15:25 +03:00
|
|
|
|
|
|
|
return (
|
2020-11-02 22:16:38 +02:00
|
|
|
<React.Fragment>
|
|
|
|
<IconButton
|
2020-11-04 21:43:31 +02:00
|
|
|
className={`media-modal__zoom-button ${zoomButtonShouldHide}`}
|
2020-11-02 22:16:38 +02:00
|
|
|
title={zoomButtonTitle}
|
|
|
|
icon={this.state.zoomState}
|
|
|
|
onClick={this.handleZoomClick}
|
|
|
|
size={40}
|
2018-04-09 00:15:25 +03:00
|
|
|
style={{
|
2020-11-02 22:16:38 +02:00
|
|
|
fontSize: '30px', /* Fontawesome's fa-compress fa-expand is larger than fa-close */
|
2018-04-09 00:15:25 +03:00
|
|
|
}}
|
|
|
|
/>
|
2020-11-02 22:16:38 +02:00
|
|
|
<div
|
|
|
|
className='zoomable-image'
|
|
|
|
ref={this.setContainerRef}
|
|
|
|
style={{ overflow }}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
role='presentation'
|
|
|
|
ref={this.setImageRef}
|
|
|
|
alt={alt}
|
|
|
|
title={alt}
|
|
|
|
src={src}
|
|
|
|
width={width}
|
|
|
|
height={height}
|
|
|
|
style={{
|
2020-11-04 21:43:31 +02:00
|
|
|
transform: `scale(${scale}) translate(-${lockTranslate.x}px, -${lockTranslate.y}px)`,
|
2020-11-02 22:16:38 +02:00
|
|
|
transformOrigin: '0 0',
|
|
|
|
}}
|
|
|
|
draggable={false}
|
|
|
|
onClick={this.handleClick}
|
|
|
|
onMouseDown={this.handleMouseDown}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</React.Fragment>
|
2018-04-09 00:15:25 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|