Skip to content

Commit de465ec

Browse files
author
vakrilov
committed
deprecate modal-dialog-host
1 parent bc733d6 commit de465ec

File tree

4 files changed

+19
-36
lines changed

4 files changed

+19
-36
lines changed

nativescript-angular/directives/dialogs.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@ export class ModalDialogParams {
2222

2323
@Injectable()
2424
export class ModalDialogService {
25-
private containerRef: ViewContainerRef;
26-
27-
public registerViewContainerRef(ref: ViewContainerRef) {
28-
this.containerRef = ref;
29-
}
30-
3125
public showModal(type: Type<any>, options: ModalDialogOptions): Promise<any> {
32-
let viewContainerRef = options.viewContainerRef || this.containerRef;
33-
34-
if (!viewContainerRef) {
26+
if (!options.viewContainerRef) {
3527
throw new Error(
3628
"No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions.");
3729
}
3830

31+
const viewContainerRef = options.viewContainerRef;
3932
const parentPage: Page = viewContainerRef.injector.get(Page);
4033
const resolver: ComponentFactoryResolver = viewContainerRef.injector.get(
4134
ComponentFactoryResolver);
@@ -101,10 +94,8 @@ export class ModalDialogService {
10194
selector: "[modal-dialog-host]"
10295
})
10396
export class ModalDialogHost {
104-
constructor(containerRef: ViewContainerRef, modalService: ModalDialogService) {
105-
console.log("ModalDialogHost is deprecated. Call ModalDialogService.showModal() " +
97+
constructor() {
98+
throw new Error("ModalDialogHost is deprecated. Call ModalDialogService.showModal() " +
10699
"by passing ViewContainerRef in the options instead.");
107-
108-
modalService.registerViewContainerRef(containerRef);
109100
}
110101
}

nativescript-angular/view-util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export class ViewUtil {
166166
const viewClass = getViewClass(TEMPLATE);
167167
const anchor = this.createAndAttach(TEMPLATE, viewClass, parentElement);
168168
anchor.templateParent = parentElement;
169+
anchor.visibility = "collapse";
169170
traceLog("Created templateAnchor: " + anchor);
170171
return anchor;
171172
}

ng-sample/app/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ const customPageFactoryProvider = {
112112
}
113113
};
114114

115-
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RendererTest));
115+
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RendererTest));
116116
// platformNativeScriptDynamic(undefined, [customPageFactoryProvider]).bootstrapModule(makeExampleModule(RendererTest));
117117
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(TabViewTest));
118118
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(Benchmark));
119119
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTest));
120120
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTemplateSelectorTest));
121121
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTestAsync));
122122
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ImageTest));
123-
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ModalTest));
123+
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ModalTest));
124124
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(HttpTest));
125125
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(PlatfromDirectivesTest));
126126
// platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ActionBarTest));

tests/app/tests/modal-dialog.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//make sure you import mocha-config before @angular/core
2-
import {assert} from "./test-config";
3-
import {TestApp} from "./test-app";
4-
import {Component, ViewContainerRef} from "@angular/core";
5-
import {Page} from "ui/page";
6-
import {topmost} from "ui/frame";
7-
import {ModalDialogParams, ModalDialogService} from "nativescript-angular/directives/dialogs";
8-
9-
import {device, platformNames} from "platform";
2+
import { assert } from "./test-config";
3+
import { TestApp } from "./test-app";
4+
import { Component, ViewContainerRef } from "@angular/core";
5+
import { Page } from "ui/page";
6+
import { topmost } from "ui/frame";
7+
import { ModalDialogParams, ModalDialogService } from "nativescript-angular/directives/dialogs";
8+
9+
import { device, platformNames } from "platform";
1010
const CLOSE_WAIT = (device.os === platformNames.ios) ? 1000 : 0;
1111

1212
@Component({
@@ -37,7 +37,7 @@ export class FailComponent {
3737
selector: "sucess-comp",
3838
providers: [ModalDialogService],
3939
template: `
40-
<GridLayout modal-dialog-host margin="20">
40+
<GridLayout margin="20">
4141
<Label text="Modal dialogs"></Label>
4242
</GridLayout>`
4343
})
@@ -73,33 +73,24 @@ describe('modal-dialog', () => {
7373
});
7474

7575

76-
it("showModal throws when there is no modal-dialog-host and no viewContainer provided", (done) => {
76+
it("showModal throws when there is no viewContainer provided", (done) => {
7777
testApp.loadComponent(FailComponent)
7878
.then((ref) => {
7979
const service = <ModalDialogService>ref.instance.service;
8080
assert.throws(() => service.showModal(ModalComponent, {}), "No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions.");
8181
}).then(() => done(), err => done(err));
8282
});
8383

84-
it("showModal succeeds when there is modal-dialog-host", (done) => {
85-
testApp.loadComponent(SuccessComponent)
86-
.then((ref) => {
87-
const service = <ModalDialogService>ref.instance.service;
88-
return service.showModal(ModalComponent, {});
89-
})
90-
.then((res) => setTimeout(done, CLOSE_WAIT), err => done(err)); // wait for the dialog to close in IOS
91-
});
92-
9384
it("showModal succeeds when there is viewContainer provided", (done) => {
9485
testApp.loadComponent(SuccessComponent)
9586
.then((ref) => {
9687
const service = <ModalDialogService>ref.instance.service;
97-
return service.showModal(ModalComponent, {});
88+
const comp = <SuccessComponent>ref.instance;
89+
return service.showModal(ModalComponent, { viewContainerRef: comp.vcRef });
9890
})
9991
.then((res) => setTimeout(done, CLOSE_WAIT), err => done(err)); // wait for the dialog to close in IOS
10092
});
10193

102-
10394
it("showModal passes modal params and gets result when resolved", (done) => {
10495
const context = { property: "my context" };
10596
testApp.loadComponent(SuccessComponent)

0 commit comments

Comments
 (0)