Skip to content

Commit fdca73a

Browse files
committed
fix(backdrop): dont allow counter to go below 0
1 parent 1a10c8a commit fdca73a

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

Diff for: js/angular/service/backdrop.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
*/
3535
IonicModule
3636
.factory('$ionicBackdrop', [
37-
'$document', '$timeout',
38-
function($document, $timeout) {
37+
'$document', '$timeout', '$$rAF', '$$q',
38+
function($document, $timeout, $$rAF, $$q) {
3939

4040
var el = jqLite('<div class="backdrop">');
4141
var backdropHolds = 0;
42+
var backdropIsActive = false;
4243

4344
$document[0].body.appendChild(el[0]);
4445

@@ -64,20 +65,24 @@ function($document, $timeout) {
6465
};
6566

6667
function retain() {
67-
if ((++backdropHolds) === 1) {
68+
backdropHolds++;
69+
if (backdropHolds === 1) {
6870
el.addClass('visible');
69-
ionic.requestAnimationFrame(function() {
70-
backdropHolds && el.addClass('active');
71+
$$rAF(function() {
72+
// If we're still at >0 backdropHolds after async...
73+
if (backdropHolds >= 1) el.addClass('active');
7174
});
7275
}
7376
}
7477
function release() {
75-
if ((--backdropHolds) === 0) {
78+
if (backdropHolds === 1) {
7679
el.removeClass('active');
7780
$timeout(function() {
78-
!backdropHolds && el.removeClass('visible');
81+
// If we're still at 0 backdropHolds after async...
82+
if (backdropHolds === 0) el.removeClass('visible');
7983
}, 400, false);
8084
}
85+
backdropHolds = Math.max(0, backdropHolds - 1);
8186
}
8287

8388
function getElement() {

Diff for: js/angular/service/clickBlock.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function($document, $ionicBody, $timeout) {
3535
show: function(autoExpire) {
3636
pendingShow = true;
3737
$timeout.cancel(fallbackTimer);
38-
fallbackTimer = $timeout(this.hide, autoExpire || 310);
38+
fallbackTimer = $timeout(this.hide, autoExpire || 310, false);
3939
addClickBlock();
4040
},
4141
hide: function() {

Diff for: test/unit/angular/directive/backdrop.unit.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
describe('$ionicBackdrop service', function() {
2-
beforeEach(module('ionic'));
3-
4-
beforeEach(inject(function($animate) {
5-
ionic.requestAnimationFrame = function(cb) { cb(); };
2+
beforeEach(module('ionic', function($provide) {
3+
$provide.value('$$rAF', function(cb) { cb(); });
64
}));
75

86
it('should add active on retain', inject(function($ionicBackdrop) {

Diff for: test/unit/angular/service/loading.unit.js

-14
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,6 @@ describe('$ionicLoading service', function() {
157157
expect(loader.isShown).toBe(false);
158158
expect(loader.element.hasClass('active')).toBe(false);
159159
}));
160-
it('show should only active after raf is still isShown', inject(function($ionicLoading) {
161-
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
162-
var rafCallback;
163-
ionic.requestAnimationFrame = function(cb) {
164-
rafCallback = cb;
165-
};
166-
loader.show({});
167-
expect(loader.isShown).toBe(true);
168-
loader.hide();
169-
expect(loader.isShown).toBe(false);
170-
rafCallback();
171-
expect(loader.element.hasClass('active')).toBe(false);
172-
ionic.requestAnimationFrame = function(cb) { cb(); };
173-
}));
174160

175161
describe("back button", function() {
176162
it('.show() should register back button action', inject(function($ionicLoading, $ionicPlatform, $timeout) {

0 commit comments

Comments
 (0)