Skip to content

Commit b397602

Browse files
committed
fix(renderer): use eachChild method of parent for nextSibling()
1 parent 08a7073 commit b397602

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Diff for: nativescript-angular/renderer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class NativeScriptRenderer extends RendererV2 {
116116

117117
nextSibling(node: NgView): number {
118118
traceLog(`NativeScriptRenderer.nextSibling ${node}`);
119-
return this.viewUtil.nextSibling(node);
119+
return this.viewUtil.nextSiblingIndex(node);
120120
}
121121

122122
createViewRoot(hostElement: NgView): NgView {

Diff for: nativescript-angular/view-util.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,24 @@ export class ViewUtil {
202202

203203
// finds the node in the parent's views and returns the next index
204204
// returns -1 if the node has no parent or next sibling
205-
public nextSibling(node: NgView): number {
205+
public nextSiblingIndex(node: NgView): number {
206206
const parent = node.parent;
207-
if (!parent || typeof (<any>parent)._subViews === "undefined") {
207+
208+
if (!parent) {
208209
return -1;
209210
} else {
210-
const index = (<any>parent)._subViews.indexOf(node);
211-
return index === -1 ? index : index + 1;
211+
let index = 0;
212+
let found = false;
213+
parent.eachChild(child => {
214+
if (child === node) {
215+
found = true;
216+
}
217+
218+
index += 1;
219+
return !found;
220+
});
221+
222+
return found ? index : -1;
212223
}
213224
}
214225

0 commit comments

Comments
 (0)