@@ -13,6 +13,7 @@ import {Switch} from 'ui/switch';
1313import { LayoutBase } from 'ui/layouts/layout-base' ;
1414import gestures = require( "ui/gestures" ) ;
1515import { ViewClass , getViewClass , isKnownView } from './element-registry' ;
16+ import { isString } from "utils/types" ;
1617
1718type EventHandler = ( args : EventData ) => void ;
1819
@@ -28,11 +29,11 @@ export class ViewNode {
2829 private cssClasses : Map < string , boolean > = new Map < string , boolean > ( ) ;
2930 private static whiteSpaceSplitter = / \s + / ;
3031
31- public children :Array < ViewNode > = [ ] ;
32+ public children : Array < ViewNode > = [ ] ;
3233
3334 constructor ( public parentNode : ViewNode ,
34- public viewName : string ,
35- attrNameAndValues : string [ ] ) {
35+ public viewName : string ,
36+ attrNameAndValues : string [ ] ) {
3637 this . setAttributeValues ( attrNameAndValues ) ;
3738
3839 if ( this . parentNode )
@@ -57,7 +58,7 @@ export class ViewNode {
5758 return this . _parentView
5859
5960 if ( this . parentNode ) {
60- if ( this . parentNode . viewName !== "template" && this . parentNode . nativeView ) {
61+ if ( this . parentNode . viewName !== "template" && this . parentNode . nativeView ) {
6162 this . _parentView = this . parentNode . nativeView ;
6263 } else {
6364 this . _parentView = this . parentNode . parentNativeView ;
@@ -69,6 +70,10 @@ export class ViewNode {
6970 return this . _parentView ;
7071 }
7172
73+ get isComplexProperty ( ) : boolean {
74+ return ViewNode . isComplexProperty ( this . viewName ) ;
75+ }
76+
7277 public attachToView ( atIndex : number = - 1 ) {
7378 console . log ( 'ViewNode.attachToView ' + this . viewName ) ;
7479 if ( this . _attachedToView ) {
@@ -84,9 +89,11 @@ export class ViewNode {
8489 this . children . forEach ( child => {
8590 child . attachToView ( ) ;
8691 } ) ;
92+
93+ this . postAttachUI ( ) ;
8794 }
8895
89- private createUI ( attachAtIndex : number ) {
96+ private createUI ( attachAtIndex : number ) : boolean {
9097 if ( ! isKnownView ( this . viewName ) )
9198 return ;
9299
@@ -118,12 +125,40 @@ export class ViewNode {
118125 }
119126 } else if ( ( < any > this . parentNativeView ) . _addChildFromBuilder ) {
120127 ( < 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 {
122132 console . log ( 'parentNativeView: ' + this . parentNativeView ) ;
123133 throw new Error ( "Parent view can't have children! " + this . parentNativeView ) ;
124134 }
125135 }
126136
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+
127162 private static propertyMaps : Map < Function , Map < string , string > > = new Map < Function , Map < string , string > > ( ) ;
128163
129164 private static getProperties ( instance : any ) : Map < string , string > {
@@ -142,6 +177,21 @@ export class ViewNode {
142177 return ViewNode . propertyMaps . get ( type ) ;
143178 }
144179
180+ private static isComplexProperty ( name : string ) : boolean {
181+ return isString ( name ) && name . indexOf ( "." ) !== - 1 ;
182+ }
183+
184+ private static getComplexPropertyName ( fullName : string ) : string {
185+ var name : string ;
186+
187+ if ( isString ( fullName ) ) {
188+ var names = fullName . split ( "." ) ;
189+ name = names [ names . length - 1 ] ;
190+ }
191+
192+ return name ;
193+ }
194+
145195 private configureUI ( ) {
146196 if ( this . attributes . size == 0 )
147197 return ;
@@ -337,7 +387,6 @@ export class ViewNode {
337387 this . nativeView . cssClass = classValue ;
338388 }
339389 }
340-
341390}
342391
343392export class DummyViewNode extends ViewNode {
0 commit comments