Skip to content

Commit 333d3ac

Browse files
sis0k0hdeshev
authored andcommitted
fix(renderer): use eachChild method of parent for nextSibling()
1 parent 9627509 commit 333d3ac

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
@@ -121,7 +121,7 @@ export class NativeScriptRenderer extends RendererV2 {
121121

122122
nextSibling(node: NgView): number {
123123
traceLog(`NativeScriptRenderer.nextSibling ${node}`);
124-
return this.viewUtil.nextSibling(node);
124+
return this.viewUtil.nextSiblingIndex(node);
125125
}
126126

127127
createViewRoot(hostElement: NgView): NgView {

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

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

200200
// finds the node in the parent's views and returns the next index
201201
// returns -1 if the node has no parent or next sibling
202-
public nextSibling(node: NgView): number {
202+
public nextSiblingIndex(node: NgView): number {
203203
const parent = node.parent;
204-
if (!parent || typeof (<any>parent)._subViews === "undefined") {
204+
205+
if (!parent) {
205206
return -1;
206207
} else {
207-
const index = (<any>parent)._subViews.indexOf(node);
208-
return index === -1 ? index : index + 1;
208+
let index = 0;
209+
let found = false;
210+
parent.eachChild(child => {
211+
if (child === node) {
212+
found = true;
213+
}
214+
215+
index += 1;
216+
return !found;
217+
});
218+
219+
return found ? index : -1;
209220
}
210221
}
211222

0 commit comments

Comments
 (0)