Giter Club home page Giter Club logo

Comments (5)

dpitois avatar dpitois commented on August 13, 2024

Hello,

We are using RGL too on an internal project, and I faced the same issue.
I investigated a bit today, and it looks like at some point RGL is looking for an offset of the item being dragged.
Fun fact, the property read from the nativeEvent seems to be deprecated according the MDN page MouseEvent.layerX

Not totally confirmed on my side, but I tried a local copy of the polyfill and replaced the event binding with the related pointer events rather than the touch one.

// listen to touch events
if (navigator.maxTouchPoints) {
    var d = document,
        ts = this._touchstart.bind(this),
        tm = this._touchmove.bind(this),
        te = this._touchend.bind(this),
        opt = supportsPassive ? { passive: false, capture: false } : false;
-    d.addEventListener('touchstart', ts, opt);
-    d.addEventListener('touchmove', tm, opt);
-    d.addEventListener('touchend', te);
-    d.addEventListener('touchcancel', te);
+    d.addEventListener('pointerdown', ts, opt);
+    d.addEventListener('pointermove', tm, opt);
+    d.addEventListener('pointerup', te);
+    d.addEventListener('pointercancel', te);
}

Going with touch event seems to pass the information needed to compute offset, and React-Grid-Layout does not crash.

I can suggest a PR, but not sure about any side effects, I'm testing this change using a desktop + devtools touch emulation.

from dragdroptouch.

Bernardo-Castilho avatar Bernardo-Castilho commented on August 13, 2024

Thank you for the suggestion and for testing it.

I tested this change here but it didn't work for me (Surface touch screen, Chrome). ;-(

If you have any news on this issue, please feel free to share here.

from dragdroptouch.

dpitois avatar dpitois commented on August 13, 2024

For sure, I need to do more investigation, just after posting the suggestion, I noticed that some parts of the code looks for touches.
I may suggest a PR once I debugged it on my side.

BTW: great polyfill anyway, except the issue with React-Grid-Layout it works so great!

from dragdroptouch.

Bernardo-Castilho avatar Bernardo-Castilho commented on August 13, 2024

Glad you like it!

from dragdroptouch.

dpitois avatar dpitois commented on August 13, 2024

Hello, some feedbacks about the suggestion...

It looks like I was (very) tired and using touch events does not solve the issue, or if it is possible, it may involve many other changes to the current library.

But, I try another way, and for now it looks promising on the project I'm working on with React-Grid-Layout.

this._copyProps(evt, t, DragDropTouch._ptProps);
if (!evt.offsetX || !evt.offsetY || !evt.layerX || evt.layerY) { // block added to set "missing" properties for RGL
    var rect = target.getBoundingClientRect();
    evt.offsetX = evt.clientX;
    evt.offsetY = evt.clientY;
    evt.layerX = evt.pageX - rect.left;
    evt.layerY = evt.pageY - rect.top;
}
evt.dataTransfer = this._dataTransfer;

And I also had to add some CSS to avoid RGL placeholder to catch drag event and to produce some glitch

.react-grid-placeholder {
    pointer-events: none;
}

Current status can be consulted here:
https://codesandbox.io/s/react-grid-layout-nested-grids-drag-from-outside-forked-ibvst0?file=/DragDropTouch.js

I'm still facing issue about how to get correct values for layer[X|Y], using the target boundingClientRect looks pretty OK, but it is still wrong when the target has scrolled or the RGL contains a static element.

from dragdroptouch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.