feat(animation): add option to clean up old animation stylesheets (#20940)

fixes #20610
This commit is contained in:
Liam DeBeasi
2020-04-03 09:28:41 -04:00
committed by GitHub
parent 4e28445ecb
commit 5b9840508f
2 changed files with 9 additions and 8 deletions

View File

@ -27,7 +27,7 @@ export interface Animation {
/**
* Destroy the animation and all child animations.
*/
destroy(): void;
destroy(clearStyleSheets?: boolean): void;
progressStart(forceLinearEasing: boolean, step?: number): void;
progressStep(step: number): void;

View File

@ -1,5 +1,3 @@
// TODO: Add more tests. until then, be sure to manually test menu and swipe to go back/routing transitions
import { raf } from '../helpers';
import { Animation, AnimationCallbackOptions, AnimationDirection, AnimationFill, AnimationKeyFrame, AnimationKeyFrameEdge, AnimationKeyFrames, AnimationLifecycle, AnimationPlayOptions } from './animation-interface';
@ -72,12 +70,12 @@ export const createAnimation = (animationId?: string): Animation => {
return webAnimations;
};
const destroy = () => {
const destroy = (clearStyleSheets?: boolean) => {
childAnimations.forEach(childAnimation => {
childAnimation.destroy();
childAnimation.destroy(clearStyleSheets);
});
cleanUp();
cleanUp(clearStyleSheets);
elements.length = 0;
childAnimations.length = 0;
@ -97,9 +95,12 @@ export const createAnimation = (animationId?: string): Animation => {
* animation's elements, and removes the
* animation's stylesheets from the DOM.
*/
const cleanUp = () => {
const cleanUp = (clearStyleSheets?: boolean) => {
cleanUpElements();
if (clearStyleSheets) {
cleanUpStyleSheets();
}
};
const resetFlags = () => {