Comments (10)
I had the same issue when using version 3.2.0, I resorted to downgrading to version 3.1.0 and panning seems to be working again.
from react-zoom-pan-pinch.
The following should work if you are not using StrictMode:
const Demo = React.memo(({ imageSrc }) => {
return (
<TransformWrapper key={imageSrc}>
<TransformComponent>
<ImagePreview src={imageSrc} />
</TransformComponent>
</TransformWrapper>
);
});
// <Demo imageSrc={imageSrc} />
from react-zoom-pan-pinch.
I'm taking a leap here because I don't know this codebase or the decisions that led to this but it seems like instead of doing this...
useEffect(() => {
instance.update(props);
return () => {
instance.cleanupWindowEvents();
};
}, [instance, props]);
Cleanup should be in it's own useEffect...
useEffect(() => {
instance.update(props);
}, [instance, props]);
useEffect(() => {
return () => {
instance.cleanupWindowEvents();
};
}, []);
from react-zoom-pan-pinch.
This is affecting me also, I haven't found a workaround yet.
from react-zoom-pan-pinch.
Some comments to this issue (for completeness):
Incomplete cleanup
It may be worth noting that the performance fix in 3.1.1 does cleanup mouse and key events, but does not cleanup wheel, double-click and touch events.
StrictMode compatibility
Cleanup should be in it's own useEffect...
useEffect(() => { instance.update(props); }, [instance, props]); useEffect(() => { return () => { instance.cleanupWindowEvents(); }; }, []);
The recommendation from @lesjames fixes the issue in most use cases, but is not a good solution for the future, because it does not work with React StrictMode.
See more details on why that matters. (section "Ensuring reusable state")
Instead, it would be better if the event listeners would be added in the same effect that also cleans them up. Also, instance
should be in the effect's dependency array for the same reasons:
useEffect(() => {
instance.initializeWindowEvents();
instance.handleInitializeWrapperEvents();
return () => {
instance.cleanupWindowEvents();
// TODO: cleanup rest
};
}, [instance]);
from react-zoom-pan-pinch.
Created a Minimal playground before I found this issue.
https://codesandbox.io/s/vigilant-mendeleev-9v7tf4?file=/src/App.js
And a workaround is here if anyone need it:
put following code before <TransformWrapper>
useEffect(() => {
setTimeout(() => setImageSrc(0), 300);
}, [imageSrc]);
return (
<TransformWrapper key={imageSrc}>
<TransformComponent>
<ImagePreview src={imageSrc} />
</TransformComponent>
</TransformWrapper>
)
from react-zoom-pan-pinch.
I'm having the same issue and the workaround from @zzswang does not fix it and I imagine it's not a great workaround either for those who have multiple components on one page with multiple useEffects/useStates in each component.
from react-zoom-pan-pinch.
The following should work if you are not using StrictMode:
const Demo = React.memo(({ imageSrc }) => { return ( <TransformWrapper key={imageSrc}> <TransformComponent> <ImagePreview src={imageSrc} /> </TransformComponent> </TransformWrapper> ); }); // <Demo imageSrc={imageSrc} />
You're right, that did fix it. Totally forgot that React had that feature.
Should probably mention though that according to the React docs, it's not recommended that we rely on React.memo
if the code doesn't work without it, as it's only meant to be used as performance optimization.
from react-zoom-pan-pinch.
The rule is to avoid multi rerender happened in a really short time.
from react-zoom-pan-pinch.
I have same issue. Dynamic content is injected to my image viewer as overlay, and interaction with image hangs.
from react-zoom-pan-pinch.
Related Issues (20)
- Is there a way to force image Aspect Ratio?
- minPositionX/Y and maxPositionX/Y props do not seem to work
- Is there any way to do rotate in this library? HOT 1
- how to disable panning while transformation in react-zoom-pan-pinch ? Actually when I am using center view method and whlie animation I start panning it stops the animation....I want to stop panning until animation is completed
- Unable to use drag and drop functionality inside of TransformWrapper HOT 1
- Storybook code HOT 1
- Centering issue HOT 2
- centerZoomedOut falg is not working (disable center is not working)
- zoomToElement needs a setTimeout or requestAnimationFrame HOT 1
- [QUESTION] Detect left mouse button
- Sponser banners in README.md not displaying
- Unable to Copy content
- Pinching is not working as smooth
- Better examples and documentation
- Minimap not working when content is larger than one screen?
- How i get clicked x, y coordinates in react-zoom-pan-pinch canvas?
- Is there a way of switching 2-fingers gesture (zoom) and 1-finger (pan)
- Some residue when zoom in and out on Safari 15
- How can I use controls outside the <TransformWrapper /> HOT 1
- Focus input trigger transformContentComponent to scroll to show focused cursor, but not update transform state.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-zoom-pan-pinch.