retyui / react-quick-pinch-zoom

A react component that providing multi-touch gestures for zooming and dragging on any DOM element.
https://react-quick-pinch-zoom.netlify.app/
308 stars 46 forks source link

All child drag events are ignored when `enabled={false}` #44

Closed rektdeckard closed 2 years ago

rektdeckard commented 2 years ago

Hey there, thanks for making this library!

I would like to be able to dynamically enable or disable the pan/zoom in order to interact with some child components that require drag interaction (<input type="range" />), however children do not seem to receive drag events when the enabled prop is false. I would expect that this should work, and that events would propagate normally when disabled.

const Example = () => {
  const [enabled, setEnabled] = useState(true);

  return (
    <QuickPinchZoom enabled={enabled}>
      <input  // <--- Doesn't respond to gestures
        type="range"
        onMouseEnter={() => setEnabled(false)}
        onMouseLeave={() => setEnabled(true)}
      /> 
    </QuickPinchZoom>
  );
}

Example is contrived of course, and my real input is deeply nested in a child, but either way is impossible to interact with any element via drag if they are within the QuickPinchZoom, whether it's enabled or not.

retyui commented 2 years ago

It can be done on your side, just ignore onUpdate

export const App = () => {

  const [enabled, setEnabled] = useState(true);

  return (
    <QuickPinchZoom onUpdate={enabled ? onUpdate: null}> // It should helps
      <img ref={imgRef} src={IMG_URL} />
    </QuickPinchZoom>
  );
};