mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(): rename ViewController/ViewItem
Rename ViewController to NavController, ViewItem to ViewController
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {Directive, Component, View, Host, ElementRef, forwardRef, Injector, NgZone} from 'angular2/angular2';
|
||||
|
||||
import {ViewController} from '../view/view-controller';
|
||||
import {ViewItem} from '../view/view-item';
|
||||
import {NavController} from '../nav/nav-controller';
|
||||
import {ViewController} from '../nav/view-controller';
|
||||
import {Tabs} from './tabs';
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import {Tabs} from './tabs';
|
||||
template: '<template pane-anchor></template><ng-content></ng-content>',
|
||||
directives: [forwardRef(() => TabPaneAnchor)]
|
||||
})
|
||||
export class Tab extends ViewController {
|
||||
export class Tab extends NavController {
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -51,32 +51,32 @@ export class Tab extends ViewController {
|
||||
zone: NgZone
|
||||
) {
|
||||
// A Tab is both a container of many views, and is a view itself.
|
||||
// A Tab is one ViewItem within it's Host Tabs (which extends ViewController)
|
||||
// A Tab is a ViewController for its child ViewItems
|
||||
// A Tab is one ViewController within it's Host Tabs (which extends NavController)
|
||||
// A Tab is a NavController for its child ViewControllers
|
||||
super(tabs, injector, elementRef, zone);
|
||||
this.tabs = tabs;
|
||||
|
||||
this.childNavbar(true);
|
||||
|
||||
let item = this.item = new ViewItem(tabs.Host);
|
||||
item.setInstance(this);
|
||||
item.viewElementRef(elementRef);
|
||||
let viewCtrl = this.viewCtrl = new ViewController(tabs.Host);
|
||||
viewCtrl.setInstance(this);
|
||||
viewCtrl.viewElementRef(elementRef);
|
||||
tabs.addTab(this);
|
||||
|
||||
this.navbarView = item.navbarView = () => {
|
||||
let activeItem = this.getActive();
|
||||
return activeItem && activeItem.navbarView();
|
||||
this.navbarView = viewCtrl.navbarView = () => {
|
||||
let activeView = this.getActive();
|
||||
return activeView && activeView.navbarView();
|
||||
};
|
||||
|
||||
item.enableBack = () => {
|
||||
// override ViewItem's enableBack(), should use the
|
||||
viewCtrl.enableBack = () => {
|
||||
// override ViewController's enableBack(), should use the
|
||||
// active child nav item's enableBack() instead
|
||||
let activeItem = this.getActive();
|
||||
return (activeItem && activeItem.enableBack());
|
||||
let activeView = this.getActive();
|
||||
return (activeView && activeView.enableBack());
|
||||
};
|
||||
|
||||
this.panelId = 'tab-panel-' + item.id;
|
||||
this.labeledBy = 'tab-button-' + item.id;
|
||||
this.panelId = 'tab-panel-' + viewCtrl.id;
|
||||
this.labeledBy = 'tab-button-' + viewCtrl.id;
|
||||
}
|
||||
|
||||
onInit() {
|
||||
@@ -118,11 +118,11 @@ export class Tab extends ViewController {
|
||||
}
|
||||
|
||||
get isSelected() {
|
||||
return this.tabs.isActive(this.item);
|
||||
return this.tabs.isActive(this.viewCtrl);
|
||||
}
|
||||
|
||||
get isNotSelected() {
|
||||
return !this.tabs.isActive(this.item);
|
||||
return !this.tabs.isActive(this.viewCtrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {Component, Directive, View, Injector, NgFor, ElementRef, Optional, Host, forwardRef, NgZone} from 'angular2/angular2';
|
||||
|
||||
import {IonicApp} from '../app/app';
|
||||
import {ViewController} from '../view/view-controller';
|
||||
import {ViewItem} from '../view/view-item';
|
||||
import {NavController} from '../nav/nav-controller';
|
||||
import {ViewController} from '../nav/view-controller';
|
||||
import {Icon} from '../icon/icon';
|
||||
import {IonicComponent, IonicView} from '../../config/decorators';
|
||||
|
||||
@@ -50,41 +50,41 @@ import {IonicComponent, IonicView} from '../../config/decorators';
|
||||
'</section>',
|
||||
directives: [forwardRef(() => TabButton)]
|
||||
})
|
||||
export class Tabs extends ViewController {
|
||||
export class Tabs extends NavController {
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
constructor(
|
||||
@Optional() hostViewCtrl: ViewController,
|
||||
@Optional() viewItem: ViewItem,
|
||||
@Optional() hostNavCtrl: NavController,
|
||||
@Optional() viewCtrl: ViewController,
|
||||
app: IonicApp,
|
||||
injector: Injector,
|
||||
elementRef: ElementRef,
|
||||
zone: NgZone
|
||||
) {
|
||||
super(hostViewCtrl, injector, elementRef, zone);
|
||||
super(hostNavCtrl, injector, elementRef, zone);
|
||||
this.app = app;
|
||||
|
||||
// Tabs may also be an actual ViewItem which was navigated to
|
||||
// if Tabs is static and not navigated to within a ViewController
|
||||
// then skip this and don't treat it as it's own ViewItem
|
||||
if (viewItem) {
|
||||
this.item = viewItem;
|
||||
// Tabs may also be an actual ViewController which was navigated to
|
||||
// if Tabs is static and not navigated to within a NavController
|
||||
// then skip this and don't treat it as it's own ViewController
|
||||
if (viewCtrl) {
|
||||
this.viewCtrl = viewCtrl;
|
||||
|
||||
// special overrides for the Tabs ViewItem
|
||||
// the Tabs ViewItem does not have it's own navbar
|
||||
// special overrides for the Tabs ViewController
|
||||
// the Tabs ViewController does not have it's own navbar
|
||||
// so find the navbar it should use within it's active Tab
|
||||
viewItem.navbarView = () => {
|
||||
viewCtrl.navbarView = () => {
|
||||
let activeTab = this.getActive();
|
||||
if (activeTab && activeTab.instance) {
|
||||
return activeTab.instance.navbarView();
|
||||
}
|
||||
};
|
||||
|
||||
// a Tabs ViewItem should not have a back button
|
||||
// a Tabs ViewController should not have a back button
|
||||
// enableBack back button will later be determined
|
||||
// by the active ViewItem that has a navbar
|
||||
viewItem.enableBack = () => {
|
||||
// by the active ViewController that has a navbar
|
||||
ViewController.enableBack = () => {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
@@ -96,14 +96,14 @@ export class Tabs extends ViewController {
|
||||
* @param {Tab} tab TODO
|
||||
*/
|
||||
addTab(tab) {
|
||||
// tab.item refers to the ViewItem of the individual Tab being added to Tabs (ViewController)
|
||||
// this.item refers to the ViewItem instsance on Tabs
|
||||
this.add(tab.item);
|
||||
// tab.viewCtrl refers to the ViewController of the individual Tab being added to Tabs (NavController)
|
||||
// this.viewCtrl refers to the ViewController instsance on Tabs
|
||||
this.add(tab.viewCtrl);
|
||||
|
||||
if (this.length() === 1) {
|
||||
// this was the first tab added, queue this one to be loaded and selected
|
||||
let promise = tab.queueInitial();
|
||||
this.item && this.item.addPromise(promise);
|
||||
this.viewCtrl && this.viewCtrl.addPromise(promise);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,28 +113,28 @@ export class Tabs extends ViewController {
|
||||
* @returns {TODO} TODO
|
||||
*/
|
||||
select(tab) {
|
||||
let enteringItem = null;
|
||||
let enteringView = null;
|
||||
if (typeof tab === 'number') {
|
||||
enteringItem = this.getByIndex(tab);
|
||||
enteringView = this.getByIndex(tab);
|
||||
} else {
|
||||
enteringItem = this.getByInstance(tab)
|
||||
enteringView = this.getByInstance(tab)
|
||||
}
|
||||
|
||||
if (!enteringItem || !enteringItem.instance || !this.app.isEnabled()) {
|
||||
if (!enteringView || !enteringView.instance || !this.app.isEnabled()) {
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
enteringItem.instance.load(() => {
|
||||
enteringView.instance.load(() => {
|
||||
let opts = {
|
||||
animate: false
|
||||
};
|
||||
|
||||
let leavingItem = this.getActive() || new ViewItem();
|
||||
leavingItem.shouldDestroy = false;
|
||||
leavingItem.shouldCache = true;
|
||||
let leavingView = this.getActive() || new ViewController();
|
||||
leavingView.shouldDestroy = false;
|
||||
leavingView.shouldCache = true;
|
||||
|
||||
this.transition(enteringItem, leavingItem, opts, () => {
|
||||
this.transition(enteringView, leavingView, opts, () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@@ -171,7 +171,7 @@ class TabButton {
|
||||
}
|
||||
|
||||
onInit() {
|
||||
let id = this.tab.item.id;
|
||||
let id = this.tab.viewCtrl.id;
|
||||
this.btnId = 'tab-button-' + id;
|
||||
this.panelId = 'tab-panel-' + id;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user