Skip to content

Commit b9b55b6

Browse files
committed
fix(PageRouterOutlet): Don't remove grandchild views when moving component
PageRouterOutlet.loadComponentInPage moves the componentView from its native parent, to the Page. Don't remove the componentView's children when it is removed from the native parent.
1 parent e74afc2 commit b9b55b6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Diff for: nativescript-angular/router/page-router-outlet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
357357
// Component loaded. Find its root native view.
358358
const componentView = componentRef.location.nativeElement;
359359
// Remove it from original native parent.
360-
this.viewUtil.removeChild(componentView.parent, componentView);
360+
this.viewUtil.removeChild(componentView.parent, componentView, false);
361361
// Add it to the new page
362362
this.viewUtil.insertChild(page, componentView);
363363

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ export class ViewUtil {
157157
return next;
158158
}
159159

160-
public removeChild(parent: View, child: View) {
160+
public removeChild(parent: View, child: View, removeGrandchildren = true) {
161161
if (isLogEnabled()) {
162-
traceLog(`ViewUtil.removeChild parent: ${parent} child: ${child}`);
162+
traceLog(`ViewUtil.removeChild parent: ${parent} child: ${child} `
163+
+ `remove grandchildren: ${removeGrandchildren}`);
163164
}
164165

165166
if (!parent) {
@@ -170,7 +171,8 @@ export class ViewUtil {
170171
const extendedChild = this.ensureNgViewExtensions(child);
171172

172173
// Remove the child's children and their children
173-
while (extendedChild && extendedChild.firstChild) {
174+
// Unless called from PageRouterOutlet when the child is moved from once parent to another.
175+
while (extendedChild && extendedChild.firstChild && removeGrandchildren) {
174176
const grandchild = extendedChild.firstChild;
175177
if (isLogEnabled()) {
176178
traceLog(`ViewUtil.removeChild parent: ${parent} child: ${extendedChild} grandchild: ${grandchild}`);

0 commit comments

Comments
 (0)