-
Notifications
You must be signed in to change notification settings - Fork 125
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
tried to tweak the options
of your new version, not working though
#77
Comments
just tried this
this one does work. but, it makes me wonder, the |
Can you unpack what "doesn't work" mean? (e.g. what are you trying to do, and what interaction are you performing so I can try to reproduce that?) The (But note that Also note that That said, looking at the code for |
@Bernardo-Castilho the original TS rewrite added dragdroptouch/ts/drag-drop-touch.ts Lines 242 to 246 in 7ffa058
but should that be stricter? E.g. _shouldStartDragging(e: TouchEvent) {
let delta = this._getDelta(e);
if (this.configuration.isPressHoldMode) {
return delta >= this.configuration.pressHoldThresholdPixels;
}
return delta > this.configuration.dragThresholdPixels;
} That is, check if we've crossed the |
It looks like the original version will use the smaller value between I think I like the second version better. |
i didn't give any description of what happened hence "doesn't work", my apology. i guess, i was thinking if you use my testing code and try it, you will see what it was. i try my best to describe it here anyhow: when this for the second attempt with this my intented effect: i don't want the "drag" kicking in when i just want to "scroll" the screen by swiping. so i figured i should use besides, i also tried this |
Ah, thank you, that should be enough for me to see if I can reproduce the same interactions. As for the 404: the repository changed from https://bernardo-castilho.github.io to https://drag-drop-touch-js.github.io so if you update your URL it should work. That said, github's not a fan of being a CDN (I have no idea why, it's kind of obvious that they are?) so I'm still looking at hosting the library on a "real" CDN soon. |
Oh, one more question, because I've noticed different devices doing different things: which device/os/browser combination was this happening for? |
android version 14, and android chrome 125.0.6422.165 |
Cheers. The most recent Android I have on a device here is Android 13 but that should hopefully still be good enough to replicate this weekend. |
fyi, i got this |
You want https://drag-drop-touch-js.github.io/dragdroptouch/dist/drag-drop-touch.esm.min.js (note the |
I've updated the README.md to show the correct URL. |
yes, that's working as it used to be with the correct url. |
So I set up a https://drag-drop-touch-js.github.io/dragdroptouch/demo/issue-77 which has your script block in it, <script type="module">
import { enableDragDropTouch } from "./drag-drop-touch.esm.min.js";
enableDragDropTouch(document, document, {
isPressHoldMode: true,
pressHoldThresholdPixels: 5,
});
</script> but if I load that on Android 13 in Chrome 127.0.6533.64 (that's the most recent version available on the play store for me) I can't seem to reproduce the problem you're having. If I tap-and-hold an element (but not the image, that pops up the image inspection context menu) then it changes to the "drag" CSS after a few hundred milliseconds, and then I can drag and drop it on another element to swap their positions. |
that's kind of strange. look, i tried yours on my android device, it does work (as you told), yet, my own testing setup still the same, not working. another strange thing is, when i try yours on my win10 device, it gave me this
|
hmm, is it something about |
but no, i guess. given that this |
so here's what I think is going on: Chrome on Android has drag and drop support. It... just works. Testing with https://jsfiddle.net/unh6Lsq0 on my phone, which doesn't load the drag-drop-touch polyfill already works all on its own. So the reason I saw it work was because I had the wrong URL for the js file in the index.html (as you saw) and I just updated it to the correct one and I'm going to guess that'll actually break things because chrome already works, and the polyfill is now going to interfere with proper drag-and-drop handling. |
Hm, with the HTML fixed (network tab shows correct loading of the JS file), things still seem to work on my phone. |
i can't think of anything helpful for you on this im afraid. |
I've set up your example as https://drag-drop-touch-js.github.io/dragdroptouch/demo/issue-77b/ (with |
ic. thanks. and looking for your further discovery. cheers. |
I've updated the 77b test page so that it can test all three cases (default, isPressHoldMode, and isPressHoldMode with threshold) and it does show the first two working, but the third not, so I'm going to see if I can do some creative localhost server + usb remote debugging to get more information about what's going on here. |
I tried this here. As far as I can tell, the problem is related to the fact that a elements behave as img, and are draggable by default. If you want to drag the container element instead, you have to set draggable to false on these elements, e.g.:
This works for me. |
@Bernardo-Castilho but the question is why it works just fine until you add the threshold value. Both "plain" and "isPressHoldMode-only" modes let me drag the |
Ah, sorry. I didn't realize this was about the isPressHoldMode setting. I actually never used that, don't understand what it's for. But looking at the code, it seems like a few methods check for that value: My guess is one of these must be preventing the drag operation from starting... Sorry I couldn't be more helpful. |
Right, that took longer to get back to than hoped, but: I can also reproduce this on desktop chrome using touch emulation, and it looks like with debug statements turned on, the (the reason it works with |
As far as I can tell this slipped in with the TS rewrite, which swapped out the old code, DragDropTouch.prototype._getDelta = function (e) {
var p = this._getPoint(e);
return Math.abs(p.x - this._ptDown.x) + Math.abs(p.y - this._ptDown.y);
}; with this new code: _getDelta(e: TouchEvent) {
if (!this._ptDown) return 0; // Added by NDP OK? TODO
if (this.configuration.isPressHoldMode && !this._ptDown) {
return 0;
}
let p = pointFrom(e);
return Math.abs(p.x - this._ptDown.x) + Math.abs(p.y - this._ptDown.y);
} But this will always return a delta of 0 during long press mode, so that's no bueno if we need to perform a distance-threshold check. If I rewrite it to the following code instead, then the long press threshold is respected again: _getDelta(e: TouchEvent) {
// if there is no active touch we don't need to calculate anything.
if (!this._ptDown) return 0;
// Determine how `far` from the event coordinate our
// original touch coordinate was.
const { x, y } = this._ptDown;
const p = pointFrom(e);
return ((p.x - x) ** 2 + (p.y - y) ** 2) ** 0.5;
} |
Now to figure out how to turn that into a test so we can prevent regressions =D |
Awesome detective work! |
tried this
doesn't work. anything wrong with my testing code?
The text was updated successfully, but these errors were encountered: