Skip to content

Commit c5b9a3f

Browse files
vakrilovhdeshev
vakrilov
authored andcommitted
MIgrate to modules 3.0
1 parent b855fbf commit c5b9a3f

File tree

7 files changed

+53
-76
lines changed

7 files changed

+53
-76
lines changed

nativescript-angular/animation-driver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { AnimationPlayer } from "@angular/core";
22
import { AnimationStyles, AnimationKeyframe } from "./private_import_core";
33
import { NativeScriptAnimationPlayer } from "./animation-player";
44
import { View } from "ui/core/view";
5-
import { getPropertyByCssName } from "ui/styling/style-property";
65

76
export abstract class AnimationDriver {
87
abstract animate(
@@ -13,7 +12,8 @@ export abstract class AnimationDriver {
1312
export class NativeScriptAnimationDriver implements AnimationDriver {
1413

1514
computeStyle(element: any, prop: string): string {
16-
return (<View>element).style._getValue(getPropertyByCssName(prop));
15+
const view = <View>element;
16+
return view.style[`css-${prop}`];
1717
}
1818

1919
animate(

nativescript-angular/animation-player.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
} from "ui/animation/keyframe-animation";
99
import { View } from "ui/core/view";
1010
import { AnimationCurve } from "ui/enums";
11-
import { ValueSource } from "ui/core/dependency-observable";
1211
import { isString } from "utils/types";
13-
import { getPropertyByCssName, KeyValuePair, Property } from "ui/styling/style-property";
12+
// import { ValueSource } from "ui/core/dependency-observable";
13+
// import { getPropertyByCssName, KeyValuePair, Property } from "ui/styling/style-property";
1414

1515
export class NativeScriptAnimationPlayer implements AnimationPlayer {
1616

@@ -60,22 +60,25 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
6060
for (let style of keyframe.styles.styles) {
6161
for (let substyle in style) {
6262
let value = style[substyle];
63-
let property = getPropertyByCssName(substyle);
64-
if (property) {
65-
if (typeof value === "string" && property.valueConverter) {
66-
value = property.valueConverter(<string>value);
67-
}
68-
keyframeInfo.declarations.push({ property: property.name, value: value });
69-
} else if (typeof value === "string" && substyle === "transform") {
70-
NativeScriptAnimationPlayer.parseTransform(<string>value, keyframeInfo);
71-
}
63+
console.log(value);
64+
65+
// TODO: Implement this using the modules 3.0 APIs
66+
67+
// let property = getPropertyByCssName(substyle);
68+
// if (property) {
69+
// if (typeof value === "string" && property.valueConverter) {
70+
// value = property.valueConverter(<string>value);
71+
// }
72+
// keyframeInfo.declarations.push({ property: property.name, value: value });
73+
// } else if (typeof value === "string" && substyle === "transform") {
74+
// NativeScriptAnimationPlayer.parseTransform(<string>value, keyframeInfo);
75+
// }
7276
}
7377
}
7478
keyframeAnimationInfo.keyframes.push(keyframeInfo);
7579
}
7680

77-
this.animation = KeyframeAnimation.keyframeAnimationFromInfo(
78-
keyframeAnimationInfo, ValueSource.VisualState);
81+
this.animation = KeyframeAnimation.keyframeAnimationFromInfo(keyframeAnimationInfo);
7982
}
8083

8184
init(): void {
@@ -218,7 +221,6 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
218221

219222
static parseTransform(value: string, animationInfo: KeyframeInfo) {
220223
let newTransform = NativeScriptAnimationPlayer.transformConverter(value);
221-
let array = new Array<KeyValuePair<Property, any>>();
222224
let values = undefined;
223225
for (let transform in newTransform) {
224226
switch (transform) {
@@ -287,6 +289,5 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer {
287289
throw new Error("Unsupported transform: " + transform);
288290
}
289291
}
290-
return array;
291292
}
292293
}

nativescript-angular/view-util.ts

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { isString, isDefined } from "utils/types";
2-
import { View } from "ui/core/view";
1+
import { isDefined } from "utils/types";
2+
import { View, unsetValue } from "ui/core/view";
33
import { Placeholder } from "ui/placeholder";
44
import { ContentView } from "ui/content-view";
55
import { LayoutBase } from "ui/layouts/layout-base";
@@ -12,11 +12,8 @@ import {
1212
NgView,
1313
TEMPLATE
1414
} from "./element-registry";
15-
import { getSpecialPropertySetter } from "ui/builder/special-properties";
16-
import { StyleProperty, getPropertyByName, withStyleProperty } from "ui/styling/style-property";
17-
import { ValueSource } from "ui/core/dependency-observable";
1815
import { platformNames, Device } from "platform";
19-
import { rendererLog as traceLog, styleError } from "./trace";
16+
import { rendererLog as traceLog } from "./trace";
2017

2118
const IOS_PREFX: string = ":ios:";
2219
const ANDROID_PREFX: string = ":android:";
@@ -235,15 +232,12 @@ export class ViewUtil {
235232
private setPropertyInternal(view: NgView, attributeName: string, value: any): void {
236233
traceLog("Setting attribute: " + attributeName);
237234

238-
let specialSetter = getSpecialPropertySetter(attributeName);
239235
let propMap = this.getProperties(view);
240236

241237
if (attributeName === "class") {
242238
this.setClasses(view, value);
243239
} else if (this.isXMLAttribute(attributeName)) {
244240
view._applyXmlAttribute(attributeName, value);
245-
} else if (specialSetter) {
246-
specialSetter(view, value);
247241
} else if (propMap.has(attributeName)) {
248242
// We have a lower-upper case mapped property.
249243
let propertyName = propMap.get(attributeName);
@@ -311,45 +305,19 @@ export class ViewUtil {
311305

312306
private syncClasses(view: NgView): void {
313307
let classValue = (<any>Array).from(this.cssClasses(view).keys()).join(" ");
314-
view.cssClass = classValue;
315-
}
316-
317-
private resolveCssValue(styleValue: string): string {
318-
return styleValue;
319-
}
320-
321-
private setStyleValue(view: NgView, property: StyleProperty, value: any) {
322-
try {
323-
if (value === null) {
324-
view.style._resetValue(property, ValueSource.Local);
325-
} else {
326-
view.style._setValue(property, value, ValueSource.Local);
327-
}
328-
} catch (ex) {
329-
styleError("Error setting property: " + property.name + " view: " + view +
330-
" value: " + value + " " + ex);
331-
}
308+
view.className = classValue;
332309
}
333310

334311
public setStyleProperty(view: NgView, styleName: string, styleValue: string): void {
335312
traceLog("setStyleProperty: " + styleName + " = " + styleValue);
336313

337314
let name = styleName;
338-
let resolvedValue = this.resolveCssValue(styleValue);
339-
withStyleProperty(name, resolvedValue, (property, value) => {
340-
if (isString(property)) {
341-
// Fall back to resolving property by name.
342-
const resolvedProperty = getPropertyByName(name);
343-
if (resolvedProperty) {
344-
this.setStyleValue(view, resolvedProperty, resolvedValue);
345-
} else {
346-
traceLog("Unknown style property: " + styleName);
347-
}
348-
} else {
349-
const resolvedProperty = <StyleProperty>property;
350-
this.setStyleValue(view, resolvedProperty, value);
351-
}
315+
let resolvedValue = styleValue; //this.resolveCssValue(styleValue);
352316

353-
});
317+
if (resolvedValue !== null) {
318+
view.style[name] = resolvedValue;
319+
} else {
320+
view.style[name] = unsetValue;
321+
}
354322
}
355323
}

ng-sample/app/examples/renderer-test.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
import {Component, Directive, Host, ElementRef, Input} from '@angular/core';
2-
import {Observable} from 'data/observable';
3-
import {TextValueAccessor} from 'nativescript-angular/value-accessors/text-value-accessor';
4-
import {CheckedValueAccessor} from 'nativescript-angular/value-accessors/checked-value-accessor';
1+
import { Component, Directive, Host, ElementRef, Input } from '@angular/core';
2+
import { Observable } from 'data/observable';
3+
import { TextValueAccessor } from 'nativescript-angular/value-accessors/text-value-accessor';
4+
import { CheckedValueAccessor } from 'nativescript-angular/value-accessors/checked-value-accessor';
5+
import { SegmentedBarItem } from 'ui/segmented-bar';
6+
7+
8+
function createTabItem(title: string) {
9+
let item = new SegmentedBarItem();
10+
item.title = title;
11+
return item;
12+
}
513

614
@Component({
715
moduleId: module.id,
@@ -27,8 +35,8 @@ export class ProgressDirective {
2735

2836
@Component({
2937
moduleId: module.id,
30-
selector: "renderer-test",
31-
templateUrl: "./renderer-test.html"
38+
selector: "renderer-test",
39+
templateUrl: "./renderer-test.html"
3240
})
3341
export class RendererTest {
3442
public buttonText: string = "";
@@ -64,13 +72,13 @@ export class RendererTest {
6472
"search": null,
6573
"selectedIndex": 0,
6674
"listPickerItems": [
67-
1,2,3,4
75+
1, 2, 3, 4
6876
],
6977
"segmentedBarItems": [
70-
{"title": "first"},
71-
{"title": "second"},
72-
{"title": "third"},
73-
{"title": "fourth"}
78+
createTabItem("first"),
79+
createTabItem("second"),
80+
createTabItem("third"),
81+
createTabItem("fourth")
7482
]
7583
};
7684

ng-sample/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"homepage": "https://github.com/NativeScript/template-hello-world",
2525
"dependencies": {
26-
"tns-core-modules": "~2.4.0",
26+
"tns-core-modules": "~2.5.0",
2727
"@angular/common": "~2.4.3",
2828
"@angular/compiler": "~2.4.3",
2929
"@angular/core": "~2.4.3",
@@ -56,4 +56,4 @@
5656
"version": "2.4.0"
5757
}
5858
}
59-
}
59+
}

tests/app/tests/test-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ export function createDevice(os: string): Device {
3333
return {
3434
os: os,
3535
osVersion: "0",
36-
deviceType: "phone",
36+
deviceType: "Phone",
3737
language: "en",
3838
uuid: "0000",
3939
sdkVersion: "0",
4040
region: "US",
4141
manufacturer: "tester",
4242
model: "test device"
43-
}
43+
};
4444
}

tests/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"homepage": "http://nativescript.org",
2828
"dependencies": {
2929
"nativescript-unit-test-runner": "^0.3.4",
30-
"tns-core-modules": "~2.4.0",
30+
"tns-core-modules": "~2.5.0",
3131
"nativescript-angular": "file:../nativescript-angular",
3232
"@angular/core": "~2.4.3",
3333
"@angular/common": "~2.4.3",
@@ -67,4 +67,4 @@
6767
"run-appium-android": "nativescript-dev-appium android",
6868
"appium-ios-simulator": "tns build ios && nativescript-dev-appium ios-simulator"
6969
}
70-
}
70+
}

0 commit comments

Comments
 (0)