Skip to content

Apply a drag threshold to make clicking sprites easier #1434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/containers/stage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../reducers/color-picker';

const colorPickerRadius = 20;
const dragThreshold = 3; // Same as the block drag threshold

class Stage extends React.Component {
constructor (props) {
Expand Down Expand Up @@ -149,9 +150,13 @@ class Stage extends React.Component {
this.pickX = mousePosition[0];
this.pickY = mousePosition[1];

if (this.state.mouseDownTimeoutId !== null) {
this.cancelMouseDownTimeout();
if (this.state.mouseDown && !this.state.isDragging) {
if (this.state.mouseDown && !this.state.isDragging) {
const distanceFromMouseDown = Math.sqrt(
Math.pow(mousePosition[0] - this.state.mouseDownPosition[0], 2) +
Math.pow(mousePosition[1] - this.state.mouseDownPosition[1], 2)
);
if (distanceFromMouseDown > dragThreshold) {
this.cancelMouseDownTimeout();
this.onStartDrag(...this.state.mouseDownPosition);
}
}
Expand Down