From 7cbfcc18d81096d8ab3379681bb55bb6ed24a611 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 10 Jan 2014 15:08:23 -0600 Subject: [PATCH] view-state fixes --- dist/js/ionic-angular.js | 62 +++++++++++-------- .../angular/src/directive/ionicViewState.js | 37 ++++++----- js/ext/angular/src/service/ionicView.js | 25 ++++++-- js/ext/angular/test/service/ionicView.unit.js | 44 +++++++++++++ 4 files changed, 118 insertions(+), 50 deletions(-) diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index 1c855131d4..c9c4fded52 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -620,7 +620,12 @@ angular.module('ionic.service.view', ['ui.router']) return null; }; View.prototype.go = function(opts) { - if(this.url && this.url !== $location.url() && (!opts || opts.enableUrlChange !== false)) { + + if(this.stateName) { + return $state.go(this.stateName, this.stateParams); + } + + if(this.url && this.url !== $location.url()) { if($rootScope.$viewHistory.backView === this) { return $window.history.go(-1); @@ -628,11 +633,8 @@ angular.module('ionic.service.view', ['ui.router']) return $window.history.go(1); } - return $location.url(this.url); - } - - if(this.stateName) { - return $state.go(this.stateName, this.stateParams); + $location.url(this.url); + return; } return null; @@ -696,6 +698,13 @@ angular.module('ionic.service.view', ['ui.router']) rsp.historyId = forwardView.historyId; } + } else if(currentView && currentView.historyId !== hist.historyId && + hist.cursor > -1 && hist.stack.length > 0 && hist.cursor < hist.stack.length && + hist.stack[hist.cursor].stateId === currentStateId) { + // they just changed to a different history and the history already has views in it + rsp.viewId = hist.stack[hist.cursor].viewId; + rsp.navAction = 'moveBack'; + } else { // set a new unique viewId @@ -754,6 +763,10 @@ angular.module('ionic.service.view', ['ui.router']) hist.cursor = viewHistory.currentView.index; + $rootScope.$broadcast('$viewHistory.historyChange', { + showBack: (viewHistory.backView && viewHistory.backView.historyId === viewHistory.currentView.historyId) + }); + return rsp; }, @@ -2881,7 +2894,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu }, template: '