-
Notifications
You must be signed in to change notification settings - Fork 10
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
Closes issue #58 #59
base: master
Are you sure you want to change the base?
Closes issue #58 #59
Conversation
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.
Generally I like it, but I don't like introducing demanding calculations. The other solution you have suggested did the trick, but I could reproduce the bug when rapidly dragging and then clicking. So I actually think this is better solution, if you could somehow simplify tat threshold calculation, it would be great. But if that's over your time limit, I can accept your other solution as temporary fix, and later fix it properly. Thanks for PR!
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.
Looks fine, but could you explain, why did you pick 50 as default value?
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.
50 felt the most natural when swiping. But that was my personal preference and other users might want something different so I exported it so users can choose.
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.
Well, I like that you are thinking of people that would like to customize this, but I think that something that distinguishes whether is something tap or swipe should be deterministic and not adjustable. It shouldn't be like some concrete event is on one page tap and on another swipe.
duration: 0 | ||
}) | ||
const distance = Math.abs(event.clientY - dragPosition); | ||
const threshold = distance > (fullpage.clientHeight / dragThreshold); |
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 here is too much math done for event that's fired every time user drags. Especially division is pretty demanding, it would be fine to mitigate it.
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.
Maybe we can improve the performance by using squared distances as opposed to absolutes, for example:
const distance = Math.pow(event.clientY - dragPosition, 2);
const threshold = Math.pow(fullpage.clientHeight / dragThreshold, 2);
const isDrag = distance > threshold;
This way we can avoid the square root calculation involved in computing the actual distances. The side-effect of this is maybe a few edge cases where user inputs are wrongly identified.
Another option is to use bitwise operations, an example would be:
const distance= (event.clientY - dragPosition) ** 2;
const threshold = (fullpage.clientHeight / dragThreshold) ** 2;
const isDrag = distance > threshold;
This optimization works because its only interested in whether one distance is greater than another, and you don't need the actual values; however, I believe the performance gain opposed to this will not be significant as this is not a large enough calculation to warrant it.
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.
Thanks for trying for optimization,
but I meant so meting different, like changing semantics of dragThreshold to entirely mitigate division. Actually calculating squared distances would not speed up calculations as it is defined not by power and root, but rather as negation of negative value, and you can see it in V8 code. And FYI '**' operator is actually not bitwise operator, but just expressive writing of power.
If you'll be committing some code from code review, please use conventional commits, sorry for not mentioning it in project contribution guidelines. |
formatting Co-authored-by: Filip Holčík <filip.holcik.official@gmail.com>
removed console log Co-authored-by: Filip Holčík <filip.holcik.official@gmail.com>
formatting Co-authored-by: Filip Holčík <filip.holcik.official@gmail.com>
formatting Co-authored-by: Filip Holčík <filip.holcik.official@gmail.com>
formatting Co-authored-by: Filip Holčík <filip.holcik.official@gmail.com>
fixed reference order of statements Co-authored-by: Filip Holčík <filip.holcik.official@gmail.com>
removed unnecessary statement Co-authored-by: Filip Holčík <filip.holcik.official@gmail.com>
formatting Co-authored-by: Filip Holčík <filip.holcik.official@gmail.com>
formatting Co-authored-by: Filip Holčík <filip.holcik.official@gmail.com>
formatting Co-authored-by: Filip Holčík <filip.holcik.official@gmail.com>
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.
Now I'm starting to not like this solution, it's over complicated and it could pollute code, which will require breaking change to clean (I mean that export of DragThreshold). When I was working on version 1.0.0, I was trying to minimize number of needed exports props needed for customization, but to keep level of customization high. Adding prop for decision whether something is tap or drag is overkill, and I thing it is generally decidable with simple heuristic.
I admire you will to fix this bug, and also your time investment, but I don't think this solution should be merged. I'd rather merge that other 1 line heuristic fix for now, and later, when I'll have time, I'll address this issue. Currently I'm busy to experiment with ways of fixing this, but please, keep this PR open, if I later find out, this is the best solution, so you cold heave credit on this. Please could you create another PR with that other solution?
Thank you very much,
Filip.
duration: 0 | ||
}) | ||
const distance = Math.abs(event.clientY - dragPosition); | ||
const threshold = distance > (fullpage.clientHeight / dragThreshold); |
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.
Thanks for trying for optimization,
but I meant so meting different, like changing semantics of dragThreshold to entirely mitigate division. Actually calculating squared distances would not speed up calculations as it is defined not by power and root, but rather as negation of negative value, and you can see it in V8 code. And FYI '**' operator is actually not bitwise operator, but just expressive writing of power.
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.
Well, I like that you are thinking of people that would like to customize this, but I think that something that distinguishes whether is something tap or swipe should be deterministic and not adjustable. It shouldn't be like some concrete event is on one page tap and on another swipe.
Okay, thank you for giving me a better understanding both on the direction of this library and on the v8 implementation. I will create a new pull request for the other solution when I have time this week. |
Hi @Siutan, Best, |
Hi @Hejtmus, Please go ahead and include the change with your commit, unfortunately I have not had time to work on it. Thanks, |
Now I found special edge case in that one line solution, that scrolls up any section, that is below other section and doesn't have slides, so I have to find another solution to #58. Hopefully next week I have had finished work for my clients, so I can figure out solution with no side effects. Have a nice day, |
Closes #58
Changes made:
handleDragging()
function to check for distance dragged.dragThreshold
variable to set the intensity of the drag effect (Default is 50).tapped
variable to check if distance of drag < threshold.Notes:
dragThreshold
is exported and can be used like:The quick way to fix this is also to do the following in
FullpageController.svelte
:I was unsure if this would bring up more issues/outliers later, so I didn't implement it this way.
I also found it easier to implement the sensitivity (
dragThreshold
) using thehandleDragging()
function as opposed to the above fix.