From c5dde43a3a99b47f177e2ee0f89d5a1266af60aa Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Tue, 13 Sep 2022 15:09:21 -0300 Subject: [PATCH] fix: correctly reassign siblings in linked list --- packages/angular/src/lib/view-util.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/angular/src/lib/view-util.ts b/packages/angular/src/lib/view-util.ts index 49b25ea..5704783 100644 --- a/packages/angular/src/lib/view-util.ts +++ b/packages/angular/src/lib/view-util.ts @@ -224,6 +224,7 @@ export class ViewUtil { NativeScriptDebug.viewUtilLog(`ViewUtil.removeFromList parent: ${parent} child: ${child}`); } + // only child. null everything if (parent.firstChild === child && parent.lastChild === child) { parent.firstChild = null; parent.lastChild = null; @@ -232,22 +233,29 @@ export class ViewUtil { return; } + const previous = child.previousSibling; + const next = child.nextSibling; + // is first child, make the next sibling the first child (can be null) if (parent.firstChild === child) { - parent.firstChild = child.nextSibling; + parent.firstChild = next; } - const previous = child.previousSibling; + // is last child, make the previous sibling the last child (can be null) if (parent.lastChild === child) { parent.lastChild = previous; } + // we have a previous sibling, make it point to the next sibling if (previous) { - previous.nextSibling = child.nextSibling; - if (child.nextSibling) { - child.nextSibling.previousSibling = previous; - } + previous.nextSibling = next; + } + + // we have a next sibling, make it point to the previous + if (next) { + next.previousSibling = previous; } + // finally, null the siblings child.nextSibling = null; child.previousSibling = null; }