MCPcopy Create free account
hub / github.com/angular/angular / runEnterAnimation

Function runEnterAnimation

packages/core/src/render3/instructions/animation.ts:121–189  ·  view source on GitHub ↗
(
  lView: LView,
  tNode: TNode,
  value: string | AnimationClassBindingFn,
  ngZone: NgZone,
)

Source from the content-addressed store, hash-verified

119}
120
121export function runEnterAnimation(
122 lView: LView,
123 tNode: TNode,
124 value: string | AnimationClassBindingFn,
125 ngZone: NgZone,
126): void {
127 const nativeElement = getNativeByTNode(tNode, lView) as HTMLElement;
128
129 ngDevMode && assertElementNodes(nativeElement, 'animate.enter');
130
131 const renderer = lView[RENDERER];
132
133 // Retrieve the actual class list from the value. This will resolve any resolver functions from
134 // bindings.
135 const activeClasses = getClassListFromValue(value);
136 const cleanupFns: VoidFunction[] = [];
137 let hasCompleted = false;
138
139 // In the case where multiple animations are happening on the element, we need
140 // to get the longest animation to ensure we don't complete animations early.
141 // This also allows us to setup cancellation of animations in progress if the
142 // gets removed early.
143 const handleEnterAnimationStart = (event: AnimationEvent | TransitionEvent) => {
144 // this early exit case is to prevent issues with bubbling events that are from child element animations
145 if (getEventTarget(event) !== nativeElement) return;
146
147 const eventName = event instanceof AnimationEvent ? 'animationend' : 'transitionend';
148 ngZone.runOutsideAngular(() => {
149 renderer.listen(nativeElement, eventName, handleEnterAnimationEnd);
150 });
151 };
152
153 // When the longest animation ends, we can remove all the classes
154 const handleEnterAnimationEnd = (event: AnimationEvent | TransitionEvent) => {
155 // this early exit case is to prevent issues with bubbling events that are from child element animations
156 if (getEventTarget(event) !== nativeElement) return;
157
158 if (isLongestAnimation(event, nativeElement)) {
159 hasCompleted = true;
160 }
161 enterAnimationEnd(event, nativeElement, renderer);
162 };
163
164 // We only need to add these event listeners if there are actual classes to apply
165 if (activeClasses && activeClasses.length > 0) {
166 ngZone.runOutsideAngular(() => {
167 cleanupFns.push(renderer.listen(nativeElement, 'animationstart', handleEnterAnimationStart));
168 cleanupFns.push(renderer.listen(nativeElement, 'transitionstart', handleEnterAnimationStart));
169 });
170
171 trackEnterClasses(nativeElement, activeClasses, cleanupFns);
172
173 addClasses(renderer, nativeElement, activeClasses);
174
175 // In the case that the classes added have no animations, we need to remove
176 // the classes right away. This could happen because someone is intentionally
177 // preventing an animation via selector specificity.
178 ngZone.runOutsideAngular(() => {

Callers 1

ɵɵanimateEnterFunction · 0.85

Calls 12

getNativeByTNodeFunction · 0.90
assertElementNodesFunction · 0.90
getClassListFromValueFunction · 0.90
trackEnterClassesFunction · 0.90
addClassesFunction · 0.90
removeClassesFunction · 0.90
cleanupEnterClassDataFunction · 0.90
listenMethod · 0.65
hasMethod · 0.65
runOutsideAngularMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected