@@ -54,7 +54,12 @@ export class ViewUtil {
54
54
this . isAndroid = device . os === platformNames . android ;
55
55
}
56
56
57
- public insertChild ( parent : NgView , child : NgElement , previous ?: NgElement , next ?: NgElement ) {
57
+ public insertChild (
58
+ parent : NgView ,
59
+ child : NgElement ,
60
+ previous : NgElement = parent . lastChild ,
61
+ next ?: NgElement
62
+ ) {
58
63
if ( ! parent ) {
59
64
return ;
60
65
}
@@ -68,23 +73,25 @@ export class ViewUtil {
68
73
}
69
74
}
70
75
71
- private addToQueue ( parent : NgElement , child : NgElement , previous : NgElement , next : NgElement ) {
76
+ private addToQueue (
77
+ parent : NgElement ,
78
+ child : NgElement ,
79
+ previous : NgElement ,
80
+ next : NgElement
81
+ ) : void {
82
+ if ( previous ) {
83
+ previous . nextSibling = child ;
84
+ } else {
85
+ parent . firstChild = child ;
86
+ }
87
+
72
88
if ( next ) {
73
- this . insertBetween ( child , previous , next ) ;
89
+ child . nextSibling = next ;
74
90
} else {
75
91
this . appendToQueue ( parent , child ) ;
76
92
}
77
93
}
78
94
79
- private insertBetween (
80
- view : NgElement ,
81
- previous : NgElement ,
82
- next : NgElement
83
- ) : void {
84
- previous . nextSibling = view ;
85
- view . nextSibling = next ;
86
- }
87
-
88
95
private appendToQueue ( parent : NgElement , view : NgElement ) {
89
96
if ( parent . lastChild ) {
90
97
parent . lastChild . nextSibling = view ;
@@ -133,35 +140,43 @@ export class ViewUtil {
133
140
this . removeLayoutChild ( parent , child ) ;
134
141
} else if ( isContentView ( parent ) && parent . content === child ) {
135
142
parent . content = null ;
143
+ parent . lastChild = null ;
144
+ parent . firstChild = null ;
136
145
} else if ( isView ( parent ) ) {
137
146
parent . _removeView ( child ) ;
138
147
}
139
148
}
140
149
141
150
private removeLayoutChild ( parent : NgLayoutBase , child : NgView ) : void {
142
151
const index = parent . getChildIndex ( child ) ;
152
+ this . removeFromQueue ( parent , child , index ) ;
143
153
if ( index === - 1 ) {
144
154
return ;
145
155
}
146
156
147
- this . removeFromQueue ( parent , child , index ) ;
148
157
parent . removeChild ( child ) ;
149
158
}
150
159
151
160
private removeFromQueue ( parent : NgLayoutBase , child : NgView , index : number ) {
152
- let previous = parent . getChildAt ( index - 1 ) as NgElement ;
153
- if ( ! previous ) {
154
- return ;
161
+ if ( parent . firstChild === child ) {
162
+ parent . firstChild = child . nextSibling ;
163
+ }
164
+
165
+ let previous = ( parent . getChildAt ( index - 1 ) || parent . firstChild ) as NgElement ;
166
+ if ( parent . lastChild === child ) {
167
+ parent . lastChild = previous ;
155
168
}
156
169
157
170
// since detached elements are not added to the visual tree,
158
171
// we need to find the actual previous sibling of the view,
159
- // which may be an invisible node
160
- while ( previous && previous !== child && isDetachedElement ( previous . nextSibling ) ) {
172
+ // which may as well be an invisible node
173
+ while ( previous && previous !== child && isDetachedElement ( previous . nextSibling ) ) {
161
174
previous = previous . nextSibling ;
162
175
}
163
176
164
- previous . nextSibling = child . nextSibling ;
177
+ if ( previous ) {
178
+ previous . nextSibling = child . nextSibling ;
179
+ }
165
180
}
166
181
167
182
public getChildIndex ( parent : any , child : NgView ) {
0 commit comments