From 429c945bbf5979fce25b2bc3e21dd6298bf65b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 2 Apr 2021 10:37:42 +0200 Subject: [PATCH] Don't allow translation when zoomed out MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/elements/ImageView.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/views/elements/ImageView.js b/src/components/views/elements/ImageView.js index ef2cc7d2ce..cc20e04135 100644 --- a/src/components/views/elements/ImageView.js +++ b/src/components/views/elements/ImageView.js @@ -191,6 +191,12 @@ export default class ImageView extends React.Component { ev.stopPropagation(); ev.preventDefault(); + // Zoom in if we are completely zoomed out + if (this.state.zoom === MIN_ZOOM) { + this.setState({zoom: MAX_ZOOM}); + return; + } + this.setState({moving: true}); this.previousX = this.state.translationX; this.previousY = this.state.translationY; @@ -213,21 +219,17 @@ export default class ImageView extends React.Component { } onEndMoving = () => { - // Zoom in or out if we haven't moved much + // Zoom out if we haven't moved much if ( this.state.moving === true && Math.abs(this.state.translationX - this.previousX) < 10 && Math.abs(this.state.translationY - this.previousY) < 10 ) { - if (this.state.zoom === MIN_ZOOM) { - this.setState({zoom: MAX_ZOOM}); - } else { - this.setState({ - zoom: MIN_ZOOM, - translationX: 0, - translationY: 0, - }); - } + this.setState({ + zoom: MIN_ZOOM, + translationX: 0, + translationY: 0, + }); } this.setState({moving: false}); }