Skip to content

Commit cef6708

Browse files
vladipusmhartington
authored andcommitted
fix(history): maintain nextViewOptions with resolves
Closes #3027. Closes #3892 An updated fix for #3027 Launches the expiration timer only after successful state transition.
1 parent bcfe210 commit cef6708

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Diff for: js/angular/service/history.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
4242
var DIRECTION_NONE = 'none';
4343

4444
var stateChangeCounter = 0;
45-
var lastStateId, nextViewOptions, nextViewExpireTimer, forcedNav;
45+
var lastStateId, nextViewOptions, deregisterStateChangeListener, nextViewExpireTimer, forcedNav;
4646

4747
var viewHistory = {
4848
histories: { root: { historyId: 'root', parentHistoryId: null, stack: [], cursor: -1 } },
@@ -367,6 +367,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
367367
hist.stack.push(viewHistory.views[viewId]);
368368
}
369369

370+
deregisterStateChangeListener && deregisterStateChangeListener();
370371
$timeout.cancel(nextViewExpireTimer);
371372
if (nextViewOptions) {
372373
if (nextViewOptions.disableAnimate) direction = DIRECTION_NONE;
@@ -682,6 +683,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
682683
* ```
683684
*/
684685
nextViewOptions: function(opts) {
686+
deregisterStateChangeListener && deregisterStateChangeListener();
685687
if (arguments.length) {
686688
$timeout.cancel(nextViewExpireTimer);
687689
if (opts === null) {
@@ -690,9 +692,11 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
690692
nextViewOptions = nextViewOptions || {};
691693
extend(nextViewOptions, opts);
692694
if (nextViewOptions.expire) {
693-
nextViewExpireTimer = $timeout(function() {
694-
nextViewOptions = null;
695-
}, nextViewOptions.expire);
695+
deregisterStateChangeListener = $rootScope.$on('$stateChangeSuccess', function() {
696+
nextViewExpireTimer = $timeout(function(){
697+
nextViewOptions = null;
698+
}, nextViewOptions.expire);
699+
});
696700
}
697701
}
698702
}

0 commit comments

Comments
 (0)