88 getViewMeta ,
99 isKnownView ,
1010 ViewExtensions ,
11+ DetachedElement ,
12+ NgElement ,
1113 NgView ,
1214} from "./element-registry" ;
1315import { platformNames , Device } from "tns-core-modules/platform" ;
@@ -47,21 +49,21 @@ export class ViewUtil {
4749 this . isAndroid = device . os === platformNames . android ;
4850 }
4951
50- public insertChild ( parent : any , child : NgView , atIndex : number = - 1 ) {
51- if ( ! parent ) {
52+ public insertChild ( parent : any , child : NgElement , atIndex : number = - 1 ) {
53+ if ( child instanceof DetachedElement ) {
54+ child . templateParent = parent ;
5255 return ;
5356 }
5457
55- if ( child . meta . skipAddToDom ) {
56- child . templateParent = parent ;
58+ if ( ! parent || child . meta . skipAddToDom ) {
5759 return ;
5860 }
5961
6062 if ( parent . meta && parent . meta . insertChild ) {
6163 parent . meta . insertChild ( parent , child , atIndex ) ;
6264 } else if ( isLayout ( parent ) ) {
6365 if ( child . parent === parent ) {
64- let index = ( < LayoutBase > parent ) . getChildIndex ( child ) ;
66+ const index = ( < LayoutBase > parent ) . getChildIndex ( child ) ;
6567 if ( index !== - 1 ) {
6668 parent . removeChild ( child ) ;
6769 }
@@ -72,21 +74,16 @@ export class ViewUtil {
7274 parent . addChild ( child ) ;
7375 }
7476 } else if ( isContentView ( parent ) ) {
75- // Explicit handling of template anchors inside ContentView
76- if ( child . nodeName === "#comment" ) {
77- parent . _addView ( child , atIndex ) ;
78- } else {
79- parent . content = child ;
80- }
77+ parent . content = child ;
8178 } else if ( parent && parent . _addChildFromBuilder ) {
8279 parent . _addChildFromBuilder ( child . nodeName , child ) ;
8380 } else {
8481 // throw new Error("Parent can"t contain children: " + parent.nodeName + ", " + parent);
8582 }
8683 }
8784
88- public removeChild ( parent : any , child : NgView ) {
89- if ( ! parent || child . meta . skipAddToDom ) {
85+ public removeChild ( parent : any , child : NgElement ) {
86+ if ( ! parent || child instanceof DetachedElement || child . meta . skipAddToDom ) {
9087 return ;
9188 }
9289
@@ -98,11 +95,6 @@ export class ViewUtil {
9895 if ( parent . content === child ) {
9996 parent . content = null ;
10097 }
101-
102- // Explicit handling of template anchors inside ContentView
103- if ( child . nodeName === "#comment" ) {
104- parent . _removeView ( child ) ;
105- }
10698 } else if ( isView ( parent ) ) {
10799 parent . _removeView ( child ) ;
108100 } else {
@@ -120,20 +112,12 @@ export class ViewUtil {
120112 }
121113 }
122114
123- public createComment ( ) : NgView {
124- const commentView = this . createView ( "Comment" ) ;
125- commentView . nodeName = "#comment" ;
126- commentView . visibility = "collapse" ;
127-
128- return commentView ;
115+ public createComment ( ) : DetachedElement {
116+ return new DetachedElement ( ) ;
129117 }
130118
131- public createText ( ) : NgView {
132- const detachedText = this . createView ( "DetachedText" ) ;
133- detachedText . nodeName = "#text" ;
134- detachedText . visibility = "collapse" ;
135-
136- return detachedText ;
119+ public createText ( ) : DetachedElement {
120+ return new DetachedElement ( ) ;
137121 }
138122
139123 public createView ( name : string ) : NgView {
@@ -142,6 +126,7 @@ export class ViewUtil {
142126 if ( ! isKnownView ( name ) ) {
143127 name = "ProxyViewContainer" ;
144128 }
129+
145130 const viewClass = getViewClass ( name ) ;
146131 let view = < NgView > new viewClass ( ) ;
147132 view . nodeName = name ;
0 commit comments