Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 5d0c8d8

Browse files
matskoNarretz
authored andcommitted
feat(ngAnimate): add ng-[event]-prepare class for structural animations
The new prepare class is added before the animation is pushed to the queue and removed before the animation runs. The class can be used to apply CSS to explicitly hide these elements to prevent a flash of content before the animation runs. This can happen if a structural animation (such as ng-if) sits at the bottom of a tree which has ng-class animations on the parents. Because child animations are spaced out with requestAnimationFrame, the ng-enter class might not be applied in time, so the ng.if element is briefly visible before its animation starts.
1 parent b641181 commit 5d0c8d8

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/ngAnimate/.jshintrc

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"REMOVE_CLASS_SUFFIX": false,
2929
"EVENT_CLASS_PREFIX": false,
3030
"ACTIVE_CLASS_SUFFIX": false,
31+
"PREPARE_CLASS_SUFFIX": false,
3132

3233
"TRANSITION_DURATION_PROP": false,
3334
"TRANSITION_DELAY_PROP": false,

src/ngAnimate/animation.js

+10
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
135135
options.tempClasses = null;
136136
}
137137

138+
var prepareClassName;
139+
if (isStructural) {
140+
prepareClassName = 'ng-' + event + PREPARE_CLASS_SUFFIX;
141+
$$jqLite.addClass(element, prepareClassName);
142+
}
143+
138144
animationQueue.push({
139145
// this data is used by the postDigest code and passed into
140146
// the driver step function
@@ -357,6 +363,10 @@ var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
357363
if (tempClasses) {
358364
$$jqLite.addClass(element, tempClasses);
359365
}
366+
if (prepareClassName) {
367+
$$jqLite.removeClass(element, prepareClassName);
368+
prepareClassName = null;
369+
}
360370
}
361371

362372
function updateAnimationRunners(animation, newRunner) {

src/ngAnimate/shared.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var ADD_CLASS_SUFFIX = '-add';
2020
var REMOVE_CLASS_SUFFIX = '-remove';
2121
var EVENT_CLASS_PREFIX = 'ng-';
2222
var ACTIVE_CLASS_SUFFIX = '-active';
23+
var PREPARE_CLASS_SUFFIX = '-prepare';
2324

2425
var NG_ANIMATE_CLASSNAME = 'ng-animate';
2526
var NG_ANIMATE_CHILDREN_DATA = '$$ngAnimateChildren';

0 commit comments

Comments
 (0)