tabs navbar wip

This commit is contained in:
Adam Bradley
2015-06-08 17:16:22 -05:00
parent 9df956e865
commit a94186d970
4 changed files with 52 additions and 32 deletions

View File

@ -11,7 +11,7 @@ import {bind} from 'angular2/di';
import {NavController} from './nav-controller'; import {NavController} from './nav-controller';
import {NavItem, NavParams} from './nav-item'; import {NavItem, NavParams} from './nav-item';
import {Pane, NavBarSection} from './pane'; import {Pane, NavBarContainer} from './pane';
import {Transition} from '../../transitions/transition'; import {Transition} from '../../transitions/transition';
import {ClickBlock} from '../../util/click-block'; import {ClickBlock} from '../../util/click-block';
import * as util from 'ionic/util'; import * as util from 'ionic/util';
@ -80,7 +80,7 @@ export class NavBase {
// decide which sections should be added to this Pane, ie: nav bars, tab bars, etc. // decide which sections should be added to this Pane, ie: nav bars, tab bars, etc.
// add only the sections it needs // add only the sections it needs
if (itemStructure.navbar) { if (itemStructure.navbar) {
sectionsToAdd.push(NavBarSection); sectionsToAdd.push(NavBarContainer);
} }
// add the sections which this type of Pane requires // add the sections which this type of Pane requires
@ -476,6 +476,18 @@ export class NavBase {
return this.domElement; return this.domElement;
} }
navbarViewContainer(nbContainer) {
if (nbContainer) {
this._nbContainer = nbContainer;
}
if (this._nbContainer) {
return this._nbContainer;
}
if (this.parent) {
return this.parent.navbarViewContainer();
}
}
add(item) { add(item) {
item.id = this.id + '' + (++this.childIds); item.id = this.id + '' + (++this.childIds);
this.items.push(item); this.items.push(item);

View File

@ -31,28 +31,30 @@ export class NavItem {
} }
stage(callback) { stage(callback) {
// update if it's possible to go back from this nav item let nav = this.nav;
this.enableBack = this.nav && !!this.nav.getPrevious(this);
if (this.instance) { // update if it's possible to go back from this nav item
this.enableBack = nav && !!nav.getPrevious(this);
if (this.instance || !nav) {
// already compiled this view // already compiled this view
return callback(); return callback();
} }
// compile the Component // compile the Component
this.nav.compiler.compileInHost(this.ComponentClass).then(componentProtoViewRef => { nav.compiler.compileInHost(this.ComponentClass).then(componentProtoViewRef => {
// figure out the sturcture of this Component // figure out the sturcture of this Component
// does it have a navbar? Is it tabs? Should it not have a navbar or any toolbars? // does it have a navbar? Is it tabs? Should it not have a navbar or any toolbars?
let itemStructure = getProtoViewStructure(componentProtoViewRef); let itemStructure = getProtoViewStructure(componentProtoViewRef);
// get the appropriate Pane which this NavItem will fit into // get the appropriate Pane which this NavItem will fit into
this.nav.getPane(itemStructure, pane => { nav.getPane(itemStructure, pane => {
// create a new injector just for this NavItem // create a new injector just for this NavItem
let injector = this.nav.injector.resolveAndCreateChild([ let injector = nav.injector.resolveAndCreateChild([
bind(NavBase).toValue(this.nav), bind(NavBase).toValue(this.nav),
bind(NavController).toValue(this.nav.navCtrl), bind(NavController).toValue(nav.navCtrl),
bind(NavParams).toValue(new NavParams(this.params)), bind(NavParams).toValue(new NavParams(this.params)),
bind(NavItem).toValue(this) bind(NavItem).toValue(this)
]); ]);
@ -63,13 +65,15 @@ export class NavItem {
let newLocation = new ElementRef(hostViewRef, 0); let newLocation = new ElementRef(hostViewRef, 0);
this.setInstance( this.nav.loader._viewManager.getComponent(newLocation) ); this.setInstance( nav.loader._viewManager.getComponent(newLocation) );
this.setViewElement( hostViewRef._view.render._view.rootNodes[0] ); this.setViewElement( hostViewRef._view.render._view.rootNodes[0] );
this.disposals.push(() => { this.disposals.push(() => {
viewContainer.remove( viewContainer.indexOf(hostViewRef) ); viewContainer.remove( viewContainer.indexOf(hostViewRef) );
}); });
// get the view's context so when creating the navbar
// it uses the same context as the content
let context = { let context = {
boundElementIndex: 0, boundElementIndex: 0,
parentView: { parentView: {
@ -77,18 +81,26 @@ export class NavItem {
} }
}; };
// add only the sections it needs // get the item container's nav bar
let navbarViewContainer = pane.sections.navbar.viewContainerRef; let navbarViewContainer = nav.navbarViewContainer();
if (navbarViewContainer && itemStructure.navbar && this.protos.navbar) {
this.navbarView = navbarViewContainer.create(this.protos.navbar, -1, context, injector); // get the item's navbar protoview
let navbarProtoView = this.protos.navbar;
// add a navbar view if the pane has a navbar container, and the
// item's instance has a navbar protoview to go to inside of it
if (navbarViewContainer && navbarProtoView) {
this.navbarView = navbarViewContainer.create(navbarProtoView, -1, context, injector);
this.disposals.push(() => { this.disposals.push(() => {
navbarViewContainer.remove( navbarViewContainer.indexOf(this.navbarView) ); navbarViewContainer.remove( navbarViewContainer.indexOf(this.navbarView) );
}); });
} }
// this item has finished loading
this.loaded(); this.loaded();
// all done, fire the callback
callback(); callback();
}); });
@ -128,8 +140,9 @@ export class NavItem {
} }
navbarElement() { navbarElement() {
if (this.navbarView && this.navbarView._view) { let navbarView = this.navbarView;
return this.navbarView._view.render._view.rootNodes[0]; if (navbarView && navbarView._view) {
return navbarView._view.render._view.rootNodes[0];
} }
} }

View File

@ -5,6 +5,7 @@ import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
import {ElementRef} from 'angular2/src/core/compiler/element_ref'; import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {Nav} from './nav'; import {Nav} from './nav';
import {NavBase} from './nav-base';
import {SwipeHandle} from './swipe-handle'; import {SwipeHandle} from './swipe-handle';
@ -57,25 +58,18 @@ class PaneContentAnchor {
} }
}) })
@View({ @View({
template: ` template: `<template navbar-anchor></template>`,
<template section-anchor></template> directives: [NavBarAnchor]
`,
directives: [PaneSectionAnchor]
}) })
export class NavBarSection { export class NavBarContainer {}
constructor(@Parent() pane: Pane, viewContainerRef: ViewContainerRef, elementRef: ElementRef) {
this.pane = pane;
pane.addSection('navbar', this);
}
}
// Reference point of where the guts of the NavBar should go next to // Reference point of where individual view navbars will go next to
@Directive({ @Directive({
selector: 'template[section-anchor]' selector: 'template[navbar-anchor]'
}) })
class PaneSectionAnchor { class NavBarAnchor {
constructor(@Parent() navBarSection: NavBarSection, viewContainerRef: ViewContainerRef) { constructor(nav: NavBase, viewContainerRef: ViewContainerRef) {
navBarSection.viewContainerRef = viewContainerRef; nav.navbarViewContainer(viewContainerRef);
} }
} }

View File

@ -55,7 +55,7 @@ export class Tab extends NavBase {
this.sections = tabs.parent.panes['_n'].sections; this.sections = tabs.parent.panes['_n'].sections;
} }
this.item = new NavItem(this); this.item = new NavItem(tabs.parent);
this.item.setInstance(this); this.item.setInstance(this);
this.item.setViewElement(elementRef.domElement); this.item.setViewElement(elementRef.domElement);
tabs.addTab(this.item); tabs.addTab(this.item);
@ -85,6 +85,7 @@ export class Tab extends NavBase {
callback && callback(); callback && callback();
}); });
this._loaded = true; this._loaded = true;
} else { } else {
callback && callback(); callback && callback();
} }