refactor(): ggnore, ngAnimate

Addresses #1100
This commit is contained in:
Andy Joslin
2014-04-11 07:32:34 -06:00
parent e75e20dc9d
commit bc3e223e33
9 changed files with 69 additions and 177 deletions

View File

@@ -1,55 +0,0 @@
/**
* Stop race conditions with toggling an ngAnimate on an element rapidly,
* due to the asynchronous nature of addClass and removeClass
*
* Additionally, only toggle classes on requestAnimationFrame, to stop flickers on
* iOS and older android for elements that were just attached to the DOM.
*/
angular.module('ionic')
.factory('$animateClassToggler', [
'$animate',
'$rootScope',
function($animate, $rootScope) {
return function(element, className) {
var self = {
_nextOperation: null,
_animating: false,
_toggle: toggle,
_animate: animate,
_animationDone: animationDone,
addClass: function() { self._toggle(true); },
removeClass: function() { self._toggle(false); }
};
return self;
function toggle(hasClass) {
var operation = hasClass ? 'addClass' : 'removeClass';
if (self._animating) {
self._nextOperation = operation;
} else {
self._animate(operation);
}
}
function animate(operation) {
self._animating = true;
ionic.requestAnimationFrame(function() {
$rootScope.$evalAsync(function() {
$animate[operation](element, className, self._animationDone);
});
});
}
function animationDone() {
self._animating = false;
if (self._nextOperation) {
self._animate(self._nextOperation);
self._nextOperation = null;
}
}
};
}]);

View File

@@ -4,14 +4,11 @@ angular.module('ionic')
* @private
*/
.factory('$ionicBackdrop', [
'$animate',
'$document',
'$animateClassToggler',
function($animate, $document, $animateClassToggler) {
function($document) {
var el = angular.element('<div class="backdrop ng-hide">');
var el = angular.element('<div class="backdrop">');
var backdropHolds = 0;
var toggler = $animateClassToggler(el, 'ng-hide');
$document[0].body.appendChild(el[0]);
@@ -24,12 +21,18 @@ function($animate, $document, $animateClassToggler) {
function retain() {
if ( (++backdropHolds) === 1 ) {
toggler.removeClass();
el.addClass('visible');
ionic.requestAnimationFrame(function() {
backdropHolds && el.addClass('active');
});
}
}
function release() {
if ( (--backdropHolds) === 0 ) {
toggler.addClass();
el.removeClass('active');
setTimeout(function() {
!backdropHolds && el.removeClass('visible');
}, 100);
}
}
}]);

View File

@@ -1,6 +1,6 @@
var TPL_LOADING =
'<div class="loading ng-hide">' +
'<div class="loading">' +
'</div>';
var HIDE_LOADING_DEPRECATED = '$ionicLoading instance.hide() has been deprecated. Use $ionicLoading.hide().';
@@ -33,7 +33,6 @@ angular.module('ionic.service.loading', [])
* ```
*/
.factory('$ionicLoading', [
'$animate',
'$document',
'$ionicTemplateLoader',
'$ionicBackdrop',
@@ -41,8 +40,7 @@ angular.module('ionic.service.loading', [])
'$q',
'$log',
'$compile',
'$animateClassToggler',
function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile, $animateClassToggler) {
function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile) {
var loaderInstance;
//default value
@@ -83,10 +81,9 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
})
.then(function(loader) {
var toggler = $animateClassToggler(loader.element, 'ng-hide');
var self = loader;
loader.show = function(options) {
var self = this;
var templatePromise = options.templateUrl ?
$ionicTemplateLoader.load(options.templateUrl) :
//options.content: deprecated
@@ -114,10 +111,17 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
self.element.html(html);
$compile(self.element.contents())(self.scope);
}
//Don't show until template changes
if (self.isShown) {
self.element.addClass('visible');
ionic.DomUtil.centerElementByMarginTwice(self.element[0]);
ionic.requestAnimationFrame(function() {
self.isShown && self.element.addClass('active');
});
}
});
toggler.removeClass();
ionic.DomUtil.centerElementByMarginTwice(this.element[0]);
this.isShown = true;
};
loader.hide = function() {
@@ -125,7 +129,10 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
if (this.hasBackdrop) {
$ionicBackdrop.release();
}
toggler.addClass();
self.element.removeClass('active');
setTimeout(function() {
!self.isShown && self.element.removeClass('visible');
}, 200);
}
$timeout.cancel(this.durationTimeout);
this.isShown = false;