Skip to content

Commit

Permalink
fix(backdrop): dont allow counter to go below 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Apr 13, 2015
1 parent 1a10c8a commit fdca73a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 26 deletions.
19 changes: 12 additions & 7 deletions js/angular/service/backdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
*/
IonicModule
.factory('$ionicBackdrop', [
'$document', '$timeout',
function($document, $timeout) {
'$document', '$timeout', '$$rAF', '$$q',
function($document, $timeout, $$rAF, $$q) {

var el = jqLite('<div class="backdrop">');
var backdropHolds = 0;
var backdropIsActive = false;

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

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

function retain() {
if ((++backdropHolds) === 1) {
backdropHolds++;
if (backdropHolds === 1) {
el.addClass('visible');
ionic.requestAnimationFrame(function() {
backdropHolds && el.addClass('active');
$$rAF(function() {
// If we're still at >0 backdropHolds after async...
if (backdropHolds >= 1) el.addClass('active');
});
}
}
function release() {
if ((--backdropHolds) === 0) {
if (backdropHolds === 1) {
el.removeClass('active');
$timeout(function() {
!backdropHolds && el.removeClass('visible');
// If we're still at 0 backdropHolds after async...
if (backdropHolds === 0) el.removeClass('visible');
}, 400, false);
}
backdropHolds = Math.max(0, backdropHolds - 1);
}

function getElement() {
Expand Down
2 changes: 1 addition & 1 deletion js/angular/service/clickBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function($document, $ionicBody, $timeout) {
show: function(autoExpire) {
pendingShow = true;
$timeout.cancel(fallbackTimer);
fallbackTimer = $timeout(this.hide, autoExpire || 310);
fallbackTimer = $timeout(this.hide, autoExpire || 310, false);
addClickBlock();
},
hide: function() {
Expand Down
6 changes: 2 additions & 4 deletions test/unit/angular/directive/backdrop.unit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
describe('$ionicBackdrop service', function() {
beforeEach(module('ionic'));

beforeEach(inject(function($animate) {
ionic.requestAnimationFrame = function(cb) { cb(); };
beforeEach(module('ionic', function($provide) {
$provide.value('$$rAF', function(cb) { cb(); });
}));

it('should add active on retain', inject(function($ionicBackdrop) {
Expand Down
14 changes: 0 additions & 14 deletions test/unit/angular/service/loading.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,6 @@ describe('$ionicLoading service', function() {
expect(loader.isShown).toBe(false);
expect(loader.element.hasClass('active')).toBe(false);
}));
it('show should only active after raf is still isShown', inject(function($ionicLoading) {
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
var rafCallback;
ionic.requestAnimationFrame = function(cb) {
rafCallback = cb;
};
loader.show({});
expect(loader.isShown).toBe(true);
loader.hide();
expect(loader.isShown).toBe(false);
rafCallback();
expect(loader.element.hasClass('active')).toBe(false);
ionic.requestAnimationFrame = function(cb) { cb(); };
}));

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

0 comments on commit fdca73a

Please sign in to comment.