Skip to content
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

Add option to prevent firing multiple directions #275

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vietnogi
Copy link

@vietnogi vietnogi commented Dec 30, 2021

Problem
User is swiping up but also to the right and firing events for swiping right causing unintentional functionality.

Use Case
User is scrolling up a list but its not straight so causing UX for swiping right.

Solution
Add add an option to prevent mix directions during a single swipe. A state for the initial direction is set and will be use to compare subsequent swipe movements. If the option is set and if the swipe direction changes, then we do not fire the event.

Before Example
swipe

After Example
swipe

@vietnogi vietnogi marked this pull request as ready for review December 30, 2021 17:08
@hartzis hartzis self-requested a review January 17, 2022 18:43
@hartzis hartzis self-assigned this Jan 17, 2022
@hartzis hartzis added this to the v7 milestone Jan 17, 2022
@hartzis
Copy link
Collaborator

hartzis commented Jan 17, 2022

@vietnogi Thank you for this! This is awesome and something i've also noticed before.

I think this will be a great addition and possibly even be on by default, what are your thoughts?

I have it added to the v7 project!

Do you think you'd be able to add a test?

@hartzis
Copy link
Collaborator

hartzis commented Jan 17, 2022

❓ maybe off by default and change name more to its intent like onlyUniDirectionalSwipes?

  • trackInitialDirection
  • onlyOneDirection
  • preventMixDirections ( current in this PR )
  • noMixedDirections
  • onlyInitialDirection

If it were the opposite and on by default:

  • allowMultiDirectionSwipe
  • allowFinalDirection
  • callLastDirection

@hartzis hartzis changed the base branch from main to v7 February 18, 2022 22:49
Copy link
Collaborator

@hartzis hartzis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Need to adjust where initialDirection is set to happen after delta check.
  • need test(s) for new functionality

moving out of v7 for now, but we can totally add this functionality after as backwards compatible 👍

@@ -140,7 +143,12 @@ function getHandlers(
? props.delta
: props.delta[dir.toLowerCase() as Lowercase<SwipeDirections>] ||
defaultProps.delta;
if (absX < delta && absY < delta && !state.swiping) return state;
if (absX < delta && absY < delta && !state.swiping)
return { ...state, initialDirection: state.initialDirection || dir };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 i think we'd need to actually set initialDirection outside of the catch for delta. We should probably only count the initial direction once the user has surpassed the delta which signifies the start of a "swipe" or "swiping"

@hartzis hartzis removed this from the v7 milestone Feb 21, 2022
@hartzis hartzis changed the base branch from v7 to main February 21, 2022 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants