Skip to content

Commit d86d350

Browse files
authored
Merge branch 'master' into add-test-for-native-setters
2 parents a1b794b + 6168ddb commit d86d350

37 files changed

+436
-301
lines changed

Diff for: .travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ deploy:
6161
api_key:
6262
secure: J88MqLAoZStZZ77AAf+wgaoZp+8zG3fOUHRneSe4x/yEzyUShS9SlGuq0TSkm9sJVX94iHJl1BQ4yjLshOPV9dkOg1+BB4PbsDTKPCAhPCZgpW7WKz6iImmuWHArchLIRtI1fp+UYi1+V6c7gLALQPY7qR2QJcDJdq1tdgORAyGySMis95ttVhnn6DWTBbs/ocu+IzgOyBSkIiZR0mGk7q/pmVQPy+XL5PQoyUOhD4MmvAAIeVr+XoZ5I8pAUwhi1/bZijXrzWe7LbXh8pTDlEWvYduzYYjJZqUrHiE/e1e8/DIPXGaBUQBj7LRxSqqO8AJXGeCg4DF1R9j4CSG5c0pAwQ/U6vOGu8duPEGaoKG5+HlrTav7gI/YbwFA5HKyh1uzQ5trZDJ4mMKUoB1+8/eL2cjLudtyBB2Kg28wH6f78A9mQC1EJcP7Jz3qJTSUyhczIvwSF8/EkD8xmeaoTi2e+4TNgf7pys1cp6c7m7zKZbvVy25lfyAfG1rCF5+rzKj+GnE9mtLaY6VvlKWjyxklh8hfRBC94TZ8K7PH0tmdgk2Jal+OCdm9FDdmNrBSC1G/gPS8PchtffIRprPhNAUfcVpdg0rlQ4dckbGRbB5UBgwHkpoKasaSTx/nO85AiK6USIYOIod19loXUBvN3QyHUX76w265UhmTnb8iojo=
6363
on:
64-
branch: master
64+
branch: master

Diff for: nativescript-angular/animations/animation-driver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AnimationPlayer } from "@angular/animations";
22

3-
import { NgView } from "../element-types";
3+
import { NgView } from "../element-registry";
44
import { NativeScriptAnimationPlayer } from "./animation-player";
55
import { Keyframe } from "./utils";
66

Diff for: nativescript-angular/animations/animation-engine.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ɵDomAnimationEngine as DomAnimationEngine } from "@angular/animations/browser";
22
import { AnimationEvent, AnimationPlayer } from "@angular/animations";
33

4-
import { NgView } from "../element-types";
4+
import { NgView } from "../element-registry";
55
import {
66
copyArray,
77
cssClasses,

Diff for: nativescript-angular/animations/animation-player.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
KeyframeAnimationInfo,
55
} from "tns-core-modules/ui/animation/keyframe-animation";
66

7-
import { NgView } from "../element-types";
7+
import { NgView } from "../element-registry";
88
import { Keyframe, getAnimationCurve, parseAnimationKeyframe } from "./utils";
99

1010
export class NativeScriptAnimationPlayer implements AnimationPlayer {

Diff for: nativescript-angular/animations/dom-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "@angular/animations";
88
import { unsetValue } from "tns-core-modules/ui/core/view";
99

10-
import { NgView } from "../element-types";
10+
import { NgView } from "../element-registry";
1111

1212
// overriden to use the default 'unsetValue'
1313
// instead of empty string ''

Diff for: nativescript-angular/directives/action-bar.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import { Page } from "tns-core-modules/ui/page";
44
import { View } from "tns-core-modules/ui/core/view";
55

66
import { isBlank } from "../lang-facade";
7-
import { registerElement } from "../element-registry";
8-
import { ViewClassMeta, NgView } from "../element-types";
7+
import {
8+
NgView,
9+
ViewClassMeta,
10+
registerElement,
11+
} from "../element-registry";
912

1013
const actionBarMeta: ViewClassMeta = {
1114
skipAddToDom: true,

Diff for: nativescript-angular/directives/dialogs.ts

+59-29
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import {
2-
ReflectiveInjector, ComponentFactoryResolver, ViewContainerRef,
3-
Type, Injectable, ComponentRef, Directive
2+
ComponentFactoryResolver,
3+
ComponentRef,
4+
Directive,
5+
Injectable,
6+
NgModuleRef,
7+
ReflectiveInjector,
8+
Type,
9+
ViewContainerRef,
410
} from "@angular/core";
11+
512
import { Page } from "tns-core-modules/ui/page";
613
import { View } from "tns-core-modules/ui/core/view";
14+
715
import { DetachedLoader } from "../common/detached-loader";
816
import { PageFactory, PAGE_FACTORY } from "../platform-providers";
917

1018
export interface ModalDialogOptions {
1119
context?: any;
1220
fullscreen?: boolean;
1321
viewContainerRef?: ViewContainerRef;
22+
moduleRef?: NgModuleRef<any>;
1423
}
1524

1625
export class ModalDialogParams {
@@ -20,42 +29,61 @@ export class ModalDialogParams {
2029
}
2130
}
2231

32+
interface ShowDialogOptions {
33+
containerRef: ViewContainerRef;
34+
context: any;
35+
doneCallback;
36+
fullscreen: boolean;
37+
pageFactory: PageFactory;
38+
parentPage: Page;
39+
resolver: ComponentFactoryResolver;
40+
type: Type<any>;
41+
}
42+
2343
@Injectable()
2444
export class ModalDialogService {
25-
public showModal(type: Type<any>, options: ModalDialogOptions): Promise<any> {
26-
if (!options.viewContainerRef) {
45+
public showModal(type: Type<any>,
46+
{viewContainerRef, moduleRef, context, fullscreen}: ModalDialogOptions
47+
): Promise<any> {
48+
if (!viewContainerRef) {
2749
throw new Error(
28-
"No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions.");
50+
"No viewContainerRef: " +
51+
"Make sure you pass viewContainerRef in ModalDialogOptions."
52+
);
2953
}
3054

31-
const viewContainerRef = options.viewContainerRef;
3255
const parentPage: Page = viewContainerRef.injector.get(Page);
33-
const resolver: ComponentFactoryResolver = viewContainerRef.injector.get(
34-
ComponentFactoryResolver);
3556
const pageFactory: PageFactory = viewContainerRef.injector.get(PAGE_FACTORY);
3657

37-
return new Promise((resolve) => {
38-
setTimeout(() => ModalDialogService.showDialog(
39-
type,
40-
options,
41-
resolve,
42-
viewContainerRef,
43-
resolver,
58+
// resolve from particular module (moduleRef)
59+
// or from same module as parentPage (viewContainerRef)
60+
const componentContainer = moduleRef || viewContainerRef;
61+
const resolver = componentContainer.injector.get(ComponentFactoryResolver);
62+
63+
return new Promise(resolve => {
64+
setTimeout(() => ModalDialogService.showDialog({
65+
containerRef: viewContainerRef,
66+
context,
67+
doneCallback: resolve,
68+
fullscreen,
69+
pageFactory,
4470
parentPage,
45-
pageFactory
46-
), 10);
71+
resolver,
72+
type,
73+
}), 10);
4774
});
4875
}
4976

50-
private static showDialog(
51-
type: Type<any>,
52-
options: ModalDialogOptions,
77+
private static showDialog({
78+
containerRef,
79+
context,
5380
doneCallback,
54-
containerRef: ViewContainerRef,
55-
resolver: ComponentFactoryResolver,
56-
parentPage: Page,
57-
pageFactory: PageFactory): void {
58-
81+
fullscreen,
82+
pageFactory,
83+
parentPage,
84+
resolver,
85+
type,
86+
}: ShowDialogOptions): void {
5987
const page = pageFactory({ isModal: true, componentType: type });
6088

6189
let detachedLoaderRef: ComponentRef<DetachedLoader>;
@@ -66,7 +94,7 @@ export class ModalDialogService {
6694
detachedLoaderRef.destroy();
6795
};
6896

69-
const modalParams = new ModalDialogParams(options.context, closeCallback);
97+
const modalParams = new ModalDialogParams(context, closeCallback);
7098

7199
const providers = ReflectiveInjector.resolve([
72100
{ provide: Page, useValue: page },
@@ -85,7 +113,7 @@ export class ModalDialogService {
85113
}
86114

87115
page.content = componentView;
88-
parentPage.showModal(page, options.context, closeCallback, options.fullscreen);
116+
parentPage.showModal(page, context, closeCallback, fullscreen);
89117
});
90118
}
91119
}
@@ -96,7 +124,9 @@ export class ModalDialogService {
96124
})
97125
export class ModalDialogHost { // tslint:disable-line:directive-class-suffix
98126
constructor() {
99-
throw new Error("ModalDialogHost is deprecated. Call ModalDialogService.showModal() " +
100-
"by passing ViewContainerRef in the options instead.");
127+
throw new Error("ModalDialogHost is deprecated. " +
128+
"Call ModalDialogService.showModal() " +
129+
"by passing ViewContainerRef in the options instead."
130+
);
101131
}
102132
}

Diff for: nativescript-angular/directives/list-view-comp.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import { ListView, ItemEventData } from "tns-core-modules/ui/list-view";
2323
import { View, KeyedTemplate } from "tns-core-modules/ui/core/view";
2424
import { ObservableArray } from "tns-core-modules/data/observable-array";
2525
import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base";
26+
import { profile } from "tns-core-modules/profiling";
2627

27-
import { CommentNode } from "../element-types";
28+
import { CommentNode } from "../element-registry";
2829
import { isListLikeIterable } from "../collection-facade";
2930
import { listViewLog, listViewError } from "../trace";
3031

@@ -148,6 +149,7 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit {
148149
this._templateMap.set(key, keyedTemplate);
149150
}
150151

152+
@profile
151153
public onItemLoading(args: ItemEventData) {
152154
if (!args.view && !this.itemTemplate) {
153155
return;
@@ -195,6 +197,7 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit {
195197
this.setupItemView.next({ view: viewRef, data: data, index: index, context: context });
196198
}
197199

200+
@profile
198201
private detectChangesOnChild(viewRef: EmbeddedViewRef<ListItemContext>, index: number) {
199202
listViewLog("Manually detect changes in child: " + index);
200203
viewRef.markForCheck();

Diff for: nativescript-angular/directives/tab-view.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "@angular/core";
1010
import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view";
1111

12-
import { CommentNode } from "../element-types";
12+
import { CommentNode } from "../element-registry";
1313
import { rendererLog } from "../trace";
1414
import { isBlank } from "../lang-facade";
1515

Diff for: nativescript-angular/dom-adapter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class NativeScriptDomAdapter implements ɵDomAdapter {
167167
getLocation(): Location { throw new Error("Not implemented!") }
168168
getBaseHref(): string { throw new Error("Not implemented!") }
169169
resetBaseElement(): void { throw new Error("Not implemented!") }
170-
getUserAgent(): string { throw new Error("Not implemented!") }
170+
getUserAgent(): string { return "Fake user agent"; }
171171
setData(_element: any /** TODO #9100 */, _name: string, _value: string): any
172172
/** TODO #9100 */ { throw new Error("Not implemented!") }
173173
getComputedStyle(_element: any /** TODO #9100 */): any { throw new Error("Not implemented!") }
@@ -179,7 +179,7 @@ export class NativeScriptDomAdapter implements ɵDomAdapter {
179179
getTransitionEnd(): string { throw new Error("Not implemented!") }
180180
supportsAnimation(): boolean { throw new Error("Not implemented!") }
181181

182-
supportsCookies(): boolean { throw new Error("Not implemented!") }
182+
supportsCookies(): boolean { return false; }
183183
getCookie(_name: string): string { throw new Error("Not implemented!") }
184184
setCookie(_name: string, _value: string): any /** TODO #9100 */ { throw new Error("Not implemented!") }
185185
}

Diff for: nativescript-angular/element-registry.ts

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
import { ViewClass, ViewClassMeta } from "./element-types";
1+
import { View } from "tns-core-modules/ui/core/view";
2+
3+
export type NgView = (View & ViewExtensions);
4+
export type NgElement = NgView | CommentNode;
5+
6+
export interface ViewExtensions {
7+
nodeType: number;
8+
nodeName: string;
9+
templateParent: NgView;
10+
ngCssClasses: Map<string, boolean>;
11+
meta: ViewClassMeta;
12+
}
13+
14+
export interface ViewClass {
15+
new (): View;
16+
}
17+
18+
// used for creating comments and text nodes in the renderer
19+
export class CommentNode {
20+
meta: { skipAddToDom: true };
21+
templateParent: NgView;
22+
}
23+
24+
export interface ViewClassMeta {
25+
skipAddToDom?: boolean;
26+
insertChild?: (parent: NgView, child: NgView, atIndex: number) => void;
27+
removeChild?: (parent: NgView, child: NgView) => void;
28+
}
29+
30+
export function isDetachedElement(element): boolean {
31+
return (element && element.meta && element.meta.skipAddToDom);
32+
}
233

334
export type ViewResolver = () => ViewClass;
435

Diff for: nativescript-angular/element-types.ts

-32
This file was deleted.

Diff for: nativescript-angular/index.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ export * from "./view-util";
1717
export * from "./resource-loader";
1818

1919
export {
20+
ViewClass,
21+
ViewClassMeta,
2022
ViewResolver,
21-
registerElement,
2223
getViewClass,
2324
getViewMeta,
2425
isKnownView,
26+
registerElement,
2527
} from "./element-registry";
2628

27-
export {
28-
ViewClass,
29-
ViewClassMeta,
30-
} from "./element-types";
31-
3229
export * from "./value-accessors/base-value-accessor";

Diff for: nativescript-angular/nativescript.module.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@ import "./polyfills/array";
88
import "./polyfills/console";
99

1010
import { CommonModule } from "@angular/common";
11-
import { NativeScriptRendererFactory } from "./renderer";
12-
import { DetachedLoader } from "./common/detached-loader";
13-
import { ModalDialogHost, ModalDialogService } from "./directives/dialogs";
1411
import {
1512
ApplicationModule,
1613
ErrorHandler,
14+
NO_ERRORS_SCHEMA,
15+
NgModule,
1716
RendererFactory2,
18-
NgModule, NO_ERRORS_SCHEMA,
17+
SystemJsNgModuleLoader,
1918
} from "@angular/core";
19+
20+
import { NativeScriptRendererFactory } from "./renderer";
21+
import { DetachedLoader } from "./common/detached-loader";
2022
import {
21-
defaultPageProvider,
23+
ModalDialogHost,
24+
ModalDialogService,
25+
} from "./directives/dialogs";
26+
import {
27+
defaultDeviceProvider,
2228
defaultFrameProvider,
23-
defaultDeviceProvider
29+
defaultPageProvider,
2430
} from "./platform-providers";
2531
import { NS_DIRECTIVES } from "./directives";
2632

@@ -35,13 +41,14 @@ export function errorHandlerFactory() {
3541
...NS_DIRECTIVES,
3642
],
3743
providers: [
38-
{ provide: ErrorHandler, useFactory: errorHandlerFactory },
44+
ModalDialogService,
45+
NativeScriptRendererFactory,
46+
SystemJsNgModuleLoader,
47+
defaultDeviceProvider,
3948
defaultFrameProvider,
4049
defaultPageProvider,
41-
defaultDeviceProvider,
42-
NativeScriptRendererFactory,
50+
{ provide: ErrorHandler, useFactory: errorHandlerFactory },
4351
{ provide: RendererFactory2, useClass: NativeScriptRendererFactory },
44-
ModalDialogService
4552
],
4653
entryComponents: [
4754
DetachedLoader,

0 commit comments

Comments
 (0)