question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[trackMouse], End event is not fired when moving out of <Swipeable> area

See original GitHub issue

Steps to reproduce:

  1. Start swipeing on some element
  2. Move your finger so it’s outside of <Swipeable> area (but still pressed)
  3. Release finger

Expected:

  • onSwiped or onSwiped[Direction] was fired: a) just when finger moved out of element area b) when finger was released outside of element area (preffered is b) )

Actual:

  • onSwiped or onSwiped[Direction] is not fired.

Note: It happens when trackMouse is enabled.

Any ideas?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
hartziscommented, Jan 10, 2017

@TanaseHagi interesting solution with the extends Swipeable. I think i’d like to see this functionality added in the next major version, turned on when trackMouse is used 👍

1reaction
TanaseHagicommented, Jan 10, 2017

I had the same issue with trackMouse prop set to true. My solution was to bind mousemove and mouseup events on the document object.

The reason for this is that onTouchMove and onTouchEnd also fire for touches outside of the nodeName element they were bound to, while onMouseMove and onMouseUp do not do not fire when the user moves outside the nodeName element or releases the mouse outside of it.

This is my typescript code to get around the problem.

class CustomSwipeable extends Swipeable {
    public eventStart: (e: any) => void;
    public eventMove: (e: any) => void;
    public eventEnd: (e: any) => void;
    constructor(props: any) {
        super(props);
    }
    public start = (e: React.MouseEvent) => {
        this.eventStart(e);
        document.addEventListener("mousemove", this.move);
        document.addEventListener("mouseup", this.end);
    }
    public move = (e: MouseEvent) => {
        this.eventMove(e);
    }
    public end = (e: MouseEvent) => {
        this.eventEnd(e);
        document.removeEventListener("mousemove", this.move);
        document.removeEventListener("mouseup", this.end);
    }
    public render() {
        const newProps = ({
            ...this.props,
            onTouchStart: this.eventStart,
            onTouchMove: this.eventMove,
            onTouchEnd: this.eventEnd,
            onMouseDown: this.props.trackMouse && this.start,
            // onMouseDown: this.props.trackMouse && this.eventStart,
            // onMouseMove: this.props.trackMouse && this.eventMove,
            // onMouseUp: this.props.trackMouse && this.eventEnd,
        } as any);

        delete newProps.onSwiped;
        delete newProps.onSwiping;
        delete newProps.onSwipingUp;
        delete newProps.onSwipingRight;
        delete newProps.onSwipingDown;
        delete newProps.onSwipingLeft;
        delete newProps.onSwipedUp;
        delete newProps.onSwipedRight;
        delete newProps.onSwipedDown;
        delete newProps.onSwipedLeft;
        delete newProps.flickThreshold;
        delete newProps.delta;
        delete newProps.preventDefaultTouchmoveEvent;
        delete newProps.stopPropagation;
        delete newProps.nodeName;
        delete newProps.children;
        delete newProps.trackMouse;

        return React.createElement(
            this.props.nodeName,
            newProps,
            this.props.children
        );
    }
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Trackpad Events - Apple Developer
Scroll and swipe gestures, once begun, are locked to that gesture until the gesture ends. As it generates gestures, the trackpad hardware might ......
Read more >
Using Touch Events - Web APIs | MDN
A disadvantage to using mouse events is that they do not support ... touchmove - fired when a touch point is moved along...
Read more >
AngularJs $swipe not firing end event on mouseup
On a touch screen device, the demo functions correctly. The start event, move events, and end event fire respectively when dragging the finger ......
Read more >
react-swipeable - npm
Start using react-swipeable in your project by running `npm i ... It will also not trigger any callbacks and the swipe event will...
Read more >
Working with Events from Touch-Enabled Devices | JavaFX 2 ...
A single swipe event is generated for each swiping gesture. ... If the scroll gesture ends outside of the window, the shape is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found