@@ -13,6 +13,7 @@ import {Switch} from 'ui/switch';
13
13
import { LayoutBase } from 'ui/layouts/layout-base' ;
14
14
import gestures = require( "ui/gestures" ) ;
15
15
import { ViewClass , getViewClass , isKnownView } from './element-registry' ;
16
+ import { isString } from "utils/types" ;
16
17
17
18
type EventHandler = ( args : EventData ) => void ;
18
19
@@ -28,11 +29,11 @@ export class ViewNode {
28
29
private cssClasses : Map < string , boolean > = new Map < string , boolean > ( ) ;
29
30
private static whiteSpaceSplitter = / \s + / ;
30
31
31
- public children :Array < ViewNode > = [ ] ;
32
+ public children : Array < ViewNode > = [ ] ;
32
33
33
34
constructor ( public parentNode : ViewNode ,
34
- public viewName : string ,
35
- attrNameAndValues : string [ ] ) {
35
+ public viewName : string ,
36
+ attrNameAndValues : string [ ] ) {
36
37
this . setAttributeValues ( attrNameAndValues ) ;
37
38
38
39
if ( this . parentNode )
@@ -57,7 +58,7 @@ export class ViewNode {
57
58
return this . _parentView
58
59
59
60
if ( this . parentNode ) {
60
- if ( this . parentNode . viewName !== "template" && this . parentNode . nativeView ) {
61
+ if ( this . parentNode . viewName !== "template" && this . parentNode . nativeView ) {
61
62
this . _parentView = this . parentNode . nativeView ;
62
63
} else {
63
64
this . _parentView = this . parentNode . parentNativeView ;
@@ -69,6 +70,10 @@ export class ViewNode {
69
70
return this . _parentView ;
70
71
}
71
72
73
+ get isComplexProperty ( ) : boolean {
74
+ return ViewNode . isComplexProperty ( this . viewName ) ;
75
+ }
76
+
72
77
public attachToView ( atIndex : number = - 1 ) {
73
78
console . log ( 'ViewNode.attachToView ' + this . viewName ) ;
74
79
if ( this . _attachedToView ) {
@@ -84,9 +89,11 @@ export class ViewNode {
84
89
this . children . forEach ( child => {
85
90
child . attachToView ( ) ;
86
91
} ) ;
92
+
93
+ this . postAttachUI ( ) ;
87
94
}
88
95
89
- private createUI ( attachAtIndex : number ) {
96
+ private createUI ( attachAtIndex : number ) : boolean {
90
97
if ( ! isKnownView ( this . viewName ) )
91
98
return ;
92
99
@@ -118,12 +125,41 @@ export class ViewNode {
118
125
}
119
126
} else if ( ( < any > this . parentNativeView ) . _addChildFromBuilder ) {
120
127
( < any > this . parentNativeView ) . _addChildFromBuilder ( this . viewName , this . nativeView ) ;
121
- } else {
128
+ } else if ( this . parentNode . isComplexProperty ) {
129
+ // complex property - we will deal with this in postAttachUI()
130
+ }
131
+ else {
122
132
console . log ( 'parentNativeView: ' + this . parentNativeView ) ;
123
133
throw new Error ( "Parent view can't have children! " + this . parentNativeView ) ;
124
134
}
125
135
}
126
136
137
+ private postAttachUI ( ) {
138
+ if ( this . isComplexProperty ) {
139
+ let nativeParent = < any > this . parentNativeView ;
140
+ if ( ! nativeParent ) {
141
+ return ;
142
+ }
143
+
144
+ let propertyName = ViewNode . getComplexPropertyName ( this . viewName ) ;
145
+ let realChildren = [ ] ;
146
+ for ( let child of this . children ) {
147
+ if ( child . nativeView ) {
148
+ realChildren . push ( child . nativeView ) ;
149
+ }
150
+ }
151
+ if ( realChildren . length > 0 ) {
152
+ if ( nativeParent . _addArrayFromBuilder ) {
153
+ nativeParent . _addArrayFromBuilder ( propertyName , realChildren ) ;
154
+ }
155
+ else {
156
+ this . parentNode . setAttribute ( propertyName , realChildren [ 0 ] ) ;
157
+ }
158
+ }
159
+ }
160
+ }
161
+
162
+
127
163
private static propertyMaps : Map < Function , Map < string , string > > = new Map < Function , Map < string , string > > ( ) ;
128
164
129
165
private static getProperties ( instance : any ) : Map < string , string > {
@@ -142,6 +178,21 @@ export class ViewNode {
142
178
return ViewNode . propertyMaps . get ( type ) ;
143
179
}
144
180
181
+ private static isComplexProperty ( name : string ) : boolean {
182
+ return isString ( name ) && name . indexOf ( "." ) !== - 1 ;
183
+ }
184
+
185
+ private static getComplexPropertyName ( fullName : string ) : string {
186
+ var name : string ;
187
+
188
+ if ( isString ( fullName ) ) {
189
+ var names = fullName . split ( "." ) ;
190
+ name = names [ names . length - 1 ] ;
191
+ }
192
+
193
+ return name ;
194
+ }
195
+
145
196
private configureUI ( ) {
146
197
if ( this . attributes . size == 0 )
147
198
return ;
@@ -337,7 +388,6 @@ export class ViewNode {
337
388
this . nativeView . cssClass = classValue ;
338
389
}
339
390
}
340
-
341
391
}
342
392
343
393
export class DummyViewNode extends ViewNode {
0 commit comments