Skip to content

Commit fdee488

Browse files
committed
chore: add demo case for tabbed outlet routing
1 parent 92749c9 commit fdee488

File tree

11 files changed

+168
-10869
lines changed

11 files changed

+168
-10869
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/node_modules
1010
/packages/*/node_modules
1111
package-lock.json
12+
.npmrc
1213

1314
# IDEs and editors
1415
/.idea

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,32 @@ For usage with NativeScript for Angular 12+ projects.
55
Clean and setup workspace:
66

77
```
8-
yarn clean.all
8+
npm run clean.all
99
```
1010

1111
## Build packages:
1212

1313
```
14-
yarn build
14+
npm run build
1515
```
1616

1717
## Run demo:
1818

1919
```
20-
nx run nativescript-demo-ng:ios
20+
npm run demo:ios
21+
// or...
22+
npm run demo:android
23+
```
24+
25+
## Clean/Reset demo dependencies
26+
27+
```
28+
npm run demo:clean
2129
```
2230

2331
## Unit tests for iOS and Android:
2432

2533
```
26-
yarn test.android
27-
yarn test.ios
34+
npm run test:android
35+
npm run test:ios
2836
```

apps/nativescript-demo-ng/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
},
88
"dependencies": {
99
"@nativescript/angular": "file:../../packages/angular",
10-
"@nativescript/core": "file:../../node_modules/@nativescript/core"
10+
"@nativescript/core": "file:../../node_modules/@nativescript/core",
11+
"@nativescript-community/ui-material-bottom-navigation": "file:nativescript-community-ui-material-bottom-navigation-6.1.3-fixed-ios-appearance.tgz"
1112
},
1213
"devDependencies": {
1314
"@nativescript/android": "~8.1.1",

apps/nativescript-demo-ng/src/app/app-routing.module.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
import { NgModule } from '@angular/core';
2-
import { NativeScriptRouterModule } from '@nativescript/angular';
2+
import { NativeScriptRouterModule, NSEmptyOutletComponent } from '@nativescript/angular';
33
import { Routes } from '@angular/router';
44

55
import { ItemsComponent } from './item/items.component';
66
import { ItemDetailComponent } from './item/item-detail.component';
7+
import { HomeComponent } from './home/home.component';
8+
import { BootGuardService } from './boot-guard.service';
79

810
const routes: Routes = [
9-
{ path: '', redirectTo: '/rootlazy', pathMatch: 'full' },
10-
{ path: 'items', component: ItemsComponent },
11-
{ path: 'item/:id', component: ItemDetailComponent },
12-
{ path: 'item2', loadChildren: () => import('./item2/item2.module').then((m) => m.Item2Module) },
13-
{ path: 'rootlazy', loadChildren: () => import('./item3/item3.module').then((m) => m.Item3Module) },
11+
// { path: '', redirectTo: '/rootlazy', pathMatch: 'full' },
12+
// { path: 'items', component: ItemsComponent },
13+
// { path: 'item/:id', component: ItemDetailComponent },
14+
// { path: 'item2', loadChildren: () => import('./item2/item2.module').then((m) => m.Item2Module) },
15+
// { path: 'rootlazy', loadChildren: () => import('./item3/item3.module').then((m) => m.Item3Module) },
16+
{ path: '', redirectTo: '/home', pathMatch: 'full' },
17+
{
18+
path: 'home',
19+
component: HomeComponent,
20+
canActivate: [BootGuardService],
21+
children: [
22+
{
23+
path: 'start',
24+
component: NSEmptyOutletComponent,
25+
loadChildren: () => import('./item3/item3.module').then((m) => m.Item3Module),
26+
outlet: 'startTab',
27+
},
28+
],
29+
},
30+
{
31+
path: 'item2',
32+
loadChildren: () => import('./item2/item2.module').then((m) => m.Item2Module),
33+
},
1434
];
1535

1636
@NgModule({

apps/nativescript-demo-ng/src/app/app.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import { AppComponent } from './app.component';
66
import { ItemsComponent } from './item/items.component';
77
import { ItemDetailComponent } from './item/item-detail.component';
88
import { ModalComponent } from './modal/modal.component';
9+
import { HomeComponent } from './home/home.component';
10+
11+
import { NativeScriptMaterialBottomNavigationModule } from '@nativescript-community/ui-material-bottom-navigation/angular';
912

1013
@NgModule({
1114
bootstrap: [AppComponent],
12-
imports: [NativeScriptModule, NativeScriptHttpClientModule, AppRoutingModule, NativeDialogModule],
13-
declarations: [AppComponent, ItemsComponent, ItemDetailComponent, ModalComponent],
15+
imports: [NativeScriptModule, NativeScriptHttpClientModule, AppRoutingModule, NativeDialogModule, NativeScriptMaterialBottomNavigationModule],
16+
declarations: [AppComponent, ItemsComponent, ItemDetailComponent, ModalComponent, HomeComponent],
1417
providers: [],
1518
schemas: [NO_ERRORS_SCHEMA],
1619
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Injectable } from '@angular/core';
2+
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route, Router } from '@angular/router';
3+
4+
@Injectable({
5+
providedIn: 'root',
6+
})
7+
export class BootGuardService implements CanActivate, CanLoad {
8+
public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
9+
return new Promise((resolve) => {
10+
resolve(true);
11+
});
12+
}
13+
14+
public canLoad(route: Route): Promise<boolean> {
15+
return this.canActivate(null, null);
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<GridLayout rows="*" columns="*">
2+
<MDBottomNavigation selectedIndex="0" (loaded)="loadedTabView($event)" (selectedIndexChange)="onIndexChanged($event)">
3+
<MDTabStrip class="c-tabs">
4+
<MDTabStripItem class="tabstripitem">
5+
<Label [text]="tabItems?.start?.title" class="text-center t-12"></Label>
6+
</MDTabStripItem>
7+
</MDTabStrip>
8+
9+
<MDTabContentItem backgroundColor="transparent">
10+
<GridLayout>
11+
<page-router-outlet actionBarVisibility="never" name="startTab"></page-router-outlet>
12+
</GridLayout>
13+
</MDTabContentItem>
14+
</MDBottomNavigation>
15+
</GridLayout>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Component, NgZone } from '@angular/core';
2+
import { ActivatedRoute, Router } from '@angular/router';
3+
import { RouterExtensions } from '@nativescript/angular';
4+
import { Page, TabView } from '@nativescript/core';
5+
6+
@Component({
7+
moduleId: module.id,
8+
selector: 'demo-home',
9+
templateUrl: './home.component.html',
10+
})
11+
export class HomeComponent {
12+
tabItems: { [key: string]: { index: number; title?: string; iconSource?: string; textTransform?: string } } = {};
13+
private _tabs = ['start'];
14+
private _hasInitTab: { start?: boolean } = {};
15+
16+
constructor(
17+
private _ngZone: NgZone,
18+
// vcRef: ViewContainerRef,
19+
private _activeRoute: ActivatedRoute,
20+
private _page: Page,
21+
private _ngRouter: Router,
22+
private _router: RouterExtensions
23+
) {
24+
this._initMenu();
25+
}
26+
27+
ngOnInit() {
28+
this._viewTab(0);
29+
}
30+
31+
private _tabView;
32+
onIndexChanged(e) {
33+
if (e && e.object) {
34+
this._tabView = <TabView>e.object;
35+
}
36+
}
37+
38+
loadedTabView(args) {}
39+
40+
private _viewTab(index: number) {
41+
let route;
42+
switch (index) {
43+
case 0:
44+
if (!this._hasInitTab.start) {
45+
this._hasInitTab.start = true;
46+
route = { outlets: { startTab: ['start'] } };
47+
}
48+
break;
49+
}
50+
51+
console.log('tab index changed:', index);
52+
this._ngZone.run(() => {
53+
if (route) {
54+
this._router.navigate([route], {
55+
animated: false,
56+
relativeTo: this._activeRoute,
57+
});
58+
}
59+
});
60+
}
61+
62+
private _initMenu(profilePic?: string) {
63+
for (let i = 0; i < this._tabs.length; i++) {
64+
const tab = this._tabs[i];
65+
// console.log('================')
66+
// console.log(tab)
67+
// console.log(i);
68+
// console.log(tab);
69+
let title = '';
70+
switch (tab) {
71+
case 'start':
72+
title = 'Start Tab';
73+
break;
74+
}
75+
this.tabItems[tab] = {
76+
index: i,
77+
title,
78+
textTransform: 'capitalize',
79+
};
80+
}
81+
}
82+
}

apps/nativescript-demo-ng/yarn.lock

Lines changed: 0 additions & 126 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"license": "MIT",
55
"private": true,
66
"scripts": {
7-
"clean": "npx rimraf hooks node_modules package-lock.json yarn.lock && yarn",
8-
"clean.all": "yarn clean && nx run nativescript-demo-ng:clean",
7+
"clean": "npx rimraf hooks node_modules package-lock.json yarn.lock && npm i --legacy-peer-deps",
8+
"clean.all": "npm run clean && npm run demo:clean",
99
"postinstall": "husky install",
1010
"nx": "nx",
1111
"start": "nx serve",
1212
"build": "nx run zone-js:build && nx run angular:build",
13-
"test.android": "nx run nativescript-demo-ng:test --args='--platform=android'",
14-
"test.ios": "nx run nativescript-demo-ng:test --args='--platform=ios'",
13+
"test:android": "nx run nativescript-demo-ng:test --args='--platform=android'",
14+
"test:ios": "nx run nativescript-demo-ng:test --args='--platform=ios'",
1515
"lint": "nx workspace-lint && nx lint",
1616
"e2e": "nx e2e",
1717
"affected:apps": "nx affected:apps",
@@ -29,6 +29,9 @@
2929
"dep-graph": "nx dep-graph",
3030
"help": "nx help",
3131
"workspace-generator": "nx workspace-generator",
32+
"demo:android": "nx run nativescript-demo-ng:android",
33+
"demo:ios": "nx run nativescript-demo-ng:ios",
34+
"demo:clean": "nx run nativescript-demo-ng:clean",
3235
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
3336
},
3437
"dependencies": {

0 commit comments

Comments
 (0)