Skip to content

Commit

Permalink
fix(tabs): adjust the top of tabs each time the tab changes
Browse files Browse the repository at this point in the history
  • Loading branch information
brandyscarney committed Dec 6, 2016
1 parent db9f1a8 commit 3b612d2
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export class Content extends Ion implements OnDestroy, OnInit {
/** @internal */
_tabsPlacement: string;
/** @internal */
_tTop: number;
/** @internal */
_inputPolling: boolean = false;
/** @internal */
_scroll: ScrollView;
Expand Down Expand Up @@ -555,6 +557,7 @@ export class Content extends Ion implements OnDestroy, OnInit {
let cacheHeaderHeight = this._hdrHeight;
let cacheFooterHeight = this._ftrHeight;
let cacheTabsPlacement = this._tabsPlacement;
let tabsTop = 0;

this.scrollWidth = 0;
this.scrollHeight = 0;
Expand All @@ -565,6 +568,7 @@ export class Content extends Ion implements OnDestroy, OnInit {
this._hdrHeight = 0;
this._ftrHeight = 0;
this._tabsPlacement = null;
this._tTop = 0;

let ele: HTMLElement = this._elementRef.nativeElement;
if (!ele) {
Expand Down Expand Up @@ -624,6 +628,12 @@ export class Content extends Ion implements OnDestroy, OnInit {
ele = ele.parentElement;
}

// Tabs top
if (this._tabs && this._tabsPlacement === 'top') {
this._tTop = this._hdrHeight;
tabsTop = this._tabs._top;
}

// Toolbar height
this._cTop = this._hdrHeight;
this._cBottom = this._ftrHeight;
Expand All @@ -650,6 +660,7 @@ export class Content extends Ion implements OnDestroy, OnInit {
cacheHeaderHeight !== this._hdrHeight ||
cacheFooterHeight !== this._ftrHeight ||
cacheTabsPlacement !== this._tabsPlacement ||
tabsTop !== this._tTop ||
this._cTop !== this.contentTop ||
this._cBottom !== this.contentBottom
);
Expand All @@ -668,7 +679,7 @@ export class Content extends Ion implements OnDestroy, OnInit {
*/
writeDimensions() {
if (!this._dirty) {
console.debug('Skipping writeDimenstions');
console.debug('Skipping writeDimensions');
return;
}

Expand Down Expand Up @@ -740,7 +751,7 @@ export class Content extends Ion implements OnDestroy, OnInit {
// set the position of the tabbar
if (this._tabsPlacement === 'top') {
// ******** DOM WRITE ****************
this._tabs.setTabbarPosition(this._hdrHeight, -1);
this._tabs.setTabbarPosition(this._tTop, -1);

} else {
assert(this._tabsPlacement === 'bottom', 'tabsPlacement should be bottom');
Expand Down
143 changes: 143 additions & 0 deletions src/components/tabs/test/top/app-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { Component, NgModule } from '@angular/core';
import { IonicApp, IonicModule } from '../../../..';

//
// Tab 1
//
@Component({
template: `
<ion-header>
<ion-navbar>
<ion-title>Speakers</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list>
<ion-list-header>
Tab 1
</ion-list-header>
<ion-item *ngFor="let i of items">Item {{i}} {{i}} {{i}} {{i}}</ion-item>
</ion-list>
</ion-content>
`
})
export class Tab1 {
items: any[] = [];

constructor() {
for (var i = 1; i <= 250; i++) {
this.items.push(i);
}
}
}

//
// Tab 2
//
@Component({
template: `
<ion-header>
<ion-navbar>
<ion-title>Schedule</ion-title>
</ion-navbar>
<ion-toolbar>
<ion-searchbar></ion-searchbar>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item-sliding *ngFor="let session of sessions" #slidingItem>
<ion-item>
<h3>{{session.name}} {{session.name}} {{session.name}}</h3>
<p>{{session.location}} {{session.location}} {{session.location}}</p>
</ion-item>
<ion-item-options>
<button ion-button color="primary">Speaker<br>Info</button>
<button ion-button color="secondary">Add to<br>Favorites</button>
</ion-item-options>
</ion-item-sliding>
</ion-list>
</ion-content>
`
})
export class Tab2 {
sessions: any[] = [];

constructor() {
for (var i = 1; i <= 250; i++) {
this.sessions.push({
name: 'Name ' + i,
location: 'Location: ' + i
});
}
}
}

//
// Tab 3
//
@Component({
template: `
<ion-header>
<ion-navbar>
<ion-title>Map</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<h2>Tab 3</h2>
</ion-content>
`
})
export class Tab3 {
constructor() {}
}


@Component({
template: `
<ion-tabs>
<ion-tab tabTitle="Speakers" tabIcon="person" [root]="root1"></ion-tab>
<ion-tab tabTitle="Schedule" tabIcon="globe" [root]="root2"></ion-tab>
<ion-tab tabTitle="Map" tabIcon="map" [root]="root3"></ion-tab>
</ion-tabs>
`
})
export class TabsPage {
root1 = Tab1;
root2 = Tab2;
root3 = Tab3;
}

@Component({
template: `<ion-nav [root]="root"></ion-nav>`
})
export class E2EApp {
root = TabsPage;
}

@NgModule({
declarations: [
E2EApp,
Tab1,
Tab2,
Tab3,
TabsPage
],
imports: [
IonicModule.forRoot(E2EApp, {
tabsPlacement: 'top'
})
],
bootstrap: [IonicApp],
entryComponents: [
E2EApp,
Tab1,
Tab2,
Tab3,
TabsPage
]
})
export class AppModule {}

0 comments on commit 3b612d2

Please sign in to comment.