Skip to content

Commit

Permalink
fix($$RAFProvider): check for webkitCancelRequestAnimationFrame.
Browse files Browse the repository at this point in the history
Android 4.3 only supports webkitCancelRequestAnimationFrame.

Closes angular#6526
  • Loading branch information
Traxmaxx committed Mar 6, 2014
1 parent d07101d commit d324c9e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/ng/raf.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
'use strict';

function $$RAFProvider(){ //rAF
this.$get = ['$window', function($window) {
var requestAnimationFrame = $window.requestAnimationFrame ||
$window.webkitRequestAnimationFrame;
function createRAF($window) {
var requestAnimationFrame = $window.requestAnimationFrame ||
$window.webkitRequestAnimationFrame;

var cancelAnimationFrame = $window.cancelAnimationFrame ||
$window.webkitCancelAnimationFrame;
var cancelAnimationFrame = $window.cancelAnimationFrame ||
$window.webkitCancelAnimationFrame ||
$window.webkitCancelRequestAnimationFrame;

var raf = function(fn) {
var id = requestAnimationFrame(fn);
return function() {
cancelAnimationFrame(id);
};
var raf = function(fn) {
var id = requestAnimationFrame(fn);
return function() {
cancelAnimationFrame(id);
};
};

raf.supported = !!requestAnimationFrame;

raf.supported = !!requestAnimationFrame;
return raf;
}

return raf;
function $$RAFProvider(){ //rAF
this.$get = ['$window', function($window) {
return createRAF($window);
}];
}
24 changes: 24 additions & 0 deletions test/ng/rafSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,28 @@ describe('$$rAF', function() {
}
}));
});

describe('mobile', function() {
var $window;

it('should provide a cancellation method for an older version of Android', function() {
module(function($provide) {
$provide.value('$window', {
webkitRequestAnimationFrame: jasmine.createSpy('$window.webkitRequestAnimationFrame'),
webkitCancelRequestAnimationFrame: jasmine.createSpy('$window.webkitCancelRequestAnimationFrame')
});
});

inject(function($window) {
var $raf = createRAF($window);
var cancel = $raf(function() {});

try {
cancel();
} catch(e) {}

expect($window.webkitCancelRequestAnimationFrame).toHaveBeenCalled();
});
});
});
});

1 comment on commit d324c9e

@nenadvicentic
Copy link

Choose a reason for hiding this comment

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

I think this should be merged with another patch for old Firefox versions.
https://github.com/thomasbelin4/angular.js/blob/42de3e7ed28880f9fc89654419a2df21a2e9f2a9/src/ng/raf.js

Please sign in to comment.