Skip to content

Commit a8ceee4

Browse files
authored
fix(navigation): reduce urls to minimum set of fields
* wip * simple-nav, simple-tabs, simple-nav-then-tabs, simple-nested-navs all pass w00t w00t * updates * fix tests * update test
1 parent 97f9522 commit a8ceee4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1194
-387
lines changed

src/components/app/app.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,31 @@ export class App {
419419
}
420420
}
421421

422+
getNavByIdOrName(id: string) {
423+
const navs = Array.from(this._rootNavs.values());
424+
for (const navContainer of navs) {
425+
const match = getNavByIdOrName(navContainer, id);
426+
if (match) {
427+
return match;
428+
}
429+
}
430+
return null;
431+
}
432+
422433
}
423434

435+
export function getNavByIdOrName(nav: NavigationContainer, id: string): NavigationContainer {
436+
if (nav.id === id || nav.name === id) {
437+
return nav;
438+
}
439+
for (const child of nav.getAllChildNavs()) {
440+
const tmp = getNavByIdOrName(child, id);
441+
if (tmp) {
442+
return tmp;
443+
}
444+
}
445+
return null;
446+
}
424447

425448
function getPoppableNav(nav: NavControllerBase): NavControllerBase {
426449
if (!nav) {
@@ -455,6 +478,7 @@ export function findTopNavs(nav: NavigationContainer): NavigationContainer[] {
455478
return containers;
456479
}
457480

481+
458482
const SKIP_BLURRING = ['INPUT', 'TEXTAREA', 'ION-INPUT', 'ION-TEXTAREA'];
459483
const ACTIVE_SCROLLING_TIME = 100;
460484
const CLICK_BLOCK_BUFFER_IN_MILLIS = 64;

src/components/app/test/app.spec.ts

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,149 @@ describe('App', () => {
767767
});
768768
});
769769

770+
describe('getNavByIdOrName', () => {
771+
it('should return a basic root nav', () => {
772+
const nav = mockNavController();
773+
app.registerRootNav(nav);
774+
const result = app.getNavByIdOrName(nav.id);
775+
expect(result).toEqual(nav);
776+
});
777+
778+
it('should return a child nav', () => {
779+
const rootNav = mockNavController();
780+
app.registerRootNav(rootNav);
781+
782+
const childNav = mockNavController();
783+
childNav.parent = rootNav;
784+
rootNav.registerChildNav(childNav);
785+
786+
const childChildNav = mockNavController();
787+
childChildNav.parent = childNav;
788+
childNav.registerChildNav(childChildNav);
789+
790+
791+
const expectedChildNav = app.getNavByIdOrName(childNav.id);
792+
expect(expectedChildNav).toEqual(childNav);
793+
794+
const expectedChildChildNav = app.getNavByIdOrName(childChildNav.id);
795+
expect(expectedChildChildNav).toEqual(childChildNav);
796+
});
797+
798+
it('should return a child nav when there is a tabs in there', () => {
799+
const rootNav = mockNavController();
800+
app.registerRootNav(rootNav);
801+
802+
const tabs = mockTabs();
803+
tabs.parent = rootNav;
804+
rootNav.registerChildNav(tabs);
805+
806+
const tab1 = mockTab(tabs);
807+
const tab2 = mockTab(tabs);
808+
const tab3 = mockTab(tabs);
809+
810+
const tabChildNav = mockNavController();
811+
tabChildNav.parent = tab2;
812+
tab2.registerChildNav(tabChildNav);
813+
814+
const tabChildChildNav = mockNavController();
815+
tabChildChildNav.parent = tabChildNav;
816+
tabChildNav.registerChildNav(tabChildChildNav);
817+
818+
const expectedTab1 = app.getNavByIdOrName(tab1.id);
819+
expect(expectedTab1).toEqual(tab1);
820+
821+
const expectedTab2 = app.getNavByIdOrName(tab2.id);
822+
expect(expectedTab2).toEqual(tab2);
823+
824+
const expectedTab3 = app.getNavByIdOrName(tab3.id);
825+
expect(expectedTab3).toEqual(tab3);
826+
827+
const expectedTabChildNav = app.getNavByIdOrName(tabChildNav.id);
828+
expect(expectedTabChildNav).toEqual(tabChildNav);
829+
830+
const expectedTabChildChildNav = app.getNavByIdOrName(tabChildChildNav.id);
831+
expect(expectedTabChildChildNav).toEqual(tabChildChildNav);
832+
});
833+
834+
it('should return a basic root nav when the are multiple root navs', () => {
835+
const rootNavOne = mockNavController();
836+
const rootNavTwo = mockNavController();
837+
const rootNavThree = mockNavController();
838+
app.registerRootNav(rootNavOne);
839+
app.registerRootNav(rootNavTwo);
840+
app.registerRootNav(rootNavThree);
841+
842+
const expectedRootNavOne = app.getNavByIdOrName(rootNavOne.id);
843+
expect(expectedRootNavOne).toEqual(rootNavOne);
844+
845+
const expectedRootNavTwo = app.getNavByIdOrName(rootNavTwo.id);
846+
expect(expectedRootNavTwo).toEqual(rootNavTwo);
847+
848+
const expectedRootNavThree = app.getNavByIdOrName(rootNavThree.id);
849+
expect(expectedRootNavThree).toEqual(rootNavThree);
850+
});
851+
852+
it('should return a proper navs when there are multiple root navs with nested navs', () => {
853+
const rootNavOne = mockNavController();
854+
const rootNavTwo = mockNavController();
855+
const rootNavThree = mockNavController();
856+
app.registerRootNav(rootNavOne);
857+
app.registerRootNav(rootNavTwo);
858+
app.registerRootNav(rootNavThree);
859+
860+
const childNavOne = mockNavController();
861+
childNavOne.parent = rootNavOne;
862+
rootNavOne.registerChildNav(childNavOne);
863+
864+
const childChildNavOne = mockNavController();
865+
childChildNavOne.parent = childNavOne;
866+
childNavOne.registerChildNav(childChildNavOne);
867+
868+
const childNavTwo = mockNavController();
869+
childNavOne.parent = rootNavTwo;
870+
rootNavTwo.registerChildNav(childNavTwo);
871+
872+
const childChildNavTwo = mockNavController();
873+
childChildNavTwo.parent = childNavTwo;
874+
childNavTwo.registerChildNav(childChildNavTwo);
875+
876+
const childNavThree = mockNavController();
877+
childNavThree.parent = rootNavThree;
878+
rootNavThree.registerChildNav(childNavThree);
879+
880+
const childChildNavThree = mockNavController();
881+
childChildNavThree.parent = childNavThree;
882+
childNavThree.registerChildNav(childChildNavThree);
883+
884+
const expectedRootNavOne = app.getNavByIdOrName(rootNavOne.id);
885+
expect(expectedRootNavOne).toEqual(rootNavOne);
886+
887+
const expectedChildNavOne = app.getNavByIdOrName(childNavOne.id);
888+
expect(expectedChildNavOne).toEqual(childNavOne);
889+
890+
const expectedChildChildNavOne = app.getNavByIdOrName(childChildNavOne.id);
891+
expect(expectedChildChildNavOne).toEqual(childChildNavOne);
892+
893+
const expectedRootNavTwo = app.getNavByIdOrName(rootNavTwo.id);
894+
expect(expectedRootNavTwo).toEqual(rootNavTwo);
895+
896+
const expectedChildNavTwo = app.getNavByIdOrName(childNavTwo.id);
897+
expect(expectedChildNavTwo).toEqual(childNavTwo);
898+
899+
const expectedChildChildNavTwo = app.getNavByIdOrName(childChildNavTwo.id);
900+
expect(expectedChildChildNavTwo).toEqual(childChildNavTwo);
901+
902+
const expectedRootNavThree = app.getNavByIdOrName(rootNavThree.id);
903+
expect(expectedRootNavThree).toEqual(rootNavThree);
904+
905+
const expectedChildNavThree = app.getNavByIdOrName(childNavThree.id);
906+
expect(expectedChildNavThree).toEqual(childNavThree);
907+
908+
const expectedChildChildNavThree = app.getNavByIdOrName(childChildNavThree.id);
909+
expect(expectedChildChildNavThree).toEqual(childChildNavThree);
910+
});
911+
});
912+
770913
let app: App;
771914
let config: Config;
772915
let plt: MockPlatform;

src/components/nav/test/advanced-nav-then-tabs/app/app.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Component } from '@angular/core';
33
@Component({
44
template: `
55
<ion-split-pane>
6-
<ion-nav [root]="rootOne"></ion-nav>
7-
<ion-nav [root]="rootTwo" main #content></ion-nav>
6+
<ion-nav [root]="rootOne" name="left"></ion-nav>
7+
<ion-nav [root]="rootTwo" main #content name="right"></ion-nav>
88
99
</ion-split-pane>
1010
`

src/components/nav/test/advanced-tabs/pages/tabs-one/tab-one-page-three/tab-one-page-three.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { IonicPage, NavController, NavParams } from '../../../../../../..';
1919
<div>
2020
Name: {{paramTwo}}
2121
</div>
22-
<button ion-button (click)="goToNext()">Next</button>
2322
</ion-content>
2423
`
2524
})

src/components/nav/test/advanced-tabs/pages/tabs-one/tab-two-page-three/tab-two-page-three.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import { IonicPage, NavController, NavParams } from '../../../../../../..';
1414
<ion-content>
1515
Tabs 1 Tab 2 Page 3
1616
<div>
17-
Param One: {{userId}}
17+
Param One: {{paramOne}}
1818
</div>
1919
<div>
20-
Param Two: {{name}}
20+
Param Two: {{paramTwo}}
2121
</div>
2222
</ion-content>
2323
`
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
template: `<ion-nav [root]="root"></ion-nav>`
5+
})
6+
export class AppComponent {
7+
root = 'LoginPage';
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
import { IonicApp, IonicModule } from '../../../../..';
4+
5+
import { AppComponent } from './app.component';
6+
7+
@NgModule({
8+
declarations: [
9+
AppComponent
10+
],
11+
imports: [
12+
BrowserModule,
13+
IonicModule.forRoot(AppComponent, { swipeBackEnabled: true, preloadModules: true }),
14+
],
15+
bootstrap: [IonicApp]
16+
})
17+
export class AppModule {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2+
3+
import { AppModule } from './app.module';
4+
5+
platformBrowserDynamic().bootstrapModule(AppModule);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NgModule } from '@angular/core';
2+
import { IonicPageModule } from '../../../../../..';
3+
import { LandingPage } from './landing-page';
4+
5+
@NgModule({
6+
imports: [
7+
IonicPageModule.forChild(LandingPage)
8+
],
9+
declarations: [
10+
LandingPage
11+
]
12+
})
13+
export class LandingPageModule { }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Component } from '@angular/core';
2+
import { IonicPage, NavController, } from '../../../../../..';
3+
4+
@IonicPage()
5+
@Component({
6+
template: `
7+
<ion-header>
8+
<ion-navbar>
9+
<ion-title>My Super Cool, multi-pane App</ion-title>
10+
</ion-navbar>
11+
</ion-header>
12+
<ion-content>
13+
<ion-grid>
14+
<ion-row>
15+
<ion-col style="height: 1000px; background-color: blue">
16+
<ion-nav root="FirstPage" name="left"></ion-nav>
17+
</ion-col>
18+
<ion-col style="height: 1000px; background-color: green">
19+
<ion-nav root="FourthPage" name="right"></ion-nav>
20+
</ion-col>
21+
</ion-row>
22+
</ion-grid>
23+
</ion-content>
24+
`
25+
})
26+
export class LandingPage {
27+
constructor(public nav: NavController) {
28+
}
29+
30+
}

0 commit comments

Comments
 (0)