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

Commit 34c4426

Browse files
committed
fix($animateCss): ensure that custom durations do not confuse the gcs cache
Closes #11723
1 parent 0681a54 commit 34c4426

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

src/ngAnimate/animateCss.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
626626

627627
var timings = computeTimings(node, fullClassName, cacheKey);
628628
var relativeDelay = timings.maxDelay;
629-
maxDelay = Math.max(relativeDelay, 0);
629+
maxDelay = Math.max(relativeDelay, 0) || 0;
630630
maxDuration = timings.maxDuration;
631631

632632
var flags = {};
@@ -665,7 +665,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
665665
// we need to recalculate the delay value since we used a pre-emptive negative
666666
// delay value and the delay value is required for the final event checking. This
667667
// property will ensure that this will happen after the RAF phase has passed.
668-
if (timings.transitionDuration > 0) {
668+
if (options.duration == null && timings.transitionDuration > 0) {
669669
flags.recalculateTimingStyles = flags.recalculateTimingStyles || isFirst;
670670
}
671671

@@ -742,6 +742,9 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
742742
applyAnimationClasses(element, options);
743743
applyAnimationStyles(element, options);
744744

745+
// we increment the counter so that if the same element is animated
746+
// then the existing cache will not apply to it
747+
745748
// the reason why we have this option is to allow a synchronous closing callback
746749
// that is fired as SOON as the animation ends (when the CSS is removed) or if
747750
// the animation never takes off at all. A good example is a leave animation since
@@ -854,7 +857,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
854857

855858
timings = computeTimings(node, fullClassName, cacheKey);
856859
relativeDelay = timings.maxDelay;
857-
maxDelay = Math.max(relativeDelay, 0);
860+
maxDelay = Math.max(relativeDelay, 0) || 0;
858861
maxDuration = timings.maxDuration;
859862

860863
if (maxDuration === 0) {
@@ -871,7 +874,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
871874
? parseFloat(options.delay)
872875
: relativeDelay;
873876

874-
maxDelay = Math.max(relativeDelay, 0);
877+
maxDelay = Math.max(relativeDelay, 0) || 0;
875878

876879
var delayStyle;
877880
if (flags.applyTransitionDelay) {

test/ngAnimate/animateCssSpec.js

+41
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,47 @@ describe("ngAnimate $animateCss", function() {
12031203
});
12041204
});
12051205

1206+
it('should avoid applying the same cache to an element a follow-up animation is run on the same element',
1207+
inject(function($animateCss, $rootElement, $document) {
1208+
1209+
var element = jqLite('<div></div>');
1210+
element.attr('class', '');
1211+
1212+
$rootElement.append(element);
1213+
jqLite($document[0].body).append($rootElement);
1214+
1215+
var runner = $animateCss(element, {
1216+
duration: 0.5,
1217+
to: { background: 'red' }
1218+
}).start();
1219+
1220+
triggerAnimationStartFrame();
1221+
expect(element.attr('style')).toContain('transition');
1222+
1223+
browserTrigger(element, 'transitionend',
1224+
{ timeStamp: Date.now(), elapsedTime: 0.5 });
1225+
1226+
expect(element.attr('style')).not.toContain('transition');
1227+
1228+
runner = $animateCss(element, {
1229+
duration: 0.8,
1230+
to: { background: 'blue' }
1231+
}).start();
1232+
1233+
triggerAnimationStartFrame();
1234+
expect(element.attr('style')).toContain('transition');
1235+
1236+
browserTrigger(element, 'transitionend',
1237+
{ timeStamp: Date.now(), elapsedTime: 0.5 });
1238+
1239+
expect(element.attr('style')).toContain('transition');
1240+
1241+
browserTrigger(element, 'transitionend',
1242+
{ timeStamp: Date.now(), elapsedTime: 0.8 });
1243+
1244+
expect(element.attr('style')).not.toContain('transition');
1245+
}));
1246+
12061247
it('should apply a custom temporary class when a non-structural animation is used',
12071248
inject(function($animateCss, $rootElement, $document) {
12081249

0 commit comments

Comments
 (0)