mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(navViewController): move view switcher logic
Move some of the $ionicViewSwitcher logic into the navViewController so each ionNavView is capable of updating its own child ionView elements.
This commit is contained in:
86
js/angular/controller/navViewController.js
vendored
86
js/angular/controller/navViewController.js
vendored
@@ -3,15 +3,24 @@ IonicModule
|
||||
'$scope',
|
||||
'$element',
|
||||
'$attrs',
|
||||
'$compile',
|
||||
'$controller',
|
||||
'$ionicNavBarDelegate',
|
||||
'$ionicHistory',
|
||||
'$ionicViewSwitcher',
|
||||
'$ionicConfig',
|
||||
function($scope, $element, $attrs, $ionicNavBarDelegate, $ionicHistory, $ionicViewSwitcher, $ionicConfig) {
|
||||
function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate, $ionicHistory, $ionicViewSwitcher) {
|
||||
|
||||
var DATA_ELE_IDENTIFIER = '$eleId';
|
||||
var VIEW_STATUS_ACTIVE = 'active';
|
||||
var VIEW_STATUS_CACHED = 'cached';
|
||||
var HISTORY_AFTER_ROOT = 'after-root';
|
||||
|
||||
var self = this;
|
||||
var direction;
|
||||
var isPrimary = false;
|
||||
var navBarDelegate;
|
||||
var activeEleId;
|
||||
var navViewAttr = $ionicViewSwitcher.navViewAttr;
|
||||
|
||||
|
||||
self.init = function() {
|
||||
@@ -82,7 +91,7 @@ function($scope, $element, $attrs, $ionicNavBarDelegate, $ionicHistory, $ionicVi
|
||||
|
||||
// register the view and figure out where it lives in the various
|
||||
// histories and nav stacks, along with how views should enter/leave
|
||||
var switcher = $ionicViewSwitcher.create($scope, $element, viewLocals, enteringView, leavingView);
|
||||
var switcher = $ionicViewSwitcher.create(self, viewLocals, enteringView, leavingView);
|
||||
|
||||
// init the rendering of views for this navView directive
|
||||
switcher.init(registerData, function() {
|
||||
@@ -95,16 +104,81 @@ function($scope, $element, $attrs, $ionicNavBarDelegate, $ionicHistory, $ionicVi
|
||||
};
|
||||
|
||||
|
||||
self.beforeEnter = function(transData) {
|
||||
self.beforeEnter = function(transitionData) {
|
||||
if (isPrimary) {
|
||||
// only update this nav-view's nav-bar if this is the primary nav-view
|
||||
navBarDelegate = transData.navBarDelegate;
|
||||
navBarDelegate = transitionData.navBarDelegate;
|
||||
var associatedNavBarCtrl = getAssociatedNavBarCtrl();
|
||||
associatedNavBarCtrl && associatedNavBarCtrl.update(transData);
|
||||
associatedNavBarCtrl && associatedNavBarCtrl.update(transitionData);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
self.activeEleId = function(eleId) {
|
||||
if (arguments.length) {
|
||||
activeEleId = eleId;
|
||||
}
|
||||
return activeEleId;
|
||||
};
|
||||
|
||||
|
||||
self.transitionEnd = function() {
|
||||
var viewElements = $element.children();
|
||||
var viewElementsLength = viewElements.length;
|
||||
var x, viewElement;
|
||||
var isHistoryRoot;
|
||||
|
||||
for (x = 0; x < viewElementsLength; x++) {
|
||||
viewElement = viewElements.eq(x);
|
||||
|
||||
if (viewElement.data(DATA_ELE_IDENTIFIER) === activeEleId) {
|
||||
// this is the active element
|
||||
navViewAttr(viewElement, VIEW_STATUS_ACTIVE);
|
||||
isHistoryRoot = $ionicViewSwitcher.isHistoryRoot(viewElement);
|
||||
|
||||
} else if (navViewAttr(viewElement) === 'leaving' || navViewAttr(viewElement) === VIEW_STATUS_ACTIVE) {
|
||||
// this is a leaving element or was the former active element
|
||||
navViewAttr(viewElement, VIEW_STATUS_CACHED);
|
||||
}
|
||||
}
|
||||
|
||||
if (isHistoryRoot) {
|
||||
for (x = 0; x < viewElementsLength; x++) {
|
||||
viewElement = viewElements.eq(x);
|
||||
|
||||
if ($ionicViewSwitcher.isHistoryRoot(viewElement) && navViewAttr(viewElement) !== VIEW_STATUS_ACTIVE) {
|
||||
$ionicViewSwitcher.historyCursorAttr(viewElement, HISTORY_AFTER_ROOT);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
self.getViewElements = function() {
|
||||
return $element.children();
|
||||
};
|
||||
|
||||
|
||||
self.appendViewElement = function(viewEle, viewLocals) {
|
||||
// compile the entering element and get the link function
|
||||
var linkFn = $compile(viewEle);
|
||||
|
||||
$element.append(viewEle);
|
||||
|
||||
var viewScope = $scope.$new();
|
||||
|
||||
if (viewLocals && viewLocals.$$controller) {
|
||||
viewLocals.$scope = viewScope;
|
||||
var controller = $controller(viewLocals.$$controller, viewLocals);
|
||||
$element.children().data('$ngControllerController', controller);
|
||||
}
|
||||
|
||||
linkFn(viewScope);
|
||||
|
||||
return viewScope;
|
||||
};
|
||||
|
||||
|
||||
self.title = function(val) {
|
||||
var associatedNavBarCtrl = getAssociatedNavBarCtrl();
|
||||
associatedNavBarCtrl && associatedNavBarCtrl.title(val);
|
||||
|
||||
2
js/angular/controller/viewController.js
vendored
2
js/angular/controller/viewController.js
vendored
@@ -89,8 +89,6 @@ function($scope, $element, $attrs, $compile, $ionicViewSwitcher) {
|
||||
navViewCtrl.showBar(!val);
|
||||
}));
|
||||
}
|
||||
|
||||
$ionicViewSwitcher.setActiveView($element.parent());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user