Skip to content

Commit

Permalink
fix(animation): properly clean up elements (#19210)
Browse files Browse the repository at this point in the history
* fix destroy method

* wrap dom writes in raf

* Add comments
  • Loading branch information
liamdebeasi committed Aug 28, 2019
1 parent da5d3f0 commit 93f2064
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions core/src/utils/animation/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export const createAnimation = () => {
* Destroy the animation and all child animations.
*/
const destroy = () => {
childAnimations.forEach(childAnimation => {
childAnimation.destroy();
});

cleanUp();

elements.length = 0;
Expand All @@ -71,10 +75,6 @@ export const createAnimation = () => {
initialized = false;
shouldCalculateNumAnimations = true;

childAnimations.forEach(childAnimation => {
childAnimation.destroy();
});

return ani;
};

Expand Down Expand Up @@ -124,14 +124,16 @@ export const createAnimation = () => {
webAnimations.length = 0;
} else {
elements.forEach(element => {
removeStyleProperty(element, 'animation-name');
removeStyleProperty(element, 'animation-duration');
removeStyleProperty(element, 'animation-timing-function');
removeStyleProperty(element, 'animation-iteration-count');
removeStyleProperty(element, 'animation-delay');
removeStyleProperty(element, 'animation-play-state');
removeStyleProperty(element, 'animation-fill-mode');
removeStyleProperty(element, 'animation-direction');
requestAnimationFrame(() => {
removeStyleProperty(element, 'animation-name');
removeStyleProperty(element, 'animation-duration');
removeStyleProperty(element, 'animation-timing-function');
removeStyleProperty(element, 'animation-iteration-count');
removeStyleProperty(element, 'animation-delay');
removeStyleProperty(element, 'animation-play-state');
removeStyleProperty(element, 'animation-fill-mode');
removeStyleProperty(element, 'animation-direction');
});
});
}
};
Expand All @@ -142,7 +144,14 @@ export const createAnimation = () => {
*/
const cleanUpStyleSheets = () => {
stylesheets.forEach(stylesheet => {
stylesheet.parentNode!.removeChild(stylesheet);
/**
* When sharing stylesheets, it's possible
* for another animation to have already
* cleaned up a particular stylesheet
*/
if (stylesheet && stylesheet.parentNode) {
stylesheet.parentNode.removeChild(stylesheet);
}
});

stylesheets.length = 0;
Expand Down

0 comments on commit 93f2064

Please sign in to comment.