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

fix($animateCss): use timing functions when present #12666

Closed
Closed
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
15 changes: 11 additions & 4 deletions src/ngAnimate/animateCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ var DETECT_CSS_PROPERTIES = {
transitionDuration: TRANSITION_DURATION_PROP,
transitionDelay: TRANSITION_DELAY_PROP,
transitionProperty: TRANSITION_PROP + PROPERTY_KEY,
transitionTimingFunction: TRANSITION_PROP + TIMING_KEY,
animationDuration: ANIMATION_DURATION_PROP,
animationDelay: ANIMATION_DELAY_PROP,
animationIterationCount: ANIMATION_PROP + ANIMATION_ITERATION_COUNT_KEY
Expand All @@ -232,6 +233,8 @@ var DETECT_STAGGER_CSS_PROPERTIES = {
animationDelay: ANIMATION_DELAY_PROP
};

var TRANSITION_EASING_VALUE = /ease|ease-in|ease-out|ease-in-out|linear|step-start|step-end|steps\(.+\)|cubic-bezier\(.+\)/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the regex fails when I have something like transition: 1s ease-in-out color' (It will take the first match, which is ease).


function getCssKeyframeDurationStyle(duration) {
return [ANIMATION_DURATION_PROP, duration + 's'];
}
Expand Down Expand Up @@ -286,13 +289,16 @@ function truthyTimingValue(val) {
return val === 0 || val != null;
}

function getCssTransitionDurationStyle(duration, applyOnlyDuration) {
function getCssTransitionStyle(computedStyles, duration, applyOnlyDuration) {
var style = TRANSITION_PROP;
var value = duration + 's';
if (applyOnlyDuration) {
style += DURATION_KEY;
} else {
value += ' linear all';
var transitionStyle = computedStyles[TRANSITION_PROP];
var match = TRANSITION_EASING_VALUE.test(transitionStyle);
transitionStyle = match ? transitionStyle.match(TRANSITION_EASING_VALUE)[0] : 'linear';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why exec the RegExp twice ? Is there a (noticeable) perf gain ?

value += ' ' + transitionStyle + ' all';
}
return [style, value];
}
Expand Down Expand Up @@ -437,6 +443,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {

var temporaryStyles = [];
var classes = element.attr('class');
var computedStyles = $window.getComputedStyle(element[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably not call this twice. It's called anyway in the "init" fn.

var styles = packageStyles(options);
var animationClosed;
var animationPaused;
Expand Down Expand Up @@ -531,7 +538,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {

if (options.duration >= 0) {
applyOnlyDuration = node.style[TRANSITION_PROP].length > 0;
var durationStyle = getCssTransitionDurationStyle(options.duration, applyOnlyDuration);
var durationStyle = getCssTransitionStyle(computedStyles, options.duration, applyOnlyDuration);

// we set the duration so that it will be picked up by getComputedStyle later
applyInlineStyle(node, durationStyle);
Expand Down Expand Up @@ -586,7 +593,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
flags.hasTransitions = true;
timings.transitionDuration = maxDuration;
applyOnlyDuration = node.style[TRANSITION_PROP + PROPERTY_KEY].length > 0;
temporaryStyles.push(getCssTransitionDurationStyle(maxDuration, applyOnlyDuration));
temporaryStyles.push(getCssTransitionStyle(computedStyles, maxDuration, applyOnlyDuration));
}

if (flags.applyAnimationDuration) {
Expand Down