Skip to content

Commit 3b612d2

Browse files
committed
fix(tabs): adjust the top of tabs each time the tab changes
1 parent db9f1a8 commit 3b612d2

File tree

2 files changed

+156
-2
lines changed

2 files changed

+156
-2
lines changed

src/components/content/content.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ export class Content extends Ion implements OnDestroy, OnInit {
144144
/** @internal */
145145
_tabsPlacement: string;
146146
/** @internal */
147+
_tTop: number;
148+
/** @internal */
147149
_inputPolling: boolean = false;
148150
/** @internal */
149151
_scroll: ScrollView;
@@ -555,6 +557,7 @@ export class Content extends Ion implements OnDestroy, OnInit {
555557
let cacheHeaderHeight = this._hdrHeight;
556558
let cacheFooterHeight = this._ftrHeight;
557559
let cacheTabsPlacement = this._tabsPlacement;
560+
let tabsTop = 0;
558561

559562
this.scrollWidth = 0;
560563
this.scrollHeight = 0;
@@ -565,6 +568,7 @@ export class Content extends Ion implements OnDestroy, OnInit {
565568
this._hdrHeight = 0;
566569
this._ftrHeight = 0;
567570
this._tabsPlacement = null;
571+
this._tTop = 0;
568572

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

631+
// Tabs top
632+
if (this._tabs && this._tabsPlacement === 'top') {
633+
this._tTop = this._hdrHeight;
634+
tabsTop = this._tabs._top;
635+
}
636+
627637
// Toolbar height
628638
this._cTop = this._hdrHeight;
629639
this._cBottom = this._ftrHeight;
@@ -650,6 +660,7 @@ export class Content extends Ion implements OnDestroy, OnInit {
650660
cacheHeaderHeight !== this._hdrHeight ||
651661
cacheFooterHeight !== this._ftrHeight ||
652662
cacheTabsPlacement !== this._tabsPlacement ||
663+
tabsTop !== this._tTop ||
653664
this._cTop !== this.contentTop ||
654665
this._cBottom !== this.contentBottom
655666
);
@@ -668,7 +679,7 @@ export class Content extends Ion implements OnDestroy, OnInit {
668679
*/
669680
writeDimensions() {
670681
if (!this._dirty) {
671-
console.debug('Skipping writeDimenstions');
682+
console.debug('Skipping writeDimensions');
672683
return;
673684
}
674685

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

745756
} else {
746757
assert(this._tabsPlacement === 'bottom', 'tabsPlacement should be bottom');
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import { Component, NgModule } from '@angular/core';
2+
import { IonicApp, IonicModule } from '../../../..';
3+
4+
//
5+
// Tab 1
6+
//
7+
@Component({
8+
template: `
9+
<ion-header>
10+
<ion-navbar>
11+
<ion-title>Speakers</ion-title>
12+
</ion-navbar>
13+
</ion-header>
14+
15+
<ion-content>
16+
<ion-list>
17+
<ion-list-header>
18+
Tab 1
19+
</ion-list-header>
20+
<ion-item *ngFor="let i of items">Item {{i}} {{i}} {{i}} {{i}}</ion-item>
21+
</ion-list>
22+
</ion-content>
23+
`
24+
})
25+
export class Tab1 {
26+
items: any[] = [];
27+
28+
constructor() {
29+
for (var i = 1; i <= 250; i++) {
30+
this.items.push(i);
31+
}
32+
}
33+
}
34+
35+
//
36+
// Tab 2
37+
//
38+
@Component({
39+
template: `
40+
<ion-header>
41+
<ion-navbar>
42+
<ion-title>Schedule</ion-title>
43+
</ion-navbar>
44+
<ion-toolbar>
45+
<ion-searchbar></ion-searchbar>
46+
</ion-toolbar>
47+
</ion-header>
48+
49+
<ion-content>
50+
<ion-list>
51+
<ion-item-sliding *ngFor="let session of sessions" #slidingItem>
52+
<ion-item>
53+
<h3>{{session.name}} {{session.name}} {{session.name}}</h3>
54+
<p>{{session.location}} {{session.location}} {{session.location}}</p>
55+
</ion-item>
56+
<ion-item-options>
57+
<button ion-button color="primary">Speaker<br>Info</button>
58+
<button ion-button color="secondary">Add to<br>Favorites</button>
59+
</ion-item-options>
60+
</ion-item-sliding>
61+
</ion-list>
62+
</ion-content>
63+
`
64+
})
65+
export class Tab2 {
66+
sessions: any[] = [];
67+
68+
constructor() {
69+
for (var i = 1; i <= 250; i++) {
70+
this.sessions.push({
71+
name: 'Name ' + i,
72+
location: 'Location: ' + i
73+
});
74+
}
75+
}
76+
}
77+
78+
//
79+
// Tab 3
80+
//
81+
@Component({
82+
template: `
83+
<ion-header>
84+
<ion-navbar>
85+
<ion-title>Map</ion-title>
86+
</ion-navbar>
87+
</ion-header>
88+
89+
<ion-content padding>
90+
<h2>Tab 3</h2>
91+
</ion-content>
92+
`
93+
})
94+
export class Tab3 {
95+
constructor() {}
96+
}
97+
98+
99+
@Component({
100+
template: `
101+
<ion-tabs>
102+
<ion-tab tabTitle="Speakers" tabIcon="person" [root]="root1"></ion-tab>
103+
<ion-tab tabTitle="Schedule" tabIcon="globe" [root]="root2"></ion-tab>
104+
<ion-tab tabTitle="Map" tabIcon="map" [root]="root3"></ion-tab>
105+
</ion-tabs>
106+
`
107+
})
108+
export class TabsPage {
109+
root1 = Tab1;
110+
root2 = Tab2;
111+
root3 = Tab3;
112+
}
113+
114+
@Component({
115+
template: `<ion-nav [root]="root"></ion-nav>`
116+
})
117+
export class E2EApp {
118+
root = TabsPage;
119+
}
120+
121+
@NgModule({
122+
declarations: [
123+
E2EApp,
124+
Tab1,
125+
Tab2,
126+
Tab3,
127+
TabsPage
128+
],
129+
imports: [
130+
IonicModule.forRoot(E2EApp, {
131+
tabsPlacement: 'top'
132+
})
133+
],
134+
bootstrap: [IonicApp],
135+
entryComponents: [
136+
E2EApp,
137+
Tab1,
138+
Tab2,
139+
Tab3,
140+
TabsPage
141+
]
142+
})
143+
export class AppModule {}

0 commit comments

Comments
 (0)