the tab who loved me

This commit is contained in:
Adam Bradley
2015-06-05 09:17:45 -05:00
parent 5b30901f39
commit fd0fde4890
5 changed files with 69 additions and 29 deletions

View File

@ -139,7 +139,7 @@ gulp.task('bundle.deps', function() {
return builder.loadConfig('config.js').then(function(){ return builder.loadConfig('config.js').then(function(){
// add ionic and angular2 build paths, since config.js is loaded at runtime from // add ionic and angular2 build paths, since config.js is loaded at runtime from
// tests we don't want to put them there // tests we don't want to put them there
builder.config({ builder.config({
baseURL: 'file:' + process.cwd(), baseURL: 'file:' + process.cwd(),
paths : { paths : {
"ionic/*": "dist/js/es6/ionic/*.js", "ionic/*": "dist/js/es6/ionic/*.js",
@ -157,7 +157,7 @@ gulp.task('examples', function() {
var buildTest = lazypipe() var buildTest = lazypipe()
.pipe(traceur, traceurOptions) .pipe(traceur, traceurOptions)
//.pipe(babel, babelOptions) Let SystemJS load index.js at runtime, saves build time //.pipe(babel, babelOptions) Let SystemJS load index.js at runtime, saves build time
// Get each test folder with gulp.src // Get each test folder with gulp.src
return gulp.src('ionic/components/*/test/*/**/*') return gulp.src('ionic/components/*/test/*/**/*')
.pipe(cache('examples', { optimizeMemory: true })) .pipe(cache('examples', { optimizeMemory: true }))
@ -169,7 +169,7 @@ gulp.task('examples', function() {
.pipe(gulp.dest('dist/examples/')) .pipe(gulp.dest('dist/examples/'))
function createIndexHTML() { function createIndexHTML() {
var indexContents = _.template( var indexContents = _.template(
fs.readFileSync('scripts/e2e/ionic.template.html') fs.readFileSync('scripts/e2e/ionic.template.html')
)({ )({
buildConfig: buildConfig buildConfig: buildConfig
@ -400,6 +400,10 @@ function doubleCheckDistFiles() {
if (!fs.existsSync('../angular-ionic/dist/js/dev/es5/fonts')) { if (!fs.existsSync('../angular-ionic/dist/js/dev/es5/fonts')) {
gulp.start('old.fonts'); gulp.start('old.fonts');
} }
if (!fs.existsSync('../angular-ionic/dist/js/dev/es5/polyfills')) {
gulp.start('old.polyfills');
}
} }
gulp.task('old.clean', function(done) { gulp.task('old.clean', function(done) {

View File

@ -27,8 +27,6 @@ export class NavBase {
injector: Injector injector: Injector
) { ) {
console.log('NavBase, parent NavBase:', parentNavBase);
this.compiler = compiler; this.compiler = compiler;
this.elementRef = elementRef; this.elementRef = elementRef;
this.domElement = elementRef.domElement; this.domElement = elementRef.domElement;
@ -45,11 +43,8 @@ export class NavBase {
this.childIds = -1; this.childIds = -1;
} }
initial(initial) { initial(ComponentClass) {
console.log('initial') this.push(ComponentClass);
if (initial) {
this.push(initial);
}
} }
setPaneAnchor(elementRef) { setPaneAnchor(elementRef) {
@ -198,10 +193,12 @@ export class NavBase {
} }
select(enteringItem, opts = {}) { select(enteringItem, opts = {}) {
if (!enteringItem || this.isTransitioning()) { if (!enteringItem || !enteringItem.instance || this.isTransitioning()) {
return; return;
} }
enteringItem.instance.loadInitial();
opts.animation = 'none'; opts.animation = 'none';
let leavingItem = this.getActive() || new NavItem(); let leavingItem = this.getActive() || new NavItem();
@ -442,15 +439,24 @@ export class NavBase {
return null; return null;
} }
findByInstance(instance) { getByInstance(instance) {
for (let i = 0, ii = this.items.length; i < ii; i++) { if (instance) {
if (this.items[i].instance === instance) { for (let i = 0, ii = this.items.length; i < ii; i++) {
return this.items[i]; if (this.items[i].instance === instance) {
return this.items[i];
}
} }
} }
return null; return null;
} }
getByIndex(index) {
if (index < this.items.length && index > -1) {
return this.items[index];
}
return null;
}
getPrevious(item) { getPrevious(item) {
if (item) { if (item) {
return this.items[ this.items.indexOf(item) - 1 ]; return this.items[ this.items.indexOf(item) - 1 ];
@ -493,10 +499,6 @@ export class NavBase {
return this.items.length; return this.items.length;
} }
isActive(item) {
return (item && item.state === ACTIVE_STATE);
}
clear() { clear() {
let pops = []; let pops = [];
for (let item of this.items) { for (let item of this.items) {
@ -517,6 +519,14 @@ export class NavBase {
return instances return instances
} }
isActive(item) {
return (item && item.state === ACTIVE_STATE);
}
isStagedEntering(item) {
return (item && item.state === STAGED_ENTERING_STATE);
}
width() { width() {
return this.domElement.offsetWidth; return this.domElement.offsetWidth;
} }

View File

@ -63,15 +63,14 @@ export class NavItem {
let hostViewRef = viewContainer.create(componentProtoViewRef, -1, null, injector); let hostViewRef = viewContainer.create(componentProtoViewRef, -1, null, injector);
let newLocation = new ElementRef(hostViewRef, 0); let newLocation = new ElementRef(hostViewRef, 0);
this.instance = this.navBase.loader._viewManager.getComponent(newLocation);
this.setInstance( this.navBase.loader._viewManager.getComponent(newLocation) );
this.setViewElement( hostViewRef._view.render._view.rootNodes[0] );
this.disposals.push(() => { this.disposals.push(() => {
viewContainer.remove( viewContainer.indexOf(hostViewRef) ); viewContainer.remove( viewContainer.indexOf(hostViewRef) );
}); });
this.viewEle = hostViewRef._view.render._view.rootNodes[0];
this.viewEle.classList.add('nav-item');
let context = { let context = {
boundElementIndex: 0, boundElementIndex: 0,
parentView: { parentView: {
@ -97,6 +96,15 @@ export class NavItem {
}); });
} }
setInstance(instance) {
this.instance = instance;
}
setViewElement(viewEle) {
this.viewEle = viewEle;
viewEle && viewEle.classList.add('nav-item');
}
cache() { cache() {
this.didCache(); this.didCache();
} }

View File

@ -1,5 +1,5 @@
import {Parent} from 'angular2/src/core/annotations_impl/visibility'; import {Parent} from 'angular2/src/core/annotations_impl/visibility';
import {Directive, Component} from 'angular2/src/core/annotations_impl/annotations'; import {Directive, Component, onInit} from 'angular2/src/core/annotations_impl/annotations';
import {Optional} from 'angular2/src/di/annotations_impl' import {Optional} from 'angular2/src/di/annotations_impl'
import {View} from 'angular2/src/core/annotations_impl/view'; import {View} from 'angular2/src/core/annotations_impl/view';
import {ElementRef} from 'angular2/src/core/compiler/element_ref'; import {ElementRef} from 'angular2/src/core/compiler/element_ref';
@ -55,7 +55,8 @@ export class Tab {
this.parentNavBase = parentNavBase; this.parentNavBase = parentNavBase;
this.item = new NavItem(parentNavBase); this.item = new NavItem(parentNavBase);
this.item.instance = this this.item.setInstance(this);
this.item.setViewElement(elementRef.domElement);
tabs.add(this.item); tabs.add(this.item);
this.panelId = 'tab-panel-' + this.item.id; this.panelId = 'tab-panel-' + this.item.id;
@ -70,8 +71,19 @@ export class Tab {
this.domElement = elementRef.domElement; this.domElement = elementRef.domElement;
this.config = Nav.config.invoke(this); this.config = Nav.config.invoke(this);
}
console.log('Tab constructor', this.item.id, ' parentNavBase:', parentNavBase); onInit() {
if ( this.parentNavBase.isActive(this.item) || this.parentNavBase.isStagedEntering(this.item) ) {
this.loadInitial();
}
}
loadInitial() {
if (this.initial && !this._loaded) {
this.navBase.initial(this.initial);
this._loaded = true;
}
} }
get isSelected() { get isSelected() {

View File

@ -59,7 +59,7 @@ export class Tabs {
this.navBase.add(tabItem); this.navBase.add(tabItem);
if (this.navBase.length() === 1) { if (this.navBase.length() === 1) {
this.select(tabItem.instance); this.select(0);
} }
} }
@ -67,8 +67,14 @@ export class Tabs {
return this.navBase.instances(); return this.navBase.instances();
} }
select(tabInstance) { select(tab) {
this.navBase.select( this.navBase.findByInstance(tabInstance) ); let item = null;
if (typeof tab === 'number') {
item = this.navBase.getByIndex(tab);
} else {
item = this.navBase.getByInstance(tab)
}
this.navBase.select(item);
} }
} }