react-zoom-pan-pinch
react-zoom-pan-pinch copied to clipboard
Expose state variables in useControls hook and on transformWrapper ref object
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)
Hello,
It would be really useful to have the state field populated on the ref object.
Thanks,
Ronald