fix(backdrop): dont allow counter to go below 0

This commit is contained in:
Andrew
2015-04-13 13:16:48 -06:00
parent 1a10c8a45b
commit fdca73a5d5
4 changed files with 15 additions and 26 deletions

View File

@@ -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]);
@@ -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() {

View File

@@ -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() {

View File

@@ -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) {

View File

@@ -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) {