Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix 809 view node siblings #810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions platform/nativescript/renderer/ViewNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,11 @@ export default class ViewNode {
throw new Error(`Can't insert child.`)
}

// in some rare cases insertBefore is called with a null referenceNode
// this makes sure that it get's appended as the last child
if (!referenceNode) {
return this.appendChild(childNode)
}

if (referenceNode.parentNode && referenceNode.parentNode !== this) {
if (
referenceNode &&
referenceNode.parentNode &&
referenceNode.parentNode !== this
) {
throw new Error(
`Can't insert child, because the reference node has a different parent.`
)
Expand All @@ -197,9 +195,17 @@ export default class ViewNode {
// throw new Error(`Can't insert child, because it is already a child.`)
}

// in some rare cases insertBefore is called with a null referenceNode
// this makes sure that it get's appended as the last child
if (!referenceNode) {
return this.appendChild(childNode)
}

let index = this.childNodes.indexOf(referenceNode)

childNode.parentNode = this
if (childNode.prevSibling) childNode.prevSibling.nextSibling = childNode

childNode.nextSibling = referenceNode
childNode.prevSibling = this.childNodes[index - 1]

Expand All @@ -220,16 +226,7 @@ export default class ViewNode {
)
}

if (childNode.parentNode === this) {
// we don't need to throw an error here, because it is a valid case
// for example when switching the order of elements in the tree
// fixes #127 - see for more details
// fixes #240
// throw new Error(`Can't append child, because it is already a child.`)
}

childNode.parentNode = this

if (this.lastChild) {
childNode.prevSibling = this.lastChild
this.lastChild.nextSibling = childNode
Expand Down