Better slide animation

This commit is contained in:
Max Lynch
2013-11-18 18:36:00 -06:00
parent 2ea66ecfb3
commit 78a16a9af1
5 changed files with 109 additions and 76 deletions

View File

@ -25,30 +25,25 @@ angular.module('ionic.ui.navRouter', [])
$rootScope.stackCursorPosition = 0;
}])
.directive('navRouter', ['$rootScope', '$location', '$window', '$route', function($rootScope, $location, $window, $route) {
.directive('navRouter', ['$rootScope', '$timeout', '$location', '$window', '$route', function($rootScope, $timeout, $location, $window, $route) {
return {
restrict: 'AC',
link: function($scope, $element, $attr) {
$scope.animation = $attr.animation;
$element.addClass($scope.animation);
var isFirst = true;
$scope.isReverse = false;
var reverseTransition = ionic.throttle(function() {
var reverseTransition = function() {
console.log('REVERSE');
$element.removeClass($scope.animation);
$element.addClass($scope.animation + '-reverse');
}, 1000, {
})
};
var forwardTransition = ionic.throttle(function() {
var forwardTransition = function() {
console.log('FORWARD');
$element.removeClass($scope.animation + '-reverse');
$element.addClass($scope.animation);
}, 1000, {
});
};
$scope.$on('$routeChangeSuccess', function(e, a) {
console.log('ROUTE CHANGED', a, e);
@ -58,6 +53,12 @@ angular.module('ionic.ui.navRouter', [])
var back, historyState = $window.history.state;
back = !!(historyState && historyState.position <= $rootScope.stackCursorPosition);
if(isFirst) {
// Don't animate
//return;
}
if(back) {
reverseTransition();
} else {
@ -69,6 +70,12 @@ angular.module('ionic.ui.navRouter', [])
// Store the new location
console.log('LOCATION CHANGE SUCCESS');
$rootScope.actualLocation = $location.path();
if(isFirst) {
isFirst = false;
$timeout(function() {
//reverseTransition();
}, 200);
}
});