Fix - Memory leak, animation frame never cancelled

This commit is contained in:
Kamran Ahmed
2018-03-04 20:52:54 +01:00
parent d5e94aa92e
commit f5ebead73c
2 changed files with 15 additions and 4 deletions
+8 -4
View File
@@ -141,10 +141,14 @@ export default class Overlay {
document.body.appendChild(this.overlay);
}
// @todo: do not requestAnimationFrame once final highlight position has been reached
// Stage a new animation frame
this.redrawAnimation = this.window.requestAnimationFrame(this.draw);
// Stage a new animation frame only if the position has not been reached
// of the alpha has not yet fully reached fully required opacity
if (
!this.positionToHighlight.equals(this.highlightedPosition) ||
this.overlayAlpha.toFixed(2) !== this.opacity.toFixed(2)
) {
this.redrawAnimation = this.window.requestAnimationFrame(this.draw);
}
} else {
this.document.body.removeChild(this.overlay);
}
+7
View File
@@ -24,4 +24,11 @@ export default class Position {
canHighlight() {
return this.left < this.right && this.top < this.bottom;
}
equals(position) {
return this.left.toFixed(3) === position.left.toFixed(3) &&
this.right.toFixed(3) === position.right.toFixed(3) &&
this.top.toFixed(3) === position.top.toFixed(3) &&
this.bottom.toFixed(3) === position.bottom.toFixed(3);
}
}