diff --git a/web/media/multimedia-modal.react.js b/web/media/multimedia-modal.react.js --- a/web/media/multimedia-modal.react.js +++ b/web/media/multimedia-modal.react.js @@ -130,8 +130,8 @@ const multimediaModal = React.useMemo( () => ( {mediaModalItem} diff --git a/web/modals/full-screen-view-modal.react.js b/web/modals/full-screen-view-modal.react.js --- a/web/modals/full-screen-view-modal.react.js +++ b/web/modals/full-screen-view-modal.react.js @@ -12,8 +12,8 @@ type BaseProps = { +children: React.Node, - +contentDimensions: ?Dimensions, - +setContentDimensions: SetState, + +dynamicContentDimensions?: ?Dimensions, + +setDynamicContentDimensions?: SetState, }; type Props = { @@ -27,12 +27,15 @@ componentDidMount() { invariant(this.overlay, 'overlay ref unset'); this.overlay.focus(); - this.calculateMediaDimensions(); - window.addEventListener('resize', this.calculateMediaDimensions); + this.calculateDynamicContentDimensions(); + window.addEventListener('resize', this.calculateDynamicContentDimensions); } componentWillUnmount() { - window.removeEventListener('resize', this.calculateMediaDimensions); + window.removeEventListener( + 'resize', + this.calculateDynamicContentDimensions, + ); } render(): React.Node { @@ -75,27 +78,36 @@ } }; - calculateMediaDimensions: () => void = () => { - if (!this.overlay || !this.props.contentDimensions) { + calculateDynamicContentDimensions: () => mixed = () => { + const { dynamicContentDimensions, setDynamicContentDimensions } = + this.props; + + if ( + !this.overlay || + !dynamicContentDimensions || + !setDynamicContentDimensions + ) { return; } + const containerWidth = this.overlay.clientWidth; const containerHeight = this.overlay.clientHeight; const containerAspectRatio = containerWidth / containerHeight; - const { width: mediaWidth, height: mediaHeight } = - this.props.contentDimensions; - const mediaAspectRatio = mediaWidth / mediaHeight; + const { width: contentWidth, height: contentHeight } = + dynamicContentDimensions; + const contentAspectRatio = contentWidth / contentHeight; let newWidth, newHeight; - if (containerAspectRatio > mediaAspectRatio) { - newWidth = Math.min(mediaWidth, containerHeight * mediaAspectRatio); - newHeight = newWidth / mediaAspectRatio; + if (containerAspectRatio > contentAspectRatio) { + newWidth = Math.min(contentWidth, containerHeight * contentAspectRatio); + newHeight = newWidth / contentAspectRatio; } else { - newHeight = Math.min(mediaHeight, containerWidth / mediaAspectRatio); - newWidth = newHeight * mediaAspectRatio; + newHeight = Math.min(contentHeight, containerWidth / contentAspectRatio); + newWidth = newHeight * contentAspectRatio; } - this.props.setContentDimensions({ + + setDynamicContentDimensions({ width: newWidth, height: newHeight, });