Skip to content
This repository was archived by the owner on Mar 1, 2025. It is now read-only.

Commit 372d48b

Browse files
committed
fix($$RAFProvider): check for webkitCancelRequestAnimationFrame.
Android 4.3 only supports webkitCancelRequestAnimationFrame. Closes angular#6526
1 parent d07101d commit 372d48b

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

src/ng/raf.js

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
'use strict';
22

3-
function $$RAFProvider(){ //rAF
4-
this.$get = ['$window', function($window) {
5-
var requestAnimationFrame = $window.requestAnimationFrame ||
6-
$window.webkitRequestAnimationFrame;
3+
function createRAF($window) {
4+
var requestAnimationFrame = $window.requestAnimationFrame ||
5+
$window.webkitRequestAnimationFrame;
76

8-
var cancelAnimationFrame = $window.cancelAnimationFrame ||
9-
$window.webkitCancelAnimationFrame;
7+
var cancelAnimationFrame = $window.cancelAnimationFrame ||
8+
$window.webkitCancelAnimationFrame ||
9+
$window.webkitCancelRequestAnimationFrame;
1010

11-
var raf = function(fn) {
12-
var id = requestAnimationFrame(fn);
13-
return function() {
14-
cancelAnimationFrame(id);
15-
};
11+
var raf = function(fn) {
12+
var id = requestAnimationFrame(fn);
13+
return function() {
14+
cancelAnimationFrame(id);
1615
};
16+
};
17+
18+
raf.supported = !!requestAnimationFrame;
1719

18-
raf.supported = !!requestAnimationFrame;
20+
return raf;
21+
}
1922

20-
return raf;
23+
function $$RAFProvider(){ //rAF
24+
this.$get = ['$window', function($window) {
25+
return createRAF($window);
2126
}];
2227
}

test/ng/rafSpec.js

+24
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,28 @@ describe('$$rAF', function() {
4444
}
4545
}));
4646
});
47+
48+
describe('mobile', function() {
49+
var $window;
50+
51+
it('should provide a cancellation method for an older version of Android', function() {
52+
module(function($provide) {
53+
$provide.value('$window', {
54+
webkitRequestAnimationFrame: jasmine.createSpy('$window.webkitRequestAnimationFrame'),
55+
webkitCancelRequestAnimationFrame: jasmine.createSpy('$window.webkitCancelRequestAnimationFrame')
56+
});
57+
});
58+
59+
inject(function($window) {
60+
var $raf = createRAF($window);
61+
var cancel = $raf(function() {});
62+
63+
try {
64+
cancel();
65+
} catch(e) {}
66+
67+
expect($window.webkitCancelRequestAnimationFrame).toHaveBeenCalled();
68+
});
69+
});
70+
});
4771
});

0 commit comments

Comments
 (0)