mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(tabs): prevent unnecessary updates during destroy
If the containing ionTabs directive is being destroyed, then child ionTab directives should not don't bother going through its controller’s `remove` method, which selects a new active tab as each ionTab is being destroyed. By selecting a new active tab as each tab is removed, it causes unnecessary view loads, transitions and multiple `viewState.changeHistory` events.
This commit is contained in:
8
js/angular/directive/tab.js
vendored
8
js/angular/directive/tab.js
vendored
@@ -98,7 +98,13 @@ function($rootScope, $animate, $ionicBind, $compile) {
|
||||
|
||||
tabsCtrl.add($scope);
|
||||
$scope.$on('$destroy', function() {
|
||||
tabsCtrl.remove($scope);
|
||||
if(!$scope.$tabsDestory) {
|
||||
// if the containing ionTabs directive is being destroyed
|
||||
// then don't bother going through the controllers remove
|
||||
// method, since remove will reset the active tab as each tab
|
||||
// is being destroyed, causing unnecessary view loads and transitions
|
||||
tabsCtrl.remove($scope);
|
||||
}
|
||||
tabNavElement.isolateScope().$destroy();
|
||||
tabNavElement.remove();
|
||||
});
|
||||
|
||||
15
js/angular/directive/tabs.js
vendored
15
js/angular/directive/tabs.js
vendored
@@ -50,9 +50,9 @@ IonicModule.constant('$ionicTabsConfig', {
|
||||
|
||||
IonicModule
|
||||
.directive('ionTabs', [
|
||||
'$ionicViewService',
|
||||
'$ionicTabsDelegate',
|
||||
'$ionicTabsConfig',
|
||||
'$ionicViewService',
|
||||
'$ionicTabsDelegate',
|
||||
'$ionicTabsConfig',
|
||||
function($ionicViewService, $ionicTabsDelegate, $ionicTabsConfig) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
@@ -74,7 +74,14 @@ function($ionicViewService, $ionicTabsDelegate, $ionicTabsConfig) {
|
||||
tabsCtrl, $attr.delegateHandle
|
||||
);
|
||||
|
||||
$scope.$on('$destroy', deregisterInstance);
|
||||
$scope.$on('$destroy', function(){
|
||||
// variable to inform child tabs that they're all being blown away
|
||||
// used so that while destorying an individual tab, each one
|
||||
// doesn't select the next tab as the active one, which causes unnecessary
|
||||
// loading of tab views when each will eventually all go away anyway
|
||||
$scope.$tabsDestory = true;
|
||||
deregisterInstance();
|
||||
});
|
||||
|
||||
tabsCtrl.$scope = $scope;
|
||||
tabsCtrl.$element = $element;
|
||||
|
||||
Reference in New Issue
Block a user