Skip to content

Commit 95069f6

Browse files
Vasil Chimevmanoldonev
Vasil Chimev
authored andcommitted
feat: set TabView as root (#74)
* feat: set TabView as root Update to: - angular@6 - rxjs@6 - nativescript-angular@next - nativescript-dev-webpack@next * fix: tslint errors * refactor: remove onSelectedIndexChanged * feat: add Android icons * refactor: extract core module * refactor(item-detail): use route snapshot instead of rxjs subscription
1 parent 0443362 commit 95069f6

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

+273
-169
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading

packages/template-tab-navigation-ng/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,26 @@ tns create my-tab-ng --template https://github.com/NativeScript/template-tab-nav
3232
## Walkthrough
3333

3434
### Architecture
35-
There is one main component that holds the tabs page:
36-
- `/tabs/tabs.component.ts` - sets up the tab navigation page layout and references the navigatable views contents via custom components.
35+
The TabView component is set up as an application starting point in:
36+
- `app.component.ts` - sets up the tab view and defines page router otlets for its items.
3737

38-
There are three blank custom components used for the tab views located in these folders:
39-
- `/tabs/browse`
40-
- `/tabs/home`
41-
- `/tabs/search`
38+
There are four components used for the tab views located in these folders:
39+
40+
- `/browse`
41+
- `/home`
42+
- `/item-detail`
43+
- `/search`
4244

4345
### Styling
4446
This template is set up to use SASS for styling. All classes used are based on the {N} core theme – consult the [documentation](https://docs.nativescript.org/angular/ui/theme.html#theme) to understand how to customize it. Check it out to see what classes you can use on which component.
4547

4648
It has 4 global style files that are located at the root of the app folder:
49+
- `_app-common.scss` - holds the CSS rules you want to apply on both iOS and Android here.
4750
- `_app-variables.scss` - holds the global SASS variables that are imported on each component's styles.
48-
- `app.scss` - the global common style sheet. These style rules are applied to both Android and iOS.
49-
- `platform.android.scss` - the global Android style sheet. These style rules are applied to Android only.
50-
- `platform.ios.scss` - the global iOS style sheet. These style rules are applied to iOS only.
51+
- `app.android.scss` - the global Android style sheet. These style rules are applied to Android only.
52+
- `app.ios.scss` - the global iOS style sheet. These style rules are applied to iOS only.
5153

52-
Each component has 3 style files located in the its folder:
54+
A component could have 3 style files located in the its folder:
5355
- `_component-name.component.scss` - the component common style sheet. These style rules are applied to both Android and iOS.
5456
- `component-name.component.android.scss` - the component Android style sheet. These style rules are applied to Android only.
5557
- `component-name.component.ios.scss` - the component iOS style sheet. These style rules are applied to iOS only.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Custom common variables
2-
@import '../app-variables';
2+
@import './app-variables';

packages/template-tab-navigation-ng/app-routing.module.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@ import { NgModule } from "@angular/core";
22
import { Routes } from "@angular/router";
33
import { NativeScriptRouterModule } from "nativescript-angular/router";
44

5+
import { BrowseComponent } from "./browse/browse.component";
6+
import { HomeComponent } from "./home/home.component";
7+
import { ItemDetailComponent } from "./item-detail/item-detail.component";
8+
import { SearchComponent } from "./search/search.component";
9+
10+
export const COMPONENTS = [BrowseComponent, HomeComponent, ItemDetailComponent, SearchComponent];
11+
512
const routes: Routes = [
6-
{ path: "", redirectTo: "/tabs", pathMatch: "full" },
7-
{ path: "tabs", loadChildren: "./tabs/tabs.module#TabsModule" }
13+
{ path: "", redirectTo: "/(homeTab:home//browseTab:browse//searchTab:search)", pathMatch: "full" },
14+
15+
{ path: "home", component: HomeComponent, outlet: "homeTab" },
16+
{ path: "browse", component: BrowseComponent, outlet: "browseTab" },
17+
{ path: "search", component: SearchComponent, outlet: "searchTab" },
18+
19+
{ path: "item/:id", component: ItemDetailComponent, outlet: "homeTab" }
820
];
921

1022
@NgModule({
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import 'app.component';
2+
3+
// Place any CSS rules you want to apply only on Android here
4+
TabView {
5+
tab-text-color: $blue-dark;
6+
selected-tab-text-color: $item-active-color;
7+
}
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
<page-router-outlet></page-router-outlet>
1+
<TabView androidTabsPosition="bottom">
2+
3+
<page-router-outlet
4+
*tabItem="{title: 'Home', iconSource: getIconSource('home')}"
5+
name="homeTab">
6+
</page-router-outlet>
7+
8+
<page-router-outlet
9+
*tabItem="{title: 'Browse', iconSource: getIconSource('browse')}"
10+
name="browseTab">
11+
</page-router-outlet>
12+
13+
<page-router-outlet
14+
*tabItem="{title: 'Search', iconSource: getIconSource('search')}"
15+
name="searchTab">
16+
</page-router-outlet>
17+
18+
</TabView>

packages/template-tab-navigation-ng/tabs/tabs.component.ios.scss renamed to packages/template-tab-navigation-ng/app.component.ios.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import 'tabs.component';
1+
@import 'app.component';
22

33
// Place any CSS rules you want to apply only on IOS here
44
TabView {
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
import { Component } from "@angular/core";
1+
import { Component, OnInit } from "@angular/core";
2+
import { isAndroid } from "platform";
3+
import { SelectedIndexChangedEventData, TabView, TabViewItem } from "tns-core-modules/ui/tab-view";
24

35
@Component({
46
selector: "ns-app",
5-
templateUrl: "app.component.html"
7+
moduleId: module.id,
8+
templateUrl: "app.component.html",
9+
styleUrls: ["./app.component.scss"]
610
})
7-
export class AppComponent { }
11+
export class AppComponent implements OnInit {
12+
13+
constructor() {
14+
// Use the component constructor to inject providers.
15+
}
16+
17+
ngOnInit(): void {
18+
// Init your component properties here.
19+
}
20+
21+
getIconSource(icon: string): string {
22+
const iconPrefix = isAndroid ? "res://" : "res://tabIcons/";
23+
24+
return iconPrefix + icon;
25+
}
26+
}

packages/template-tab-navigation-ng/app.module.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { NgModule, NgModuleFactoryLoader, NO_ERRORS_SCHEMA } from "@angular/core";
22
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
33

4-
import { AppRoutingModule } from "./app-routing.module";
4+
import { AppRoutingModule, COMPONENTS } from "./app-routing.module";
55
import { AppComponent } from "./app.component";
6+
import { CoreModule } from "./core/core.module";
67

78
@NgModule({
89
bootstrap: [
910
AppComponent
1011
],
1112
imports: [
1213
NativeScriptModule,
13-
AppRoutingModule
14+
AppRoutingModule,
15+
CoreModule
1416
],
1517
declarations: [
16-
AppComponent
18+
AppComponent,
19+
...COMPONENTS
1720
],
1821
schemas: [
1922
NO_ERRORS_SCHEMA

packages/template-tab-navigation-ng/tabs/browse/browse.component.html renamed to packages/template-tab-navigation-ng/browse/browse.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<ActionBar class="action-bar">
2+
<Label class="action-bar-title" text="Browse"></Label>
3+
</ActionBar>
4+
15
<GridLayout class="page page-content">
26
<Label class="page-icon fa" text="&#xf1ea;"></Label>
37
<Label class="page-placeholder" text="<!-- Page content goes here -->"></Label>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { NgModule } from "@angular/core";
2+
import { DataService } from "./data.service";
3+
4+
@NgModule({
5+
providers: [
6+
DataService
7+
]
8+
})
9+
export class CoreModule { }
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { Injectable } from "@angular/core";
2+
3+
export interface IDataItem {
4+
id: number;
5+
name: string;
6+
description: string;
7+
}
8+
9+
@Injectable()
10+
export class DataService {
11+
12+
private items = new Array<IDataItem>(
13+
{
14+
id: 1,
15+
name: "Item 1",
16+
description: "Description for Item 1"
17+
},
18+
{
19+
id: 2,
20+
name: "Item 2",
21+
description: "Description for Item 2"
22+
},
23+
{
24+
id: 3,
25+
name: "Item 3",
26+
description: "Description for Item 3"
27+
},
28+
{
29+
id: 4,
30+
name: "Item 4",
31+
description: "Description for Item 4"
32+
},
33+
{
34+
id: 5,
35+
name: "Item 5",
36+
description: "Description for Item 5"
37+
},
38+
{
39+
id: 6,
40+
name: "Item 6",
41+
description: "Description for Item 6"
42+
},
43+
{
44+
id: 7,
45+
name: "Item 7",
46+
description: "Description for Item 7"
47+
},
48+
{
49+
id: 8,
50+
name: "Item 8",
51+
description: "Description for Item 8"
52+
},
53+
{
54+
id: 9,
55+
name: "Item 9",
56+
description: "Description for Item 9"
57+
},
58+
{
59+
id: 10,
60+
name: "Item 10",
61+
description: "Description for Item 10"
62+
},
63+
{
64+
id: 11,
65+
name: "Item 11",
66+
description: "Description for Item 11"
67+
},
68+
{
69+
id: 12,
70+
name: "Item 12",
71+
description: "Description for Item 12"
72+
},
73+
{
74+
id: 13,
75+
name: "Item 13",
76+
description: "Description for Item 13"
77+
},
78+
{
79+
id: 14,
80+
name: "Item 14",
81+
description: "Description for Item 14"
82+
},
83+
{
84+
id: 15,
85+
name: "Item 15",
86+
description: "Description for Item 15"
87+
},
88+
{
89+
id: 16,
90+
name: "Item 16",
91+
description: "Description for Item 16"
92+
}
93+
);
94+
95+
getItems(): Array<IDataItem> {
96+
return this.items;
97+
}
98+
99+
getItem(id: number): IDataItem {
100+
return this.items.filter((item) => item.id === id)[0];
101+
}
102+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<ActionBar class="action-bar">
2+
<Label class="action-bar-title" text="Home"></Label>
3+
</ActionBar>
4+
5+
<GridLayout class="page page-content">
6+
<ListView [items]="items" class="list-group">
7+
<ng-template let-item="item">
8+
<Label [nsRouterLink]="['../item', item.id]" [text]="item.name" class="list-group-item"></Label>
9+
</ng-template>
10+
</ListView>
11+
</GridLayout>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component, OnInit } from "@angular/core";
2+
import { RouterExtensions } from "nativescript-angular/router";
3+
import { DataService, IDataItem } from "../core/data.service";
4+
5+
@Component({
6+
selector: "Home",
7+
moduleId: module.id,
8+
templateUrl: "./home.component.html"
9+
})
10+
export class HomeComponent implements OnInit {
11+
items: Array<IDataItem>;
12+
13+
constructor(private itemService: DataService, private router: RouterExtensions) { }
14+
15+
ngOnInit(): void {
16+
this.items = this.itemService.getItems();
17+
}
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<ActionBar class="action-bar">
2+
<NavigationButton [nsRouterLink]="['../../home']" android.systemIcon="ic_menu_back"></NavigationButton>
3+
<Label class="action-bar-title" [text]="item.name"></Label>
4+
</ActionBar>
5+
6+
<GridLayout>
7+
<Label class="m-10 h3" verticalAlignment="top" [text]="item.description"></Label>
8+
</GridLayout>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Component, OnInit } from "@angular/core";
2+
import { ActivatedRoute } from "@angular/router";
3+
import { DataService, IDataItem } from "../core/data.service";
4+
5+
@Component({
6+
selector: "ItemDetail",
7+
moduleId: module.id,
8+
templateUrl: "./item-detail.component.html"
9+
})
10+
export class ItemDetailComponent implements OnInit {
11+
item: IDataItem;
12+
13+
constructor(
14+
private data: DataService,
15+
private route: ActivatedRoute
16+
) { }
17+
18+
ngOnInit(): void {
19+
const id = +this.route.snapshot.params.id;
20+
this.item = this.data.getItem(id);
21+
}
22+
}

packages/template-tab-navigation-ng/package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,31 @@
3232
"v8Flags": "--expose_gc"
3333
},
3434
"dependencies": {
35-
"@angular/animations": "~5.2.0",
36-
"@angular/common": "~5.2.0",
37-
"@angular/compiler": "~5.2.0",
38-
"@angular/core": "~5.2.0",
39-
"@angular/forms": "~5.2.0",
40-
"@angular/http": "~5.2.0",
41-
"@angular/platform-browser": "~5.2.0",
42-
"@angular/platform-browser-dynamic": "~5.2.0",
43-
"@angular/router": "~5.2.0",
44-
"nativescript-angular": "~5.3.0",
35+
"@angular/animations": "~6.0.0",
36+
"@angular/common": "~6.0.0",
37+
"@angular/compiler": "~6.0.0",
38+
"@angular/core": "~6.0.0",
39+
"@angular/forms": "~6.0.0",
40+
"@angular/http": "~6.0.0",
41+
"@angular/platform-browser": "~6.0.0",
42+
"@angular/platform-browser-dynamic": "~6.0.0",
43+
"@angular/router": "~6.0.0",
44+
"nativescript-angular": "next",
4545
"nativescript-theme-core": "~1.0.4",
4646
"reflect-metadata": "~0.1.10",
47-
"rxjs": "~5.5.5",
48-
"zone.js": "~0.8.18"
47+
"rxjs": "~6.0.0",
48+
"zone.js": "^0.8.4"
4949
},
5050
"devDependencies": {
5151
"codelyzer": "~4.0.2",
5252
"nativescript-dev-sass": "~1.5.0",
5353
"nativescript-dev-typescript": "~0.7.0",
54-
"nativescript-dev-webpack": "~0.10.0",
54+
"nativescript-dev-webpack": "next",
5555
"tslint": "~5.8.0",
5656
"typescript": "~2.7.2"
5757
},
5858
"scripts": {
5959
"preinstall": "node tools/preinstall.js",
6060
"postinstall": "node tools/postinstall.js"
6161
}
62-
}
62+
}

packages/template-tab-navigation-ng/tabs/search/search.component.html renamed to packages/template-tab-navigation-ng/search/search.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<ActionBar class="action-bar">
2+
<Label class="action-bar-title" text="Search"></Label>
3+
</ActionBar>
4+
15
<GridLayout class="page page-content">
26
<Label class="page-icon fa" text="&#xf002;"></Label>
37
<Label class="page-placeholder" text="<!-- Page content goes here -->"></Label>

0 commit comments

Comments
 (0)