@@ -7,8 +7,10 @@ import {
7
7
} from 'angular2/src/core/render/api' ;
8
8
import { isBlank } from 'angular2/src/facade/lang' ;
9
9
import { DOM } from 'angular2/src/platform/dom/dom_adapter' ;
10
+ import { COMPONENT_VARIABLE , CONTENT_ATTR } from 'angular2/src/platform/dom/dom_renderer' ;
10
11
import { View } from "ui/core/view" ;
11
12
import { topmost } from 'ui/frame' ;
13
+ import { Page } from 'ui/page' ;
12
14
import * as util from "./view-util" ;
13
15
14
16
//var console = {log: function(msg) {}}
@@ -29,8 +31,18 @@ export class NativeScriptRootRenderer extends RootRenderer {
29
31
30
32
@Injectable ( )
31
33
export class NativeScriptRenderer extends Renderer {
34
+ private componentProtoId : string ;
35
+ private hasComponentStyles : boolean ;
32
36
constructor ( private _rootRenderer : NativeScriptRootRenderer , private componentProto : RenderComponentType ) {
33
37
super ( ) ;
38
+ let page = < Page > ( < any > topmost ( ) ) . currentPage ;
39
+ let stylesLength = componentProto . styles . length ;
40
+ this . componentProtoId = componentProto . id ;
41
+ for ( let i = 0 ; i < stylesLength ; i ++ ) {
42
+ this . hasComponentStyles = true ;
43
+ let cssString = componentProto . styles [ i ] + "" ;
44
+ page . addCss ( cssString . replace ( COMPONENT_VARIABLE , componentProto . id ) ) ;
45
+ }
34
46
console . log ( 'NativeScriptRenderer created' ) ;
35
47
}
36
48
@@ -126,7 +138,6 @@ export class NativeScriptRenderer extends Renderer {
126
138
console . log ( 'NativeScriptRenderer.setElementDebugInfo: ' + renderElement ) ;
127
139
}
128
140
129
-
130
141
/**
131
142
* Calls a method on an element.
132
143
*/
@@ -145,7 +156,13 @@ export class NativeScriptRenderer extends Renderer {
145
156
146
157
public createElement ( parentElement : util . NgView , name : string ) : util . NgView {
147
158
console . log ( 'NativeScriptRenderer.createElement: ' + name + ' parent: ' + parentElement + ', ' + ( parentElement ? parentElement . nodeName : 'null' ) ) ;
148
- return util . createView ( name , parentElement ) ;
159
+ let result = util . createView ( name , parentElement ) ;
160
+ // adding an attribute (property) to {N} view for applying component specific css.
161
+ // The property value is generated by angular2 infrastructure on conponent creation.
162
+ if ( this . hasComponentStyles ) {
163
+ result [ CONTENT_ATTR . replace ( COMPONENT_VARIABLE , this . componentProtoId ) ] = true ;
164
+ }
165
+ return result ;
149
166
}
150
167
151
168
public createText ( value : string ) : util . NgView {
@@ -163,4 +180,4 @@ export class NativeScriptRenderer extends Renderer {
163
180
public listenGlobal ( target : string , eventName : string , callback : Function ) : Function {
164
181
throw new Error ( 'Not implemented.' ) ;
165
182
}
166
- }
183
+ }
0 commit comments