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

Fire events or callbacks at zoomIn, zoomToElement etc...?

Open nodepond opened this issue 3 years ago • 6 comments

Is it possible to fire events or callbacks, when a trigger end animation with zoomIn, zoomOut zoomToElement etc was finished? I didn't found it anywhere, I guess this would be a nice enhancement.

Listening to onZoomStop, onPanningStop only triggers events, when user interacts with the transform.

nodepond avatar Jun 30 '21 13:06 nodepond

I second this. I need to run a function on callback anytime a zoomIn or zoomOut is called (including double-click, pinch, wheel). It would be great if the state could be returned whenever any change happened—not just pinch, pinch, wheel. Or even just a callback on doubleClick would be fantastic. Thanks for all your hard work building this.

johnnydanger avatar Jul 26 '21 17:07 johnnydanger

Anyone have a workaround way to access state after calling zoomIn, or zoomOut?

My use case is adding disabled state to buttons based on scale. Updating on scroll/pinch events with onZoom is working great but I don't have a way to access the state when calling zoomIn, or zoomOut via buttons.

https://codesandbox.io/s/epic-drake-sg5dn

JeffThorslund avatar Aug 11 '21 22:08 JeffThorslund

Seconding this as well, would be extremely handy to scale certain elements differently manually.

@JeffThorslund, a workaround might be keeping a separate state variable for the scale, which you update manually whenever you call zoomIn, zoomOut. If you know the scaling step size and initial scale, you could always add / subtract the scaling step size to your state on every zoom... call. I've thought about doing it like this in my application for the last few days, just didn't have the time yet. If you choose to implement it, let me know if it worked.

justinhehli avatar Aug 16 '21 12:08 justinhehli

Faced with the issue, and only issue to get current state after zoomIn or zoomOut is to use ref like this: <TransformWrapper initialScale={ 2 } ref={ (ref) => { console.log('ref ', ref); } } ...

YuriiDonev avatar Feb 23 '22 08:02 YuriiDonev

useTransformEffect does fire after zoomIn and zoomOut

Ross-Hunter avatar Mar 03 '23 15:03 Ross-Hunter

Listening to onZoomStop, onPanningStop only triggers events, when user interacts with the transform.

I faced the same issue. Callbacks on onPanning, onPanningStop don't fire during the animation after the user releases the mouse/touch.

Below code Yurrii mentioned doesn't fire during animation too.

<TransformWrapper
initialScale={ 2 }
ref={ (ref) => { console.log('ref ', ref); } }
...

Added) You can use onTransformed listener in TransformWrapper to get reference to the ZoomPanPinch instance even during animation

hy2850 avatar Apr 11 '23 01:04 hy2850