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

fix($animate): ensure that parallel class-based animations are all eventually closed #7767

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/ngAnimate/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,9 @@ angular.module('ngAnimate', ['ng'])
forEach(elements, function(element) {
var elementData = element.data(NG_ANIMATE_CSS_DATA_KEY);
if(elementData) {
(elementData.closeAnimationFn || noop)();
forEach(elementData.closeAnimationFns, function(fn) {
fn();
});
}
});
}
Expand Down Expand Up @@ -1431,14 +1433,15 @@ angular.module('ngAnimate', ['ng'])
stagger.animationDelay > 0 &&
stagger.animationDuration === 0;

var closeAnimationFns = formerData.closeAnimationFns || [];
element.data(NG_ANIMATE_CSS_DATA_KEY, {
stagger : stagger,
cacheKey : eventCacheKey,
running : formerData.running || 0,
itemIndex : itemIndex,
blockTransition : blockTransition,
blockAnimation : blockAnimation,
closeAnimationFn : noop
closeAnimationFns : closeAnimationFns
});

var node = extractElementNode(element);
Expand Down Expand Up @@ -1530,10 +1533,10 @@ angular.module('ngAnimate', ['ng'])
var css3AnimationEvents = ANIMATIONEND_EVENT + ' ' + TRANSITIONEND_EVENT;

element.on(css3AnimationEvents, onAnimationProgress);
elementData.closeAnimationFn = function() {
elementData.closeAnimationFns.push(function() {
onEnd();
activeAnimationComplete();
};
});

var staggerTime = itemIndex * (Math.max(stagger.animationDelay, stagger.transitionDelay) || 0);
var animationTime = (maxDelay + maxDuration) * CLOSING_TIME_BUFFER;
Expand Down
26 changes: 26 additions & 0 deletions test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,32 @@ describe("ngAnimate", function() {
});
});

it('should apply a closing timeout to close all parallel class-based animations on the same element',
inject(function($sniffer, $compile, $rootScope, $rootElement, $animate, $timeout) {

if (!$sniffer.transitions) return;

ss.addRule('.base-class', '-webkit-transition:2s linear all;' +
'transition:2s linear all;');

var element = $compile('<div class="base-class"></div>')($rootScope);
$rootElement.append(element);
jqLite($document[0].body).append($rootElement);

$animate.addClass(element, 'one');
$animate.addClass(element, 'two');

$animate.triggerReflow();

$timeout.flush(3000); //2s * 1.5

expect(element.hasClass('one-add')).toBeFalsy();
expect(element.hasClass('one-add-active')).toBeFalsy();
expect(element.hasClass('two-add')).toBeFalsy();
expect(element.hasClass('two-add-active')).toBeFalsy();
expect(element.hasClass('ng-animate')).toBeFalsy();
}));

it("apply a closing timeout with respect to a staggering animation",
inject(function($animate, $rootScope, $compile, $sniffer, $timeout) {

Expand Down