vasturiano / react-force-graph

React component for 2D, 3D, VR and AR force directed graphs
https://vasturiano.github.io/react-force-graph/example/large-graph/
MIT License
2.24k stars 284 forks source link

How to modify the canvas in 3d graph (canvas touchAction = "auto!important") #482

Open BernardoOlisan opened 11 months ago

BernardoOlisan commented 11 months ago

By default, the canvas in threejs is broken on mobile phones. I've been attempting to scroll using mobile browsers, but the issue is that the touch scroll does not respond. I came across this solution at https://discourse.threejs.org/t/scroll-mobile-ios/50237/3, which seems to address the problem. However, the challenge with react-force-graph is that I'm unsure how to modify the canvas to set canvas.style.touchAction = "auto!important".

I have already attempted this:

        graphRef.current.controls().domElement.style.touchAction = "auto"
        graphRef.current.refresh()

        const canvas = document.getElementsByClassName("scene-container")[0].children[2]
        canvas.style.touchAction = "auto!important"

However, neither of those alternatives work. By modifying the canvas style via the browser inspector, I was able to make the touch scroll work perfectly fine. But as is known, page refresh kills it.

Is there a way to modify it? @vasturiano

BernardoOlisan commented 11 months ago

I want to be able to scroll on a mobile phone even if the graph is fixed to full screen size and still be able to grab the nodes normally.