From 3e497794de9b24056166c635b70f64aff7ca4db4 Mon Sep 17 00:00:00 2001 From: Ivan Wang Date: Tue, 11 Apr 2017 17:41:18 -0700 Subject: [PATCH] Only drag sprites when mousedown starts on the sprite --- src/containers/stage.jsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/containers/stage.jsx b/src/containers/stage.jsx index e5e0c0602..377a104dc 100644 --- a/src/containers/stage.jsx +++ b/src/containers/stage.jsx @@ -23,6 +23,7 @@ class Stage extends React.Component { ]); this.state = { mouseDownTimeoutId: null, + mouseDownPosition: null, isDragging: false, dragOffset: null, dragId: null @@ -73,9 +74,11 @@ class Stage extends React.Component { } onMouseMove (e) { const mousePosition = [e.clientX - this.rect.left, e.clientY - this.rect.top]; - this.cancelMouseDownTimeout(); - if (this.state.mouseDown && !this.state.isDragging) { - this.onStartDrag(mousePosition[0], mousePosition[1]); + if (this.state.mouseDownTimeoutId !== null) { + this.cancelMouseDownTimeout(); + if (this.state.mouseDown && !this.state.isDragging) { + this.onStartDrag(...this.state.mouseDownPosition); + } } if (this.state.mouseDown && this.state.isDragging) { const spritePosition = this.getScratchCoords(mousePosition[0], mousePosition[1]); @@ -96,7 +99,8 @@ class Stage extends React.Component { onMouseUp (e) { this.cancelMouseDownTimeout(); this.setState({ - mouseDown: false + mouseDown: false, + mouseDownPosition: null, }); if (this.state.isDragging) { this.onStopDrag(); @@ -115,6 +119,7 @@ class Stage extends React.Component { const mousePosition = [e.clientX - this.rect.left, e.clientY - this.rect.top]; this.setState({ mouseDown: true, + mouseDownPosition: mousePosition, mouseDownTimeoutId: setTimeout( this.onStartDrag.bind(this, mousePosition[0], mousePosition[1]), 500