This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($animateCss): use timing functions when present #12666
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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\(.+\)/; | ||
|
||
function getCssKeyframeDurationStyle(duration) { | ||
return [ANIMATION_DURATION_PROP, duration + 's']; | ||
} | ||
|
@@ -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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||
} | ||
|
@@ -437,6 +443,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) { | |
|
||
var temporaryStyles = []; | ||
var classes = element.attr('class'); | ||
var computedStyles = $window.getComputedStyle(element[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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); | ||
|
@@ -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) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 isease
).