Don't allow translation when zoomed out

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-04-02 10:37:42 +02:00
parent 722178e26e
commit 429c945bbf
No known key found for this signature in database
GPG Key ID: 9760693FDD98A790
1 changed files with 12 additions and 10 deletions

View File

@ -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});
}