Skip to content

Commit 0f73c13

Browse files
author
vakrilov
committed
Modal dialogs page
1 parent bdb1430 commit 0f73c13

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

app/main/main-page-router-outlet.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import {FirstComponent} from "../components/first.component";
99
import {SecondComponent} from "../components/second.component";
1010
import {NavigationTestRouter} from "../router/router-outlet";
1111
import {BindingComponent} from "../binding/binding-page";
12+
import {ModalTest, ModalTestWithPushStrategy} from "../modal/modal-dialog.component";
1213

1314
@Component({
1415
selector: "main",
1516
directives: [NS_ROUTER_DIRECTIVES],
17+
styles: [ 'button { margin: 0 6 }' ],
1618
template: `
1719
<StackLayout>
1820
<Label text="Main Component" class="title"></Label>
@@ -29,7 +31,11 @@ import {BindingComponent} from "../binding/binding-page";
2931
<Button text="ActionBar1" [nsRouterLink]="['FirstActionBar']"></Button>
3032
<Button text="ActionBar2" [nsRouterLink]="['SecondActionBar']"></Button>
3133
</StackLayout>
32-
<Button text="Binding" [nsRouterLink]="['Binding']"></Button>
34+
<Button text="Binding" [nsRouterLink]="['Binding']"></Button>
35+
<StackLayout orientation="horizontal" horizontalAlignment="center">
36+
<Button text="modal" [nsRouterLink]="['Modal']"></Button>
37+
<Button text="modal(onPush)" [nsRouterLink]="['ModalWithPushStrategy']"></Button>
38+
</StackLayout>
3339
</StackLayout>
3440
`,
3541
})
@@ -50,6 +56,8 @@ class MainComponent { }
5056
{ path: '/first-action-bar', component: FirstComponentActionBar, name: 'FirstActionBar' },
5157
{ path: '/second-action-bar', component: SecondComponentActionBar, name: 'SecondActionBar' },
5258
{ path: '/binding', component: BindingComponent, name: 'Binding' },
59+
{ path: '/modal', component: ModalTest, name: 'Modal' },
60+
{ path: '/modal-on-push', component: ModalTestWithPushStrategy, name: 'ModalWithPushStrategy' },
5361

5462
])
5563
export class NavigationMainPageRouter { }

app/modal/modal-dialog.component.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import {Component, ChangeDetectionStrategy} from '@angular/core';
2+
import * as dialogs from "ui/dialogs";
3+
import {ModalDialogService, ModalDialogOptions, ModalDialogHost, ModalDialogParams} from "nativescript-angular/directives/dialogs";
4+
5+
6+
@Component({
7+
selector: 'modal-content',
8+
template: `
9+
<StackLayout margin="24" horizontalAlignment="center" verticalAlignment="center">
10+
<Label [text]="prompt"></Label>
11+
<StackLayout orientation="horizontal" marginTop="12">
12+
<Button text="ok" (tap)="close('OK')"></Button>
13+
<Button text="cancel" (tap)="close('Cancel')"></Button>
14+
</StackLayout>
15+
</StackLayout>
16+
`
17+
})
18+
class ModalContent {
19+
public prompt: string;
20+
constructor(private params: ModalDialogParams) {
21+
this.prompt = params.context.message;
22+
}
23+
24+
public close(res: string) {
25+
this.params.closeCallback(res);
26+
}
27+
}
28+
29+
const TEMPLATE = `
30+
<GridLayout rows="*, auto" modal-dialog-host>
31+
<Button text="show component" (tap)="showModal()"></Button>
32+
33+
<Label [text]="'RESULT: ' + result" row="1" margin="12"></Label>
34+
</GridLayout>
35+
`;
36+
37+
@Component({
38+
selector: 'modal-test',
39+
directives: [ModalDialogHost],
40+
providers: [ModalDialogService],
41+
template: TEMPLATE
42+
})
43+
export class ModalTest {
44+
public result: string = "---";
45+
46+
constructor(private modal: ModalDialogService) { }
47+
48+
public showModal() {
49+
const options: ModalDialogOptions = {
50+
context: { message: "Hello from dialog!" },
51+
fullscreen: true
52+
};
53+
54+
this.modal.showModal(ModalContent, options).then((res: string) => {
55+
this.result = res || "empty result";
56+
})
57+
}
58+
}
59+
60+
@Component({
61+
selector: 'modal-test-on-push',
62+
directives: [ModalDialogHost],
63+
providers: [ModalDialogService],
64+
changeDetection: ChangeDetectionStrategy.OnPush,
65+
template: TEMPLATE
66+
})
67+
export class ModalTestWithPushStrategy {
68+
public result: string = "---";
69+
70+
constructor(private modal: ModalDialogService) { }
71+
72+
public showModal() {
73+
const options: ModalDialogOptions = {
74+
context: { message: "Hello from dialog (onPush)!" },
75+
fullscreen: true
76+
};
77+
78+
this.modal.showModal(ModalContent, options).then((res: string) => {
79+
this.result = res || "empty result";
80+
})
81+
}
82+
}

package.json

Lines changed: 1 addition & 1 deletion
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.0"
9+
"version": "2.0.1"
1010
},
1111
"tns-android": {
1212
"version": "2.1.0-2016-05-20-601"

0 commit comments

Comments
 (0)