@@ -224,6 +224,7 @@ export class ViewUtil {
224224 NativeScriptDebug . viewUtilLog ( `ViewUtil.removeFromList parent: ${ parent } child: ${ child } ` ) ;
225225 }
226226
227+ // only child. null everything
227228 if ( parent . firstChild === child && parent . lastChild === child ) {
228229 parent . firstChild = null ;
229230 parent . lastChild = null ;
@@ -232,22 +233,29 @@ export class ViewUtil {
232233 return ;
233234 }
234235
236+ const previous = child . previousSibling ;
237+ const next = child . nextSibling ;
238+ // is first child, make the next sibling the first child (can be null)
235239 if ( parent . firstChild === child ) {
236- parent . firstChild = child . nextSibling ;
240+ parent . firstChild = next ;
237241 }
238242
239- const previous = child . previousSibling ;
243+ // is last child, make the previous sibling the last child (can be null)
240244 if ( parent . lastChild === child ) {
241245 parent . lastChild = previous ;
242246 }
243247
248+ // we have a previous sibling, make it point to the next sibling
244249 if ( previous ) {
245- previous . nextSibling = child . nextSibling ;
246- if ( child . nextSibling ) {
247- child . nextSibling . previousSibling = previous ;
248- }
250+ previous . nextSibling = next ;
251+ }
252+
253+ // we have a next sibling, make it point to the previous
254+ if ( next ) {
255+ next . previousSibling = previous ;
249256 }
250257
258+ // finally, null the siblings
251259 child . nextSibling = null ;
252260 child . previousSibling = null ;
253261 }
0 commit comments