Comments (5)
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.
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.
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.
Glad you like it!
from dragdroptouch.
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)
- NPM package outdated HOT 3
- Image is not draggable on Canvas. HOT 7
- Script breaks with this code HOT 2
- The returned event does not have offsetX and offsetY property HOT 5
- dblclick event triggered twice on touch screens HOT 1
- Internal selections is not working HOT 9
- How to drag&drop from window A to window B in Android? HOT 10
- Breaks Bootstrap 3 dropdown menu HOT 2
- Is it possible to make this a default behaviour on desktop as well?
- Enabling the polyfill only when draggable attribute is set HOT 1
- Demo page doesn't work, and uses a "dead" copy of wijmo
- Contributing changes HOT 8
- update the npm package HOT 3
- Set up github pages for the master branch HOT 10
- Playwright install in postinstall HOT 2
- Refine the demo page
- Should not start touch-dragging when source element has draggable="false" HOT 8
- tried to tweak the `options` of your new version, not working though HOT 30
- add DEBUG to the source HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dragdroptouch.