Skip to content

Commit 517d5d6

Browse files
author
Alexander Vakrilov
authored
Merge pull request #376 from NativeScript/fix-platform-attributes
Fixed platform specific attribute setting
2 parents 895845d + 34fc5b1 commit 517d5d6

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

nativescript-angular/view-util.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {ValueSource} from "ui/core/dependency-observable";
1010
import {platformNames, Device} from "platform";
1111
import {rendererLog as traceLog, styleError} from "./trace";
1212

13-
const IOS_PREFX: string = "@ios:";
14-
const ANDROID_PREFX: string = "@android:";
13+
const IOS_PREFX: string = ":ios:";
14+
const ANDROID_PREFX: string = ":android:";
1515
const whiteSpaceSplitter = /\s+/;
1616

1717
export type ViewExtensions = ViewExtensions;

tests/app/tests/platform-filter-components.ts

+34-6
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,24 @@ export class AndroidSpecificComponent {
2727
constructor(public elementRef: ElementRef) { }
2828
}
2929

30+
@Component({
31+
template: `
32+
<StackLayout>
33+
<Label android:text="ANDROID" ios:text="IOS"></Label>
34+
</StackLayout>`
35+
})
36+
export class PlatformSpecificAttributeComponent {
37+
constructor(public elementRef: ElementRef) { }
38+
}
3039

31-
describe('Platofrm filter components', () => {
40+
describe('Platofrm filter directives', () => {
3241
describe('on IOS device', () => {
3342
let testApp: TestApp = null;
3443

3544
before(() => {
3645
return TestApp.create([provide(DEVICE, { useValue: createDevice(platformNames.ios) })]).then((app) => {
3746
testApp = app;
38-
})
47+
});
3948
});
4049

4150
after(() => {
@@ -59,15 +68,25 @@ describe('Platofrm filter components', () => {
5968
dumpView(componentRoot, true));
6069
});
6170
});
62-
})
71+
72+
73+
it("applies iOS specific attribute", () => {
74+
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
75+
const componentRoot = componentRef.instance.elementRef.nativeElement;
76+
assert.equal(
77+
"(ProxyViewContainer (StackLayout (Label[text=IOS])))",
78+
dumpView(componentRoot, true));
79+
});
80+
});
81+
});
6382

6483
describe('on Android device', () => {
6584
let testApp: TestApp = null;
6685

6786
before(() => {
6887
return TestApp.create([provide(DEVICE, { useValue: createDevice(platformNames.android) })]).then((app) => {
6988
testApp = app;
70-
})
89+
});
7190
});
7291

7392
after(() => {
@@ -91,5 +110,14 @@ describe('Platofrm filter components', () => {
91110
dumpView(componentRoot, true));
92111
});
93112
});
94-
})
95-
})
113+
114+
it("applies Android specific attribute", () => {
115+
return testApp.loadComponent(PlatformSpecificAttributeComponent).then((componentRef) => {
116+
const componentRoot = componentRef.instance.elementRef.nativeElement;
117+
assert.equal(
118+
"(ProxyViewContainer (StackLayout (Label[text=ANDROID])))",
119+
dumpView(componentRoot, true));
120+
});
121+
});
122+
});
123+
});

tests/app/tests/property-sets.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,28 @@ describe('setting View properties', () => {
8787
it('sets ios property in ios', () => {
8888
let view = new TestView();
8989
let testUtil = new ViewUtil(iosDevice);
90-
testUtil.setProperty(view, "@ios:anyValue", "blah");
90+
testUtil.setProperty(view, ":ios:anyValue", "blah");
9191
assert.strictEqual("blah", view.anyValue);
9292
});
9393

9494
it('doesn\'t set android property in ios', () => {
9595
let view = new TestView();
9696
let testUtil = new ViewUtil(iosDevice);
97-
testUtil.setProperty(view, "@android:anyValue", "blah");
97+
testUtil.setProperty(view, ":android:anyValue", "blah");
9898
assert.isUndefined(view.anyValue);
9999
});
100100

101101
it('sets android property in android', () => {
102102
let view = new TestView();
103103
let testUtil = new ViewUtil(androidDevice);
104-
testUtil.setProperty(view, "@android:anyValue", "blah");
104+
testUtil.setProperty(view, ":android:anyValue", "blah");
105105
assert.strictEqual("blah", view.anyValue);
106106
});
107107

108108
it('doesn\'t set ios property in android', () => {
109109
let view = new TestView();
110110
let testUtil = new ViewUtil(androidDevice);
111-
testUtil.setProperty(view, "@ios:anyValue", "blah");
111+
testUtil.setProperty(view, ":ios:anyValue", "blah");
112112
assert.isUndefined(view.anyValue);
113113
});
114114
});

0 commit comments

Comments
 (0)