Skip to content

Commit e078dc2

Browse files
matskonetman92
authored andcommitted
fix(ngAnimate): ensure that the temporary CSS classes are applied before detection
Prior to 1.4 the `ng-animate` CSS class was applied before the CSS getComputedStyle detection was issued. This was lost in the 1.4 refactor, however, this patch restores the functionality. Closes angular#11769 Closes angular#11804
1 parent 966a7fb commit e078dc2

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

src/ngAnimate/animation.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
6262
event: event,
6363
structural: isStructural,
6464
options: options,
65-
start: start,
65+
beforeStart: beforeStart,
6666
close: close
6767
});
6868

@@ -88,15 +88,19 @@ var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
8888
animationQueue.length = 0;
8989

9090
forEach(groupAnimations(animations), function(animationEntry) {
91-
var startFn = animationEntry.start;
92-
var closeFn = animationEntry.close;
91+
// it's important that we apply the `ng-animate` CSS class and the
92+
// temporary classes before we do any driver invoking since these
93+
// CSS classes may be required for proper CSS detection.
94+
animationEntry.beforeStart();
95+
9396
var operation = invokeFirstDriver(animationEntry);
94-
var startAnimation = operation && operation.start; /// TODO(matsko): only recognize operation.start()
95-
if (!startAnimation) {
97+
var triggerAnimationStart = operation && operation.start; /// TODO(matsko): only recognize operation.start()
98+
99+
var closeFn = animationEntry.close;
100+
if (!triggerAnimationStart) {
96101
closeFn();
97102
} else {
98-
startFn();
99-
var animationRunner = startAnimation();
103+
var animationRunner = triggerAnimationStart();
100104
animationRunner.done(function(status) {
101105
closeFn(!status);
102106
});
@@ -173,9 +177,9 @@ var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
173177
if (!anchorGroups[lookupKey]) {
174178
var group = anchorGroups[lookupKey] = {
175179
// TODO(matsko): double-check this code
176-
start: function() {
177-
fromAnimation.start();
178-
toAnimation.start();
180+
beforeStart: function() {
181+
fromAnimation.beforeStart();
182+
toAnimation.beforeStart();
179183
},
180184
close: function() {
181185
fromAnimation.close();
@@ -241,7 +245,7 @@ var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
241245
}
242246
}
243247

244-
function start() {
248+
function beforeStart() {
245249
element.addClass(NG_ANIMATE_CLASSNAME);
246250
if (tempClasses) {
247251
$$jqLite.addClass(element, tempClasses);

test/ngAnimate/animationSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,29 @@ describe('$$animation', function() {
734734
expect(element).not.toHaveClass('ng-animate');
735735
}));
736736

737+
738+
it('should apply the `ng-animate` and temporary CSS classes before the driver is invoked', function() {
739+
var capturedElementClasses;
740+
741+
module(function($provide) {
742+
$provide.factory('mockedTestDriver', function() {
743+
return function(details) {
744+
capturedElementClasses = details.element.attr('class');
745+
};
746+
});
747+
});
748+
749+
inject(function($$animation, $rootScope) {
750+
$$animation(element, 'enter', {
751+
tempClasses: 'temp-class-name'
752+
});
753+
$rootScope.$digest();
754+
755+
expect(capturedElementClasses).toMatch(/\bng-animate\b/);
756+
expect(capturedElementClasses).toMatch(/\btemp-class-name\b/);
757+
});
758+
});
759+
737760
it('should perform the DOM operation at the end of the animation if the driver doesn\'t run it already',
738761
inject(function($$animation, $rootScope) {
739762

0 commit comments

Comments
 (0)