Skip to content

Commit 25e3c5c

Browse files
authored
chore(modal-navigation-app): Add modal-navigation test app (#1358)
* chore(modal-navigation): update modal-navigation app * feat: complete componets and navigation
1 parent 62919b1 commit 25e3c5c

23 files changed

+344
-352
lines changed

Diff for: e2e/modal-navigation-ng/app/app.module.ts

+15-16
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ import { NativeScriptModule } from "nativescript-angular/nativescript.module";
33
import { AppRoutingModule } from "./app.routing";
44
import { AppComponent } from "./app.component";
55

6-
import { ItemService } from "./item/item.service";
7-
import { ItemsComponent } from "./item/items.component";
8-
import { ItemDetailComponent } from "./item/item-detail.component";
96
import { HomeComponent } from "./home/home.component";
10-
import { ModalTest } from "./modal/modal-test";
7+
import { SecondComponent } from "./second/second.component";
8+
import { ModalSecondComponent } from "./modal-second/modal-second.component";
9+
import { ModalComponent } from "./modal/modal.component";
10+
import { NestedModalComponent } from "./modal-nested/modal-nested.component";
11+
import { ModalRouterComponent } from "./modal/modal-router/modal-router.component";
1112

12-
// Uncomment and add to NgModule imports if you need to use two-way binding
13-
// import { NativeScriptFormsModule } from "nativescript-angular/forms";
13+
import { enable as traceEnable, addCategories } from "tns-core-modules/trace";
14+
import { routerTraceCategory } from "nativescript-angular/trace";
1415

15-
// Uncomment and add to NgModule imports if you need to use the HTTP wrapper
16-
// import { NativeScriptHttpModule } from "nativescript-angular/http";
16+
// addCategories(routerTraceCategory);
17+
// traceEnable();
1718

1819
@NgModule({
1920
bootstrap: [
@@ -23,17 +24,15 @@ import { ModalTest } from "./modal/modal-test";
2324
NativeScriptModule,
2425
AppRoutingModule
2526
],
26-
entryComponents: [...ModalTest.entries],
27+
entryComponents: [ModalRouterComponent, NestedModalComponent, ModalComponent],
2728
declarations: [
2829
AppComponent,
29-
ItemsComponent,
30-
ItemDetailComponent,
3130
HomeComponent,
32-
ModalTest,
33-
...ModalTest.entries
34-
],
35-
providers: [
36-
ItemService
31+
SecondComponent,
32+
ModalComponent,
33+
NestedModalComponent,
34+
ModalRouterComponent,
35+
ModalSecondComponent
3736
],
3837
schemas: [
3938
NO_ERRORS_SCHEMA

Diff for: e2e/modal-navigation-ng/app/app.routing.ts

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
import { NgModule } from "@angular/core";
22
import { NativeScriptRouterModule } from "nativescript-angular/router";
3-
import { Routes } from "@angular/router";
3+
import { Routes, ChildrenOutletContexts } from "@angular/router";
44

55
import { HomeComponent } from "./home/home.component";
6-
import { ItemsComponent } from "./item/items.component";
7-
import { ItemDetailComponent } from "./item/item-detail.component";
8-
import { ModalTest } from "./modal/modal-test";
6+
import { SecondComponent } from "./second/second.component";
7+
import { ModalSecondComponent } from "./modal-second/modal-second.component";
8+
import { ModalComponent } from "./modal/modal.component";
9+
import { NestedModalComponent } from "./modal-nested/modal-nested.component";
10+
import { ModalRouterComponent } from "./modal/modal-router/modal-router.component";
911

1012
const routes: Routes = [
1113
{ path: "", redirectTo: "/home", pathMatch: "full" },
12-
13-
{ path: "home", component: HomeComponent },
14-
15-
{ path: "modal", component: ModalTest , children: [
16-
{ path: "items", component: ItemsComponent },
17-
{ path: "item/:id", component: ItemDetailComponent },
18-
] },
14+
{
15+
path: "home", component: HomeComponent, children: [
16+
{
17+
path: "modal", component: ModalComponent, children: [
18+
{ path: "nested-frame-modal", component: NestedModalComponent }]
19+
},
20+
{ path: "modal-second", component: ModalSecondComponent }
21+
]
22+
},
23+
{
24+
path: "second", component: SecondComponent, children: [
25+
{
26+
path: "modal", component: ModalComponent, children: [
27+
{ path: "nested-frame-modal", component: NestedModalComponent }]
28+
},
29+
{ path: "modal-second", component: ModalSecondComponent }
30+
]
31+
}
1932
];
2033

2134
@NgModule({

Diff for: e2e/modal-navigation-ng/app/home/home.component.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<ActionBar class="action-bar">
2+
<Label class="action-bar-title" text="Home"></Label>
3+
</ActionBar>
4+
5+
<StackLayout>
6+
<Button text="Show Modal Without Frame" (tap)="onModalNoFrame()"></Button>
7+
<Button text="Show Modal Page With Frame" (tap)="onModalFrame()"></Button>
8+
<Button text="Navigate To Second Page" (tap)="onNavigateSecond()"></Button>
9+
<Button text="Reset Frame Root View" (tap)="onFrameRootViewReset()"></Button>
10+
<Button text="Reset Tab Root View"></Button>
11+
<Button text="Reset Layout Root View"></Button>
12+
</StackLayout>

Diff for: e2e/modal-navigation-ng/app/home/home.component.ts

+44-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,55 @@
11
import { Component, ViewContainerRef } from "@angular/core";
2+
import { ModalDialogService, ModalDialogOptions } from "nativescript-angular/directives/dialogs";
3+
import { EventData } from "tns-core-modules/data/observable";
4+
import { Frame } from "tns-core-modules/ui/frame";
5+
import { View } from "tns-core-modules/ui/core/view";
6+
import { ModalRouterComponent } from "../modal/modal-router/modal-router.component";
7+
import { PageRouterOutlet } from "nativescript-angular/router/page-router-outlet";
28
import { RouterExtensions } from "nativescript-angular/router";
9+
import { ModalComponent } from "../modal/modal.component";
310

411
@Component({
5-
selector: "modal-test",
6-
template: `
7-
<GridLayout rows="*, auto">
8-
<Button text="got to modal page" (tap)="gotToModal()"></Button>
9-
</GridLayout>
10-
`
12+
moduleId: module.id,
13+
selector: "home-page",
14+
templateUrl: "./home.component.html"
1115
})
1216
export class HomeComponent {
17+
constructor(private modal: ModalDialogService, private vcRef: ViewContainerRef, private routerExtension: RouterExtensions) { }
1318

14-
public result: string = "result";
19+
onModalNoFrame(args: EventData) {
20+
const options: ModalDialogOptions = {
21+
context: {
22+
navigationVisibility: false
23+
},
24+
fullscreen: true,
25+
viewContainerRef: this.vcRef
26+
};
1527

16-
constructor(private _routerExtensions: RouterExtensions, private vcRef: ViewContainerRef) { }
28+
this.modal.showModal(ModalComponent, options).then((res: string) => {
29+
console.log("moda-no-frame closed");
30+
});
31+
}
32+
33+
onModalFrame(args: EventData) {
34+
const options: ModalDialogOptions = {
35+
context: {
36+
navigationVisibility: true,
37+
modalRoute: "modal"
38+
},
39+
fullscreen: true,
40+
viewContainerRef: this.vcRef
41+
};
42+
43+
this.modal.showModal(ModalRouterComponent, options).then((res: string) => {
44+
console.log("moda-frame closed");
45+
});
46+
}
47+
48+
onNavigateSecond(args: EventData) {
49+
this.routerExtension.navigate(["second"]);
50+
}
1751

18-
public gotToModal() {
19-
this._routerExtensions.navigate(["/modal"]); //{clearHistory: true}
52+
onFrameRootViewReset(args: EventData) {
53+
2054
}
2155
}

Diff for: e2e/modal-navigation-ng/app/item/item-detail.component.html

-8
This file was deleted.

Diff for: e2e/modal-navigation-ng/app/item/item-detail.component.ts

-27
This file was deleted.

Diff for: e2e/modal-navigation-ng/app/item/item.service.ts

-39
This file was deleted.

Diff for: e2e/modal-navigation-ng/app/item/item.ts

-5
This file was deleted.

Diff for: e2e/modal-navigation-ng/app/item/items.component.html

-33
This file was deleted.

Diff for: e2e/modal-navigation-ng/app/item/items.component.ts

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
<ActionBar *ngIf="navigationVisibility === 'visible'">
3+
<Label class="action-bar-title" text="Modal Nested"></Label>
4+
</ActionBar>
5+
6+
<GridLayout #rootLayout rows="auto" (showingModally)="onShowingModally($event)" backgroundColor="lightBlue">
7+
<Button text="Close Modal Nested" (tap)="close(rootLayout)"></Button>
8+
</GridLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Component } from "@angular/core";
2+
import { View, ShownModallyData } from "ui/core/view"
3+
import { ModalDialogParams } from "nativescript-angular/directives/dialogs";
4+
5+
@Component({
6+
moduleId: module.id,
7+
selector: "modal-nested-page",
8+
templateUrl: "./modal-nested.component.html"
9+
})
10+
export class NestedModalComponent {
11+
public navigationVisibility: string = "collapse";
12+
13+
constructor(private params: ModalDialogParams) {
14+
15+
console.log("ModalNestedContent.constructor: " + JSON.stringify(params));
16+
this.navigationVisibility = params.context.navigationVisibility ? "visible" : "collapse";
17+
}
18+
19+
close(layoutRoot: View) {
20+
layoutRoot.closeModal();
21+
}
22+
23+
onShowingModally(args: ShownModallyData) {
24+
console.log("modal-page showingModally");
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
<ActionBar class="action-bar">
3+
<Label class="action-bar-title" text="Modal Second"></Label>
4+
</ActionBar>
5+
6+
<GridLayout #rootLayout rows="auto, auto" (loaded)="onLoaded($event)">
7+
<Button text="Go Back" (tap)="goBack()"></Button>
8+
<Button row="1" text="Close Modal Nested" (tap)="close(rootLayout)"></Button>
9+
</GridLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component } from "@angular/core";
2+
import { View, EventData } from "ui/core/view"
3+
import { RouterExtensions } from "nativescript-angular/router";
4+
5+
@Component({
6+
moduleId: module.id,
7+
selector: "modal-second-page",
8+
templateUrl: "./modal-second.component.html"
9+
})
10+
export class ModalSecondComponent {
11+
constructor(private routerExtension: RouterExtensions) { }
12+
13+
onLoaded(args: EventData) {
14+
console.log("modal-second loaded");
15+
}
16+
17+
goBack(args: EventData) {
18+
this.routerExtension.back();
19+
}
20+
21+
close(layoutRoot: View) {
22+
layoutRoot.closeModal();
23+
}
24+
}

0 commit comments

Comments
 (0)