Skip to content

Commit 06ef682

Browse files
committed
fix(view): proper view lifecycle for caching
1 parent 89c47c2 commit 06ef682

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,17 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe
257257
$timeout.cancel(enteringEle.data(DATA_FALLBACK_TIMER));
258258
leavingEle && $timeout.cancel(leavingEle.data(DATA_FALLBACK_TIMER));
259259

260-
// emit that the views have finished transitioning
261-
// each parent nav-view will update which views are active and cached
262-
switcher.emit('after', enteringData, leavingData);
263-
264260
// resolve that this one transition (there could be many w/ nested views)
265261
deferred && deferred.resolve(navViewCtrl);
266262

267263
// the most recent transition added has completed and all the active
268264
// transition promises should be added to the services array of promises
269265
if (transitionId === transitionCounter) {
270266
$q.all(transitionPromises).then(ionicViewSwitcher.transitionEnd);
267+
268+
// emit that the views have finished transitioning
269+
// each parent nav-view will update which views are active and cached
270+
switcher.emit('after', enteringData, leavingData);
271271
switcher.cleanup(enteringData);
272272
}
273273

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

279+
279280
// remove any references that could cause memory issues
280281
nextTransition = nextDirection = enteringView = leavingView = enteringEle = leavingEle = null;
281282
}

Diff for: test/html/nav.html

+15-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<button class="button button-icon ion-android-search"></button>
2727
</ion-nav-buttons>
2828
<ion-content padding="true">
29+
<h2>Random {{random}}</h2>
2930
<ion-list>
3031
<div class="item item-divider">
3132
Things
@@ -46,6 +47,7 @@
4647
<script id="page2.html" type="text/ng-template">
4748
<ion-view title="Page 2">
4849
<ion-content padding="true">
50+
<h2>Random: {{random}}</h2>
4951
<a ng-click="goBack()" class="button button-positive">Back</a>
5052
<a href="#/page3" class="button button-positive">Page 3</a>
5153
</ion-content>
@@ -62,7 +64,9 @@
6264
<script>
6365
angular.module('nav', ['ionic'])
6466

65-
.config(function($stateProvider, $urlRouterProvider) {
67+
.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
68+
69+
//$ionicConfigProvider.views.maxCache(0);
6670

6771
$stateProvider
6872
.state('page1', {
@@ -84,7 +88,8 @@
8488
$urlRouterProvider.otherwise("/page1");
8589
})
8690

87-
.controller('Page1Ctrl', function($scope) {
91+
.controller('Page1Ctrl', function($scope, $ionicHistory) {
92+
$scope.random = Math.random() * 100;
8893
$scope.items = [];
8994
for(var i = 0; i < 4; i++) {
9095
$scope.items.push({});
@@ -96,7 +101,13 @@
96101
}
97102
})
98103

99-
.controller('Page2Ctrl', function($scope, $ionicNavBarDelegate) {
104+
.controller('Page2Ctrl', function($timeout, $scope, $ionicNavBarDelegate, $ionicHistory) {
105+
$scope.$on('$ionicView.enter', function() {
106+
//$timeout(function() {
107+
$ionicHistory.clearCache();
108+
//})
109+
});
110+
100111
$scope.goBack = function() {
101112
$ionicNavBarDelegate.back();
102113
};
@@ -107,7 +118,7 @@
107118
$ionicNavBarDelegate.back();
108119
};
109120
})
110-
121+
111122
</script>
112123
</body>
113124
</html>

0 commit comments

Comments
 (0)