From what i have read online the Angular team recommends that you should always call requestAnimationFrame()
outside of the Angular zone like this:
this.ngZone.runOutsideAngular(() => {
requestAnimationFrame(timestamp => {
let timerStart = timestamp || new Date().getTime();
this.myAnimeMethod(timestamp);
});
});
But what about the loop ...
this.ngZone.runOutsideAngular(() => {
requestAnimationFrame(timestamp => {
let timerStart = timestamp;
this.myAnimeMethod(timestamp, timerStart);
});
});
myAnimeMethod(timestamp, timerStart) {
let time = timestamp || new Date().getTime();
let runtime = time - timerStart;
/// animation logic here
if(runtime < 10000) {
// ------- continue to animate for 10 seconds -- //
requestAnimationFrame(timestamp => {
this.myAnimeMethod(timestamp, timerStart);
});
}
}
Was it enough to call this.ngZone.runOutsideAngular()
on the first request or should i be calling it again this.ngZone.runOutsideAngular()
inside myAnimeMethod()
like this?
this.ngZone.runOutsideAngular(() => {
requestAnimationFrame(timestamp => {
let timerStart = timestamp;
this.myAnimeMethod(timestamp, timerStart);
});
});
myAnimeMethod(timestamp, timerStart) {
let time = timestamp || new Date().getTime();
let runtime = time - timerStart;
/// animation logic here
if(runtime < 10000) {
// ------- request to run outside of Angular again while continuing to animate for 10 seconds -- //
this.ngZone.runOutsideAngular(() => {
requestAnimationFrame(timestamp => {
this.myAnimeMethod(timestamp, timerStart);
});
});
}
}