Open Witchayanin opened 3 years ago
Facing the same issue
Fixed in my fork of the project, commit https://github.com/Softec-Open-Source-Division/ngx-imageviewer/commit/3caab5013509248574083539b78023d7efc80c99
The correct fix for this is storing the handle that requestAnimationFrame
returns and making sure to call cancelAnimationFrame
on it when render()
is called to make sure every image has only one image render loop. You should then also call cancelAnimationFrame
in the onDestroy
, like this:
private animationFrameHandle: number;
private render() {
if (this.animationFrameHandle) {
cancelAnimationFrame(this.animationFrameHandle);
this.animationFrameHandle = null;
}
this.renderFrame();
}
private renderFrame() {
// ... Existing render code here ...
this.animationFrameHandle = requestAnimationFrame(() => this.renderFrame());
}
ngOnDestroy() {
// ... Existing destroy code here ...
// Stop animation frame when image viewer is destroyed.
if (this.animationFrameHandle) {
cancelAnimationFrame(this.animationFrameHandle);
this.animationFrameHandle = null;
}
}
I found that after view the content many times the page will significant slow down and type the input will be delay.
Reproduce step: