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

Commit f83693e

Browse files
committed
fix($animate): make sure to run a post-digest reflow for parentless animations
Closes #12400
1 parent 32d3cbb commit f83693e

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

src/ngAnimate/animation.js

+25-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,16 @@ var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
106106
result = result.concat(row);
107107
}
108108

109-
return result;
109+
var terminalAnimations = [];
110+
var parentAnimations = [];
111+
forEach(result, function(result) {
112+
if (result.terminal) {
113+
terminalAnimations.push(result);
114+
} else {
115+
parentAnimations.push(result);
116+
}
117+
});
118+
return [parentAnimations, terminalAnimations];
110119
}
111120
}
112121

@@ -220,10 +229,22 @@ var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
220229
var anim = sortAnimations(toBeSortedAnimations);
221230
var finalLevel = anim.length - 1;
222231

223-
forEach(anim, function(entry) {
224-
if (!entry.terminal) {
232+
// sortAnimations will return two lists of animations. The first list
233+
// is all of the parent animations that are likely class-based and the
234+
// second list is a collection of the rest. Before we run the second
235+
// list we must ensure that atleast one reflow has been passed such that
236+
// the preparation classes (ng-enter, class-add, etc...) have been applied
237+
// to their associated element.
238+
if (anim[0].length) {
239+
forEach(anim[0], function(entry) {
225240
$$forceReflow();
226-
}
241+
entry.fn();
242+
});
243+
} else {
244+
$$forceReflow();
245+
}
246+
247+
forEach(anim[1], function(entry) {
227248
entry.fn();
228249
});
229250
});

test/ngAnimate/integrationSpec.js

+24
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,30 @@ describe('ngAnimate integration tests', function() {
335335
expect($animate.reflows).toBe(0);
336336
});
337337
});
338+
339+
iit('should always issue atleast one reflow incase there are no parent class-based animations', function() {
340+
module('ngAnimateMock');
341+
inject(function($animate, $compile, $rootScope, $rootElement, $$rAF, $document) {
342+
element = jqLite(
343+
'<div ng-repeat="item in items" ng-class="{someAnimation:exp}">' +
344+
'{{ item }}' +
345+
'</div>'
346+
);
347+
348+
$rootElement.append(element);
349+
jqLite($document[0].body).append($rootElement);
350+
351+
$compile(element)($rootScope);
352+
$rootScope.$digest();
353+
expect($animate.reflows).toBe(0);
354+
355+
$rootScope.exp = true;
356+
$rootScope.items = [1,2,3,4,5,6,7,8,9,10];
357+
$rootScope.$digest();
358+
359+
expect($animate.reflows).toBe(1);
360+
});
361+
});
338362
});
339363

340364
describe('JS animations', function() {

0 commit comments

Comments
 (0)