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

Commit df7310f

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(progress-circular): animation timing
There were cases where the circle rendering animation would run for one iteration longer than it was supposed to. This caused a bug where the determinate value circle would get drawn at the wrong place at the end of a longer animation. Also replaces the `getTimestamp` method with `$mdUtil.now`. Closes #7471
1 parent 6afb6fc commit df7310f

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/components/progressCircular/js/progressCircularDirective.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function MdProgressCircularDirective($$rAF, $window, $mdProgressCircular, $mdUti
144144

145145
function renderCircle(animateFrom, animateTo, easing, duration, rotation) {
146146
var id = ++lastAnimationId;
147-
var startTime = getTimestamp();
147+
var startTime = $mdUtil.now();
148148
var changeInValue = animateTo - animateFrom;
149149
var diameter = getSize(scope.mdDiameter);
150150
var pathDiameter = diameter - getStroke(diameter);
@@ -156,7 +156,7 @@ function MdProgressCircularDirective($$rAF, $window, $mdProgressCircular, $mdUti
156156
path.attr('d', getSvgArc(animateTo, diameter, pathDiameter, rotation));
157157
} else {
158158
$$rAF(function animation(now) {
159-
var currentTime = (now || getTimestamp()) - startTime;
159+
var currentTime = $window.Math.min((now || $mdUtil.now()) - startTime, animationDuration);
160160

161161
path.attr('d', getSvgArc(
162162
ease(currentTime, animateFrom, changeInValue, animationDuration),
@@ -192,7 +192,7 @@ function MdProgressCircularDirective($$rAF, $window, $mdProgressCircular, $mdUti
192192

193193
function startIndeterminateAnimation() {
194194
if (!interval) {
195-
var startTime = getTimestamp();
195+
var startTime = $mdUtil.now();
196196
var animationDuration = $mdProgressCircular.rotationDurationIndeterminate;
197197
var radius = getSize(scope.mdDiameter) / 2;
198198

@@ -203,7 +203,7 @@ function MdProgressCircularDirective($$rAF, $window, $mdProgressCircular, $mdUti
203203
// with CSS keyframes, however IE11 seems to have problems centering the rotation
204204
// which causes a wobble in the indeterminate animation.
205205
$$rAF(function animation(now) {
206-
var timestamp = now || getTimestamp();
206+
var timestamp = now || $mdUtil.now();
207207
var currentTime = timestamp - startTime;
208208
var rotation = $mdProgressCircular.easingPresets.linearEase(currentTime, 0, 360, animationDuration);
209209

@@ -328,12 +328,4 @@ function MdProgressCircularDirective($$rAF, $window, $mdProgressCircular, $mdUti
328328
function getStroke(diameter) {
329329
return $mdProgressCircular.strokeWidth / 100 * diameter;
330330
}
331-
332-
/**
333-
* Retrieves a timestamp for timing animations.
334-
*/
335-
function getTimestamp() {
336-
var perf = $window.performance;
337-
return perf && perf.now && perf.now() || +new $window.Date();
338-
}
339331
}

0 commit comments

Comments
 (0)