-
Notifications
You must be signed in to change notification settings - Fork 147
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
base: main
Are you sure you want to change the base?
Conversation
@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? |
❓ maybe off by default and change name more to its intent like
If it were the opposite and on by default:
|
There was a problem hiding this 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 afterdelta
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 }; |
There was a problem hiding this comment.
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"
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
After Example