react-zoom-pan-pinch icon indicating copy to clipboard operation
react-zoom-pan-pinch copied to clipboard

Expose state variables in useControls hook and on transformWrapper ref object

Open Andrii-Vovk opened this issue 6 months ago • 1 comments

Is your feature request related to a problem? Please describe. The library lacks some common exposed variables, that would be hugely useful for: Disabling panning, zoom on conditions; Doing actions when items are zoomed in

Describe the solution you'd like Expose additional variables, like isPanning, isZoomed, scale etc. in the useControls Hook and on the ref object. It seems that ts types already include those in a state field, but it is only populated in the events, and not on the main ref obect in this configuration:

// transformWrapperRef.current?.state object is always undefined here
  const transformWrapperRef = useRef<ReactZoomPanPinchRef | null>(null);

  <TransformWrapper
    ref={transformWrapperRef}
  >
    <TransformComponent>
        <img
          src={image}
        />
    </TransformComponent>
  </TransformWrapper>

Describe alternatives you've considered Using event handlers like onPanning and onZoom to set a boolean state for isZoomedIn. Requires additional event throttling, and, to my mind is generally a worse solution. (because onZoom seems to not always fire on first double tap, and isPanning is firing every pixel moved)

Andrii-Vovk avatar Dec 28 '23 14:12 Andrii-Vovk

Hello,

It would be really useful to have the state field populated on the ref object.

Thanks,

Ronald

rluttikhuizen avatar Jan 28 '24 08:01 rluttikhuizen