Skip to content

Commit

Permalink
fix(view): proper view lifecycle for caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Dec 5, 2015
1 parent 89c47c2 commit 06ef682
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 5 additions & 4 deletions js/angular/service/viewSwitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,17 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe
$timeout.cancel(enteringEle.data(DATA_FALLBACK_TIMER));
leavingEle && $timeout.cancel(leavingEle.data(DATA_FALLBACK_TIMER));

// emit that the views have finished transitioning
// each parent nav-view will update which views are active and cached
switcher.emit('after', enteringData, leavingData);

// resolve that this one transition (there could be many w/ nested views)
deferred && deferred.resolve(navViewCtrl);

// the most recent transition added has completed and all the active
// transition promises should be added to the services array of promises
if (transitionId === transitionCounter) {
$q.all(transitionPromises).then(ionicViewSwitcher.transitionEnd);

// emit that the views have finished transitioning
// each parent nav-view will update which views are active and cached
switcher.emit('after', enteringData, leavingData);
switcher.cleanup(enteringData);
}

Expand All @@ -276,6 +276,7 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe
instance.triggerTransitionEnd();
});


// remove any references that could cause memory issues
nextTransition = nextDirection = enteringView = leavingView = enteringEle = leavingEle = null;
}
Expand Down
19 changes: 15 additions & 4 deletions test/html/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<button class="button button-icon ion-android-search"></button>
</ion-nav-buttons>
<ion-content padding="true">
<h2>Random {{random}}</h2>
<ion-list>
<div class="item item-divider">
Things
Expand All @@ -46,6 +47,7 @@
<script id="page2.html" type="text/ng-template">
<ion-view title="Page 2">
<ion-content padding="true">
<h2>Random: {{random}}</h2>
<a ng-click="goBack()" class="button button-positive">Back</a>
<a href="#/page3" class="button button-positive">Page 3</a>
</ion-content>
Expand All @@ -62,7 +64,9 @@
<script>
angular.module('nav', ['ionic'])

.config(function($stateProvider, $urlRouterProvider) {
.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {

//$ionicConfigProvider.views.maxCache(0);

$stateProvider
.state('page1', {
Expand All @@ -84,7 +88,8 @@
$urlRouterProvider.otherwise("/page1");
})

.controller('Page1Ctrl', function($scope) {
.controller('Page1Ctrl', function($scope, $ionicHistory) {
$scope.random = Math.random() * 100;
$scope.items = [];
for(var i = 0; i < 4; i++) {
$scope.items.push({});
Expand All @@ -96,7 +101,13 @@
}
})

.controller('Page2Ctrl', function($scope, $ionicNavBarDelegate) {
.controller('Page2Ctrl', function($timeout, $scope, $ionicNavBarDelegate, $ionicHistory) {
$scope.$on('$ionicView.enter', function() {
//$timeout(function() {
$ionicHistory.clearCache();
//})
});

$scope.goBack = function() {
$ionicNavBarDelegate.back();
};
Expand All @@ -107,7 +118,7 @@
$ionicNavBarDelegate.back();
};
})

</script>
</body>
</html>

0 comments on commit 06ef682

Please sign in to comment.