Skip to content

Commit 9dd4120

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

File tree

5 files changed

+23
-40
lines changed

5 files changed

+23
-40
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/nativescript.module.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import {
2121
} from "./platform-providers";
2222
import { NS_DIRECTIVES } from "./directives";
2323

24-
import * as nativescriptIntl from "nativescript-intl";
25-
global.Intl = nativescriptIntl;
26-
2724
export function errorHandlerFactory() {
2825
return new ErrorHandler(true);
2926
};

nativescript-angular/platform-common.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ import { topmost, NavigationEntry } from "ui/frame";
3333
import { Page } from "ui/page";
3434
import { TextView } from "ui/text-view";
3535

36-
import * as nativescriptIntl from "nativescript-intl";
37-
global.Intl = nativescriptIntl;
36+
import "nativescript-intl";
3837

3938
export const onBeforeLivesync = new EventEmitter<NgModuleRef<any>>();
4039
export const onAfterLivesync = new EventEmitter<NgModuleRef<any>>();

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
}

tests/app/tests/modal-dialog.ts

Lines changed: 17 additions & 22 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,39 +73,34 @@ 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)
10697
.then((ref) => {
10798
const service = <ModalDialogService>ref.instance.service;
108-
return service.showModal(ModalComponent, { context: context });
99+
const comp = <SuccessComponent>ref.instance;
100+
return service.showModal(ModalComponent, {
101+
viewContainerRef: comp.vcRef,
102+
context: context
103+
});
109104
})
110105
.then((res) => {
111106
assert.strictEqual(res, context);

0 commit comments

Comments
 (0)