Skip to content

Commit 87bc045

Browse files
author
Alexander Vakrilov
authored
Merge pull request #360 from NativeScript/cssClasses-name-clash
cssClasses renamed to ngCssClasses
2 parents 48e5fb8 + dd766d1 commit 87bc045

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ViewClassMeta {
1212
export interface ViewExtensions {
1313
nodeName: string;
1414
templateParent: NgView;
15-
cssClasses: Map<string, boolean>;
15+
ngCssClasses: Map<string, boolean>;
1616
meta: ViewClassMeta;
1717
}
1818

@@ -22,7 +22,7 @@ export interface ViewClass {
2222

2323
const defaultViewMeta: ViewClassMeta = {
2424
skipAddToDom: false,
25-
}
25+
};
2626

2727
const elementMap: Map<string, { resolver: ViewResolver, meta?: ViewClassMeta }> = new Map<string, { resolver: ViewResolver, meta?: ViewClassMeta }>();
2828
const camelCaseSplit = /([a-z0-9])([A-Z])/g;

Diff for: nativescript-angular/view-util.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import {View} 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';
6-
import {ViewClass, getViewClass, getViewMeta, isKnownView, ViewExtensions, NgView, ViewClassMeta} from './element-registry';
6+
import {ViewClass, getViewClass, getViewMeta, isKnownView, ViewExtensions, NgView} from './element-registry';
77
import {getSpecialPropertySetter} from "ui/builder/special-properties";
8-
import * as styleProperty from "ui/styling/style-property";
98
import {StyleProperty, getPropertyByName, withStyleProperty} from "ui/styling/style-property";
109
import {ValueSource} from "ui/core/dependency-observable";
11-
import { ActionBar, ActionItem, NavigationButton } from "ui/action-bar";
12-
import {device, platformNames, Device} from "platform";
10+
import {platformNames, Device} from "platform";
1311
import {rendererLog as traceLog, styleError} from "./trace";
1412

1513
const IOS_PREFX: string = "@ios:";
@@ -160,7 +158,7 @@ export class ViewUtil {
160158
}
161159

162160
private platformFilter(attribute: string): string {
163-
var lowered = attribute.toLowerCase();
161+
let lowered = attribute.toLowerCase();
164162
if (lowered.indexOf(IOS_PREFX) === 0) {
165163
if (this.isIos) {
166164
return attribute.substr(IOS_PREFX.length);
@@ -194,7 +192,7 @@ export class ViewUtil {
194192
let propMap = this.getProperties(view);
195193
let i = 0;
196194
while (i < properties.length - 1 && isDefined(view)) {
197-
var prop = properties[i];
195+
let prop = properties[i];
198196
if (propMap.has(prop)) {
199197
prop = propMap.get(prop);
200198
}
@@ -237,7 +235,7 @@ export class ViewUtil {
237235
return value;
238236
}
239237

240-
var valueAsNumber = +value;
238+
let valueAsNumber = +value;
241239
if (!isNaN(valueAsNumber)) {
242240
return valueAsNumber;
243241
} else if (value && (value.toLowerCase() === "true" || value.toLowerCase() === "false")) {
@@ -254,8 +252,8 @@ export class ViewUtil {
254252
}
255253

256254
if (!propertyMaps.has(type)) {
257-
var propMap = new Map<string, string>();
258-
for (var propName in instance) {
255+
let propMap = new Map<string, string>();
256+
for (let propName in instance) {
259257
propMap.set(propName.toLowerCase(), propName);
260258
}
261259
propertyMaps.set(type, propMap);
@@ -264,10 +262,10 @@ export class ViewUtil {
264262
}
265263

266264
private cssClasses(view: NgView) {
267-
if (!view.cssClasses) {
268-
view.cssClasses = new Map<string, boolean>();
265+
if (!view.ngCssClasses) {
266+
view.ngCssClasses = new Map<string, boolean>();
269267
}
270-
return view.cssClasses;
268+
return view.ngCssClasses;
271269
}
272270

273271
public addClass(view: NgView, className: string): void {
@@ -317,7 +315,6 @@ export class ViewUtil {
317315
withStyleProperty(name, resolvedValue, (property, value) => {
318316
if (isString(property)) {
319317
//Fall back to resolving property by name.
320-
const propertyName = <string>property;
321318
const resolvedProperty = getPropertyByName(name);
322319
if (resolvedProperty) {
323320
this.setStyleValue(view, resolvedProperty, resolvedValue);

Diff for: tests/app/tests/property-sets.ts

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
//make sure you import mocha-config before @angular/core
22
import {assert} from "./test-config";
3-
import {bootstrap} from "nativescript-angular/application";
4-
import {Component} from "@angular/core";
53
import {View} from "ui/core/view";
64
import {ViewUtil} from "nativescript-angular/view-util";
75
import {NgView, ViewExtensions, ViewClassMeta} from "nativescript-angular/element-registry";
86
import {Red} from "color/known-colors";
9-
import {device, Device, platformNames} from "platform";
7+
import {device, platformNames} from "platform";
108
import {createDevice} from "./test-utils";
119

1210
class TestView extends View implements ViewExtensions {
1311
public nodeName: string = "TestView";
1412
public templateParent: NgView = null;
1513
public meta: ViewClassMeta = { skipAddToDom: false };
16-
public cssClasses: Map<string, boolean> = new Map<string, boolean>();
14+
public ngCssClasses: Map<string, boolean> = new Map<string, boolean>();
1715

1816
public stringValue: string = "";
1917
public numValue: number = 0;
@@ -26,91 +24,91 @@ const iosDevice = createDevice(platformNames.ios);
2624
const androidDevice = createDevice(platformNames.android);
2725

2826
describe('setting View properties', () => {
29-
var viewUtil: ViewUtil;
27+
let viewUtil: ViewUtil;
3028
before(() => {
3129
viewUtil = new ViewUtil(device);
32-
})
30+
});
3331

3432
it('preserves string values', () => {
3533
let view = new TestView();
36-
viewUtil.setProperty(view, "stringValue", "blah")
34+
viewUtil.setProperty(view, "stringValue", "blah");
3735
assert.equal("blah", view.stringValue);
3836
});
3937

4038
it('converts number values', () => {
4139
let view = new TestView();
42-
viewUtil.setProperty(view, "numValue", "42")
40+
viewUtil.setProperty(view, "numValue", "42");
4341
assert.strictEqual(42, view.numValue);
44-
viewUtil.setProperty(view, "numValue", 0)
42+
viewUtil.setProperty(view, "numValue", 0);
4543
assert.strictEqual(0, view.numValue);
4644
});
4745

4846
it('converts boolean values', () => {
4947
let view = new TestView();
50-
viewUtil.setProperty(view, "boolValue", "true")
48+
viewUtil.setProperty(view, "boolValue", "true");
5149
assert.strictEqual(true, view.boolValue);
52-
viewUtil.setProperty(view, "boolValue", "false")
50+
viewUtil.setProperty(view, "boolValue", "false");
5351
assert.strictEqual(false, view.boolValue);
5452
});
5553

5654
it('sets style values', () => {
5755
let view = new TestView();
58-
viewUtil.setProperty(view, "style", "color: red")
56+
viewUtil.setProperty(view, "style", "color: red");
5957
assert.equal(Red, view.style.color.hex);
6058
});
6159

6260
it('doesn\'t convert blank strings', () => {
6361
let view = new TestView();
64-
viewUtil.setProperty(view, "stringValue", "")
62+
viewUtil.setProperty(view, "stringValue", "");
6563
assert.strictEqual("", view.stringValue);
6664
});
6765

6866
it('doesn\'t convert booleans', () => {
6967
let view = new TestView();
70-
viewUtil.setProperty(view, "boolValue", true)
68+
viewUtil.setProperty(view, "boolValue", true);
7169
assert.strictEqual(true, view.boolValue);
72-
viewUtil.setProperty(view, "boolValue", false)
70+
viewUtil.setProperty(view, "boolValue", false);
7371
assert.strictEqual(false, view.boolValue);
7472
});
7573

7674
it('preserves objects', () => {
7775
let value = { name: "Jim", age: 23 };
7876
let view = new TestView();
79-
viewUtil.setProperty(view, "anyValue", value)
77+
viewUtil.setProperty(view, "anyValue", value);
8078
assert.deepEqual(value, view.anyValue);
8179
});
8280

8381
it('sets nested properties', () => {
8482
let view = new TestView();
85-
viewUtil.setProperty(view, "nested.property", "blah")
83+
viewUtil.setProperty(view, "nested.property", "blah");
8684
assert.strictEqual("blah", view.nested.property);
8785
});
8886

8987
it('sets ios property in ios', () => {
9088
let view = new TestView();
9189
let testUtil = new ViewUtil(iosDevice);
92-
testUtil.setProperty(view, "@ios:anyValue", "blah")
90+
testUtil.setProperty(view, "@ios:anyValue", "blah");
9391
assert.strictEqual("blah", view.anyValue);
9492
});
9593

9694
it('doesn\'t set android property in ios', () => {
9795
let view = new TestView();
9896
let testUtil = new ViewUtil(iosDevice);
99-
testUtil.setProperty(view, "@android:anyValue", "blah")
97+
testUtil.setProperty(view, "@android:anyValue", "blah");
10098
assert.isUndefined(view.anyValue);
10199
});
102100

103101
it('sets android property in android', () => {
104102
let view = new TestView();
105103
let testUtil = new ViewUtil(androidDevice);
106-
testUtil.setProperty(view, "@android:anyValue", "blah")
104+
testUtil.setProperty(view, "@android:anyValue", "blah");
107105
assert.strictEqual("blah", view.anyValue);
108106
});
109107

110108
it('doesn\'t set ios property in android', () => {
111109
let view = new TestView();
112110
let testUtil = new ViewUtil(androidDevice);
113-
testUtil.setProperty(view, "@ios:anyValue", "blah")
111+
testUtil.setProperty(view, "@ios:anyValue", "blah");
114112
assert.isUndefined(view.anyValue);
115113
});
116114
});

0 commit comments

Comments
 (0)