Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 07abb9e

Browse files
fix(renderer): order not preserved (#2261)
1 parent 1dca81b commit 07abb9e

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

‎nativescript-angular/element-registry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface ViewExtensions {
99
nodeName: string;
1010
parentNode: NgView;
1111
nextSibling: NgView;
12+
previousSibling: NgView;
1213
firstChild: NgView;
1314
lastChild: NgView;
1415
ngCssClasses: Map<string, boolean>;
@@ -22,6 +23,7 @@ export abstract class InvisibleNode extends View implements NgView {
2223
nodeName: string;
2324
parentNode: NgView;
2425
nextSibling: NgView;
26+
previousSibling: NgView;
2527
firstChild: NgView;
2628
lastChild: NgView;
2729
ngCssClasses: Map<string, boolean>;

‎nativescript-angular/renderer.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import { ViewUtil } from './view-util';
66
import { NgView, InvisibleNode } from './element-registry';
77
import { NativeScriptDebug } from './trace';
88

9-
export interface ElementReference {
10-
previous: NgView;
11-
next: NgView;
12-
}
13-
149
@Injectable()
1510
export class NativeScriptRenderer extends Renderer2 {
1611
data: { [key: string]: any } = Object.create(null);
@@ -31,8 +26,8 @@ export class NativeScriptRenderer extends Renderer2 {
3126
}
3227

3328
@profile
34-
insertBefore(parent: NgView, newChild: NgView, refChild: NgView|ElementReference): void {
35-
let { previous, next } = refChild instanceof View ? this.nextSibling(refChild): refChild;
29+
insertBefore(parent: NgView, newChild: NgView, refChild: NgView): void {
30+
let { previous, next } = refChild instanceof View ? {previous: refChild.previousSibling,next: refChild} : {previous: null,next: null};
3631
if (NativeScriptDebug.isLogEnabled()) {
3732
NativeScriptDebug.rendererLog(`NativeScriptRenderer.insertBefore child: ${newChild} ` + `parent: ${parent} previous: ${previous} next: ${next}`);
3833
}
@@ -68,15 +63,12 @@ export class NativeScriptRenderer extends Renderer2 {
6863
}
6964

7065
@profile
71-
nextSibling(node: NgView): ElementReference {
66+
nextSibling(node: NgView): NgView {
7267
if (NativeScriptDebug.isLogEnabled()) {
7368
NativeScriptDebug.rendererLog(`NativeScriptRenderer.nextSibling of ${node} is ${node.nextSibling}`);
7469
}
7570

76-
return {
77-
previous: node,
78-
next: node.nextSibling,
79-
};
71+
return node.nextSibling;
8072
}
8173

8274
@profile

‎nativescript-angular/view-util.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ export class ViewUtil {
6363

6464
if (previous) {
6565
previous.nextSibling = child;
66+
child.previousSibling = previous;
6667
} else {
6768
parent.firstChild = child;
6869
}
6970

7071
if (next) {
7172
child.nextSibling = next;
73+
next.previousSibling = child;
7274
} else {
7375
this.appendToQueue(parent, child);
7476
}
@@ -81,6 +83,7 @@ export class ViewUtil {
8183

8284
if (parent.lastChild) {
8385
parent.lastChild.nextSibling = view;
86+
view.previousSibling = parent.lastChild;
8487
}
8588

8689
parent.lastChild = view;
@@ -152,23 +155,28 @@ export class ViewUtil {
152155
parent.firstChild = null;
153156
parent.lastChild = null;
154157
child.nextSibling = null;
158+
child.previousSibling = null;
155159
return;
156160
}
157161

158162
if (parent.firstChild === child) {
159163
parent.firstChild = child.nextSibling;
160164
}
161165

162-
const previous = this.findPreviousElement(parent,child);
166+
const previous = child.previousSibling;
163167
if (parent.lastChild === child) {
164168
parent.lastChild = previous;
165169
}
166170

167171
if (previous) {
168172
previous.nextSibling = child.nextSibling;
173+
if (child.nextSibling) {
174+
child.nextSibling.previousSibling = previous;
175+
}
169176
}
170177

171178
child.nextSibling = null;
179+
child.previousSibling = null;
172180
}
173181

174182
// NOTE: This one is O(n) - use carefully

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /