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.

onSwipedRight is firing when clicking outside the swipeable area

See original GitHub issue

Describe the bug I have a swipeable area with the onSwipedLeft and onSwipedRight handlers. For some reason the onSwipedRight event is firing if I click outside this area.

Steps or Sandbox to reproduce

Steps to reproduce:

  1. Swipe the “swipe me” area
  2. Click the “click me” button, or the area above the “click me” button
  3. The onSwipedRight handler fires

Expected behavior onSwipedRight should not be firing if you click the button

Device/Browser Google Chrome 100.0.4896.88 (64-bit) (for desktop browser the bug is reproducing only in mobile device mode, for example iPhone XR) or Chrome for Android 98.0.4758.101; Android 10; Mi 9 Lite Build/QKQ1.190828.002

Additional context If you click on the swipeable area between step 1 and 2 the bug does not reproduce.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
Sacretcommented, Apr 21, 2022

@hartzis thank you as well for the explanation and fix. I really appreciate it!

1reaction
hartziscommented, Apr 21, 2022

@Sacret Okay this threw me through a bit of a loop, but after some exploration and strategically placed debugger’s the issue arises when both trackTouch and trackMouse are utilized.

We are attaching the document eventlisteners even if the swipe was started as a touch. So after a touch swipe happens the mousemove and mouseup event listener’s are still attached and fire when you click outside the swipeable target. This “triggers” a new swipe based on the previous swipes eventData 🤦 .

Now that i know what is happening there are a few solutions and clean ups we can do:

  • clean up eventData after a swipe “ends”
  • only attach mouse event listeners when the start event was a mouse event
  • correctly clean up the mousemove and mouseup event listeners

Thank you thank you again @Sacret ! 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Click or tap through swipeable component · Issue #215 - GitHub
I want to use this package for opening a hamburger-menu with a swipe gesture, i defined a div with 30% width and a...
Read more >
javascript - React, click outside event fire right after the open ...
I believe the event of the on click bubbles up, while the state is already toggled, and the ref is initialized, therefore at...
Read more >
Creating An Outside Focus And Click Handler React Component
In this article, we'll look at how to create an outside focus and click handler with React. We will recreate an open source...
Read more >
react-swipeable - Formidable Labs
A React swipe event handler hook. ... Edit react-swipeable image carousel ... After LEFT swipe (SwipeEventData) => void onSwipedRight, // After RIGHT swipe...
Read more >
react-swipeable - npm
Start using react-swipeable in your project by running `npm i react-swipeable`. ... onSwipedRight, // Fired after RIGHT swipe.
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