question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for mobile/touchevents

See original GitHub issue

I came across this library yesterday when i was looking for a viable DnD tree solution. The features that this library provides handles all my usecases, except for the support for touchevents/mobile. I am wondering if you are considering supporting this feature sometime.

Personally, for my project, mobile/touch support is a critical requirement. So to test the viability, i went ahead and forked the library and tried some rudimentary fixes. react-dnd-touch-backend was required as a dependency. Please see my effort by installing:

"dependencies": {
    ....
    "@minoru/react-dnd-treeview": "https://github.com/arunmenon1975/react-dnd-treeview#touchsupport", 
    ....
    }

and adding the following 2 props - touchSupport and touchSupportOptions:

<Tree
  tree={treeData}
  touchSupport={true}
  touchSupportOptions={{
      "enableMouseEvents" : true
  }}
  rootId={0}
  onDrop={handleDrop}
  render={(node, {depth, isOpen, onToggle}) => (
    <div style={{marginLeft: depth * 10}}>
      {node.droppable && (
        <span onClick={onToggle}>
          {isOpen ? "[-]" : "[+]"}
        </span>
      )}
      {node.text.en}
    </div>
  )}
/>

It works on touch-enabled environments but there are issues, the biggest being that the Preview/Ghost component doesn’t appear. I think integrating the recommendations at the react-dnd-touch-backend docs with this library can be slightly complex. Another option is to use react-dnd-preview from here which seems to automatically create the preview for the environment the user is in. But not sure if that would mean requiring a peer dependency or if it will need to be packaged along. This may also mean that dragPreviewRender may change or perhaps not be required.

Note: Adding react-dnd-touch-backend created a few typescript issues because of the version mismatches and thus i had to upgrade React/React-DOM/react-dnd-html5-backend/react-dnd to the latest versions. For some reason i also had to add @types/hoist-non-react-statics to the dev dependencies.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
arunmenon1975commented, Jun 6, 2021

I just tried it now with sample data and everything works fine. The Tree is now touch-ready on a mobile as well. The fact that the dragPreviewRender prop is made available allows for customisation of the preview, a very useful option indeed.

Thanks for adding this feature. I will need to make some mods before i attempt it on my own data sources.

Closing the issue/feature-request since it is now fully working.

1reaction
minop1205commented, Jun 1, 2021

Version 1.4.1 has been published today. (v1.4.0 is missing because of a mistake in fixing CHANGELOG.)

It adds support for touch devices by default, so no additional configuration is required.

You can try it out if you like.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Touch events - Web APIs - MDN Web Docs - Mozilla
The touch events interfaces are relatively low-level APIs that can be used to support application-specific multi-touch interactions such as a ...
Read more >
Touch events | Can I use... Support tables for HTML5, CSS3, etc
Touch events. - REC. Method of registering when, where and how the interface is touched, for devices with a touch screen. These DOM...
Read more >
Touch and mouse - web.dev
Touch events are supported by Chrome and Firefox on desktop, and by Safari on iOS and Chrome and the Android browser on Android, ......
Read more >
Cross Browser Compatibility Score of Touch events
Browser Support for Touch events · Chrome · Safari · Firefox · IE Internet Explorer · Opera · Edge ...
Read more >
support mobile touch events #5504 - cypress-io/cypress - GitHub
in mobile mode: support touchstart / touchend correctly fire pointerleave / pointerout immediately before click as seen in the order below:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found