Skip to content

Commit b4d7286

Browse files
Merge pull request #4 from NativeScript/clear-history
Navigation otpions pages
2 parents feea2e8 + 485d166 commit b4d7286

File tree

5 files changed

+75
-7
lines changed

5 files changed

+75
-7
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
hooks
22
node_modules
33
platforms
4+
lib
45

56
app/**/*.js
67
app/**/*.map

Diff for: app/main/main-page-router-outlet.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ import { BindingComponent } from "../binding/binding-page";
1515

1616
import { ListViewComponent } from "../listView/commonTemplate/list-view-page";
1717
import { ListViewControlComponent } from "../listView/customTemplate/list-view-item-template";
18-
import { ListViewAsyncPipeComponent } from "../listView/asyncPipeTemplate/async-pipe-template"
19-
import { ListViewMainPageComponent } from "../listView/listViewMainPage/list-view-main-page"
18+
import { ListViewAsyncPipeComponent } from "../listView/asyncPipeTemplate/async-pipe-template";
19+
import { ListViewMainPageComponent } from "../listView/listViewMainPage/list-view-main-page";
2020

2121
import { ModalTest, ModalTestWithPushStrategy } from "../modal/modal-dialog.component";
2222

23+
import { NavigationOptionsComponent } from "../navigation-options/navigation-options.component";
24+
import { NavigationInfoComponent } from "../navigation-options/navigation-info.component";
25+
26+
2327
@Component({
2428
selector: "main",
2529
directives: [NS_ROUTER_DIRECTIVES],
@@ -49,7 +53,9 @@ import { ModalTest, ModalTestWithPushStrategy } from "../modal/modal-dialog.comp
4953
<StackLayout orientation="horizontal" horizontalAlignment="center">
5054
<Button text="modal" [nsRouterLink]="['/modal']"></Button>
5155
<Button text="modal(onPush)" [nsRouterLink]="['/modal-on-push']"></Button>
52-
</StackLayout>
56+
</StackLayout>
57+
58+
<Button text="nav-options" [nsRouterLink]="['/nav-options']"></Button>
5359
</StackLayout>
5460
`,
5561
})
@@ -63,7 +69,7 @@ class MainComponent { }
6369
export class NavigationMainPageRouter { }
6470

6571

66-
var routes: RouterConfig = [
72+
const routes: RouterConfig = [
6773
{ path: '', component: MainComponent },
6874
{ path: 'template', component: AppComponent },
6975
{ path: 'router', component: NavigationTestRouter, children: NavigationSubRoutes },
@@ -81,6 +87,9 @@ var routes: RouterConfig = [
8187

8288
{ path: 'modal', component: ModalTest },
8389
{ path: 'modal-on-push', component: ModalTestWithPushStrategy },
90+
91+
{ path: 'nav-options', component: NavigationOptionsComponent },
92+
{ path: 'nav-info', component: NavigationInfoComponent }
8493
];
8594

8695
export var MainRouterProviders = nsProvideRouter(routes, { enableTracing: false });

Diff for: app/navigation-options/navigation-info.component.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {Component} from '@angular/core';
2+
import {NS_ROUTER_DIRECTIVES, RouterExtensions} from "nativescript-angular/router";
3+
import {NSLocationStrategy} from "nativescript-angular/router/ns-location-strategy";
4+
import {Frame} from "ui/frame";
5+
6+
7+
@Component({
8+
selector: 'nav-info',
9+
directives: [NS_ROUTER_DIRECTIVES],
10+
template: `
11+
<StackLayout>
12+
<Label [text]="'frameStack: ' + frameStack" ></Label>
13+
<Label [text]="'locationStack: ' + locationStack" ></Label>
14+
15+
<Button text="update" (tap)="update()"></Button>
16+
<Button text="back to main" [nsRouterLink]="['/']" [clearHistory]="true"></Button>
17+
</StackLayout>
18+
`
19+
})
20+
export class NavigationInfoComponent {
21+
private frameStack: number = -1;
22+
private locationStack: number = -1;
23+
24+
constructor(private frame: Frame, private strategy: NSLocationStrategy) { }
25+
26+
update() {
27+
// If history is cleared: frameStack = 0, locationStack = 1
28+
this.frameStack = this.frame.backStack.length;
29+
this.locationStack = this.strategy._getSatates().length;
30+
}
31+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {Component} from '@angular/core';
2+
import {NS_ROUTER_DIRECTIVES, RouterExtensions} from "nativescript-angular/router";
3+
4+
@Component({
5+
selector: 'nav-options',
6+
directives: [NS_ROUTER_DIRECTIVES],
7+
template: `
8+
<StackLayout>
9+
<Button text="clear-history" [nsRouterLink]="['/nav-info']" [clearHistory]="true"></Button>
10+
<Button text="page-trasnitions" (tap)="flipToNextPage()"></Button>
11+
</StackLayout>
12+
`
13+
})
14+
export class NavigationOptionsComponent {
15+
16+
constructor(private routerExtensions: RouterExtensions) { }
17+
18+
flipToNextPage() {
19+
this.routerExtensions.navigate(["/nav-info"], {
20+
transition: {
21+
name: "flip",
22+
duration: 5000,
23+
curve: "linear"
24+
}
25+
});
26+
}
27+
}

Diff for: package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"nativescript": {
77
"id": "org.nativescript.testsappng",
88
"tns-ios": {
9-
"version": "2.0.1"
9+
"version": "2.1.1"
1010
},
1111
"tns-android": {
1212
"version": "2.1.1"
@@ -21,8 +21,8 @@
2121
"@angular/platform-server": "2.0.0-rc.3",
2222
"@angular/router-deprecated": "2.0.0-rc.2",
2323
"@angular/router": "3.0.0-alpha.7",
24-
"nativescript-angular": "^0.2.0",
25-
"tns-core-modules": "^2.0.0 || 2.0.0-angular-7"
24+
"nativescript-angular": "next",
25+
"tns-core-modules": "next"
2626
},
2727
"devDependencies": {
2828
"babel-traverse": "6.8.0",

0 commit comments

Comments
 (0)