react-dnd: Touch backend not working
Hi -
The documentation does not address this but is the touch backend supposed to simply add touch based dragging or it excludes the regular dragging (in which case is there an all in one backend?..)? I ask because I had setup a basic card for dragging which was working fine on the HTML5 Backend but when I switched to the TouchBackend it stopped working.
const [{isDragging}, drag, preview] = useDrag({
item: {
type: ItemTypes.CARD,
},
collect: monitor => ({
isDragging: !!monitor.isDragging(),
})
})
// structure of how I laid out the draggable component.
<div ref={preview}>
<div ref={drag}>
// some svg icon as handler
</div>
</div>
Any help is appreciated. Thanks.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 3
- Comments: 15 (1 by maintainers)
I have the same issue - preview not showing up while using
TouchBackendAh that seems to have done it! Although now the preview when I drag is not working. Is
Not supported or called something else?
did you add options like this? <DndProvider backend={TouchBackend} options={{ enableMouseEvents: true }}>
@tommasini I had similar problem. If you use conditon of var in props it does not work. I swited condition for component and worked for me.
Before
After
Hello, TouchBackend is not working. I’m importing like the documentations tells.
And i’m passing the provider enabling the mouse events.
I try to call also the onTouchStart, onTouchMove and onTouchEnd in the draggable item and nothing happens. Im using google chrome to simulate the mobile device, but tried later with my device and didn’t work as well but I think It would never work with my device because I dont have acces to the third party libraries.
I really need an answer, thank you people!
I appreciate help or another solution!
Stay safe ❤️
I would recommend you @william-hotmart to disable SSR on certain component. That might fix your issue. Or you can make Wrapper around
DndProviderwith SSR partial disable. “Partial SSR disable” i mean on SSR return plaindivon client on Rerender decide if it’sHTML5BackendorTouchBackendand initialize DnD provider.Right now I am not sure if there wont be some problem with missing DnD context. I’m trying to make some workaround in SSR. I will try to provide my workaround solution in few days.
The problem might be this function getGlobalContext.
What I have right now in mind is something like this example - so it might remount DnDProvider in browser because of the key.
@kdfriedman sadly yours did not work for me. I’m using SSR (nextjs).
Reason why i ended up with