Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 47e8481

Browse files
vchimevvakrilov
authored and
vakrilov
committedMar 22, 2018
fix-next(dialogs): integrate showModal method with changes in 4.0
Rename RootView class to AppHostView class. Expose ngAppRoot property of AppHostView class. Add modal-nested-test example.
1 parent 57809df commit 47e8481

File tree

7 files changed

+70
-35
lines changed

7 files changed

+70
-35
lines changed
 

‎nativescript-angular/app-host-view.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ContentView } from "tns-core-modules/ui/content-view";
2+
import { ViewBase } from "tns-core-modules/ui/core/view/view";
3+
4+
export class AppHostView extends ContentView {
5+
ngAppRoot: ViewBase;
6+
}

‎nativescript-angular/directives/dialogs.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {
1010
} from "@angular/core";
1111

1212
import { Page } from "tns-core-modules/ui/page";
13-
import { View } from "tns-core-modules/ui/core/view";
13+
import { View, ViewBase } from "tns-core-modules/ui/core/view";
1414

15+
import { AppHostView } from "../app-host-view";
1516
import { DetachedLoader } from "../common/detached-loader";
1617
import { PageFactory, PAGE_FACTORY } from "../platform-providers";
1718

@@ -35,15 +36,15 @@ interface ShowDialogOptions {
3536
doneCallback;
3637
fullscreen: boolean;
3738
pageFactory: PageFactory;
38-
parentPage: Page;
39+
parentView: ViewBase;
3940
resolver: ComponentFactoryResolver;
4041
type: Type<any>;
4142
}
4243

4344
@Injectable()
4445
export class ModalDialogService {
4546
public showModal(type: Type<any>,
46-
{viewContainerRef, moduleRef, context, fullscreen}: ModalDialogOptions
47+
{ viewContainerRef, moduleRef, context, fullscreen }: ModalDialogOptions
4748
): Promise<any> {
4849
if (!viewContainerRef) {
4950
throw new Error(
@@ -52,11 +53,15 @@ export class ModalDialogService {
5253
);
5354
}
5455

55-
const parentPage: Page = viewContainerRef.injector.get(Page);
56+
let parentView = viewContainerRef.element.nativeElement;
57+
if (parentView instanceof AppHostView && parentView.ngAppRoot) {
58+
parentView = parentView.ngAppRoot;
59+
}
60+
5661
const pageFactory: PageFactory = viewContainerRef.injector.get(PAGE_FACTORY);
5762

5863
// resolve from particular module (moduleRef)
59-
// or from same module as parentPage (viewContainerRef)
64+
// or from same module as parentView (viewContainerRef)
6065
const componentContainer = moduleRef || viewContainerRef;
6166
const resolver = componentContainer.injector.get(ComponentFactoryResolver);
6267

@@ -67,7 +72,7 @@ export class ModalDialogService {
6772
doneCallback: resolve,
6873
fullscreen,
6974
pageFactory,
70-
parentPage,
75+
parentView,
7176
resolver,
7277
type,
7378
}), 10);
@@ -80,7 +85,7 @@ export class ModalDialogService {
8085
doneCallback,
8186
fullscreen,
8287
pageFactory,
83-
parentPage,
88+
parentView,
8489
resolver,
8590
type,
8691
}: ShowDialogOptions): void {
@@ -113,7 +118,7 @@ export class ModalDialogService {
113118
}
114119

115120
page.content = componentView;
116-
parentPage.showModal(page, context, closeCallback, fullscreen);
121+
parentView.showModal(page, context, closeCallback, fullscreen);
117122
});
118123
}
119124
}

‎nativescript-angular/platform-common.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { DOCUMENT } from "@angular/common";
2424

2525
import { bootstrapLog, bootstrapLogError } from "./trace";
2626
import { PAGE_FACTORY, PageFactory, defaultPageFactoryProvider, setRootPage } from "./platform-providers";
27+
import { AppHostView } from "./app-host-view";
2728

2829
import {
2930
setCssFileName,
@@ -37,11 +38,10 @@ import {
3738
} from "tns-core-modules/application";
3839
import { NavigationEntry } from "tns-core-modules/ui/frame";
3940
import { Page } from "tns-core-modules/ui/page";
40-
import { ContentView } from "tns-core-modules/ui/content-view";
4141
import { TextView } from "tns-core-modules/ui/text-view";
4242

4343
import "nativescript-intl";
44-
import { View, Color } from "tns-core-modules/ui/core/view/view";
44+
import { Color, View } from "tns-core-modules/ui/core/view/view";
4545

4646
export const onBeforeLivesync = new EventEmitter<NgModuleRef<any>>();
4747
export const onAfterLivesync = new EventEmitter<{ moduleRef?: NgModuleRef<any>; error?: Error }>();
@@ -147,8 +147,8 @@ export class NativeScriptPlatformRef extends PlatformRef {
147147
@profile
148148
private bootstrapNativeScriptApp() {
149149
// Create a temp page for root of the renderer
150-
const tempRootView = new RootView();
151-
setRootPage(<any>tempRootView);
150+
const tempAppHostView = new AppHostView();
151+
setRootPage(<any>tempAppHostView);
152152
let rootContent: View;
153153

154154
bootstrapLog("NativeScriptPlatform bootstrap started.");
@@ -164,9 +164,10 @@ export class NativeScriptPlatformRef extends PlatformRef {
164164
bootstrapPromiseCompleted = true;
165165

166166
bootstrapLog(`Angular bootstrap bootstrap done. uptime: ${uptime()}`);
167-
rootContent = tempRootView.content;
168-
tempRootView.content = null;
169-
rootContent.parentNode = tempRootView;
167+
rootContent = tempAppHostView.content;
168+
tempAppHostView.content = null;
169+
tempAppHostView.ngAppRoot = rootContent;
170+
rootContent.parentNode = tempAppHostView;
170171
lastBootstrappedModule = new WeakRef(moduleRef);
171172
},
172173
err => {
@@ -204,8 +205,8 @@ export class NativeScriptPlatformRef extends PlatformRef {
204205

205206
onBeforeLivesync.next(lastBootstrappedModule ? lastBootstrappedModule.get() : null);
206207

207-
const tempRootView = new RootView();
208-
setRootPage(<any>tempRootView);
208+
const tempAppHostView = new AppHostView();
209+
setRootPage(<any>tempAppHostView);
209210
let rootContent: View;
210211

211212
let bootstrapPromiseCompleted = false;
@@ -215,9 +216,10 @@ export class NativeScriptPlatformRef extends PlatformRef {
215216
bootstrapLog("Angular livesync done.");
216217
onAfterLivesync.next({ moduleRef });
217218

218-
rootContent = tempRootView.content;
219-
tempRootView.content = null;
220-
rootContent.parentNode = tempRootView;
219+
rootContent = tempAppHostView.content;
220+
tempAppHostView.content = null;
221+
tempAppHostView.ngAppRoot = rootContent;
222+
rootContent.parentNode = tempAppHostView;
221223
lastBootstrappedModule = new WeakRef(moduleRef);
222224
},
223225
error => {
@@ -256,5 +258,3 @@ export class NativeScriptPlatformRef extends PlatformRef {
256258
return errorTextBox;
257259
}
258260
}
259-
260-
class RootView extends ContentView {}

‎ng-sample/app/app.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { HttpTest } from "./examples/http/http-test";
4646
import { HttpClientTest } from "./examples/http-client/http-client-test";
4747
import { ActionBarTest } from "./examples/action-bar/action-bar-test";
4848
import { ModalTest } from "./examples/modal/modal-test";
49+
import { ModalNestedTest } from "./examples/modal/modal-nested-test";
4950
import { PlatfromDirectivesTest } from "./examples/platform-directives/platform-directives-test";
5051
import { LivesyncApp } from "./examples/livesync-test/livesync-test-app";
5152

@@ -185,7 +186,5 @@ onAfterLivesync.subscribe(({ moduleRef, error }) => {
185186
});
186187

187188
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(LivesyncApp));
188-
console.log("APP RESTART!!!! !!!");
189-
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RendererTest));
190-
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(PageRouterOutletAppComponent));
191-
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(PageRouterOutletNestedAppComponent));
189+
// console.log("APP RESTART!!!! !!!");
190+
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ModalTest));

‎ng-sample/app/examples/modal/modal-content.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Component, Input} from "@angular/core";
2-
import {ModalDialogParams} from "nativescript-angular/directives/dialogs";
1+
import { Component, Input } from "@angular/core";
2+
import { ModalDialogParams } from "nativescript-angular/directives/dialogs";
33

44
@Component({
55
selector: "modal-content",
@@ -14,7 +14,9 @@ import {ModalDialogParams} from "nativescript-angular/directives/dialogs";
1414
`
1515
})
1616
export class ModalContent {
17+
1718
@Input() public prompt: string;
19+
1820
constructor(private params: ModalDialogParams) {
1921
console.log("ModalContent.constructor: " + JSON.stringify(params));
2022
this.prompt = params.context.promptMsg;
@@ -26,10 +28,10 @@ export class ModalContent {
2628

2729
ngOnInit() {
2830
console.log("ModalContent.ngOnInit");
29-
3031
}
3132

3233
ngOnDestroy() {
3334
console.log("ModalContent.ngOnDestroy");
3435
}
36+
3537
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component, ViewContainerRef } from "@angular/core";
2+
import * as dialogs from "ui/dialogs";
3+
import { ModalDialogService, ModalDialogOptions } from "nativescript-angular/directives/dialogs";
4+
import { ModalContent } from "./modal-content";
5+
import { ModalTest } from "./modal-test";
6+
7+
@Component({
8+
selector: "modal-nested-test",
9+
template: `
10+
<modal-test></modal-test>
11+
`
12+
})
13+
export class ModalNestedTest {
14+
15+
static entries = [
16+
ModalContent
17+
];
18+
19+
static exports = [
20+
ModalContent,
21+
ModalTest
22+
];
23+
24+
}

‎ng-sample/app/examples/modal/modal-test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, ViewContainerRef } from "@angular/core";
22
import * as dialogs from "ui/dialogs";
33
import { ModalDialogService, ModalDialogOptions } from "nativescript-angular/directives/dialogs";
4-
import { ModalContent} from "./modal-content";
4+
import { ModalContent } from "./modal-content";
55

66
@Component({
77
selector: "modal-test",
@@ -10,24 +10,22 @@ import { ModalContent} from "./modal-content";
1010
<StackLayout verticalAlignment="top" margin="12">
1111
<Button text="show component" (tap)="showModal(false)"></Button>
1212
<Button text="show component fullscreen" (tap)="showModal(true)"></Button>
13-
13+
1414
<Button text="alert" (tap)="showAlert()"></Button>
1515
<Button text="confirm" (tap)="showConfirm()"></Button>
1616
<Button text="prompt" (tap)="showPrompt()"></Button>
17-
1817
<Button text="action" (tap)="showAction()"></Button>
1918
<Button text="login" (tap)="showLogin()"></Button>
2019
</StackLayout>
21-
2220
<Label [text]="'RESULT: ' + result" row="1" margin="12"></Label>
2321
</GridLayout>
2422
`
2523
})
2624
export class ModalTest {
25+
2726
public result: string = "result";
2827

29-
constructor(private modal: ModalDialogService, private vcRef: ViewContainerRef) {
30-
}
28+
constructor(private modal: ModalDialogService, private vcRef: ViewContainerRef) { }
3129

3230
static entries = [
3331
ModalContent
@@ -110,4 +108,5 @@ export class ModalTest {
110108
"no result";
111109
});
112110
}
111+
113112
}

0 commit comments

Comments
 (0)
Please sign in to comment.