Skip to content

Commit 510439a

Browse files
vakrilovvakrilov
authored and
vakrilov
committed
Platfrom specific attributes
1 parent 9fb3833 commit 510439a

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

ng-sample/app/examples/platform-directives/platform-directives-test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import {Component, View} from 'angular2/core';
2-
import {RouteConfig} from 'angular2/router';
3-
import { Page} from "ui/page";
4-
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "../../nativescript-angular/router/ns-router";
5-
import {NS_DIRECTIVES} from "../../nativescript-angular/directives/ns-directives";
1+
import {Component} from 'angular2/core';
62

73
@Component({
84
selector: 'action-bar-test',
95
template: `
106
<StackLayout>
11-
<android><Label text="This is android specific content"></Label></android>
12-
<ios><Label text="This is android specific content"></Label></ios>
7+
<android><Label text="This is Android specific content"></Label></android>
8+
<ios><Label text="This is IOS specific content"></Label></ios>
9+
<Label
10+
android:text="Android specific attribute"
11+
ios:text="Ios specific attribute"></Label>
1312
</StackLayout>
1413
`
1514
})

src/nativescript-angular/view-util.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import {ViewClass, getViewClass, getViewMeta, isKnownView, ViewExtensions, NgVie
77
import {getSpecialPropertySetter} from "ui/builder/special-properties";
88
import { ActionBar, ActionItem, NavigationButton } from "ui/action-bar";
99
import trace = require("trace");
10+
import {device, platformNames} from "platform";
1011

12+
const isIos: boolean = device.os === platformNames.ios;
13+
const isAndroid: boolean = device.os === platformNames.android;
14+
const IOS_PREFX: string = "@ios:";
15+
const ANDROID_PREFX: string = "@android:";
1116

1217
export const rendererTraceCategory = "ns-renderer";
1318
export function traceLog(msg) {
@@ -142,7 +147,33 @@ function isXMLAttribute(name: string): boolean {
142147
}
143148
}
144149

150+
function platformFilter(attribute: string): string {
151+
var lowered = attribute.toLowerCase();
152+
if (lowered.indexOf(IOS_PREFX) === 0) {
153+
if (isIos) {
154+
return attribute.substr(IOS_PREFX.length);
155+
} else {
156+
return null;
157+
}
158+
}
159+
160+
if (lowered.indexOf(ANDROID_PREFX) === 0) {
161+
if (isAndroid) {
162+
return attribute.substr(ANDROID_PREFX.length);
163+
} else {
164+
return null;
165+
}
166+
}
167+
168+
return attribute;
169+
}
170+
145171
export function setProperty(view: NgView, attributeName: string, value: any): void {
172+
attributeName = platformFilter(attributeName);
173+
if (!attributeName) {
174+
return;
175+
}
176+
146177
if (attributeName.indexOf(".") !== -1) {
147178
// Handle nested properties
148179
const properties = attributeName.split(".");

0 commit comments

Comments
 (0)