From f04b5eecd5292f4b42d0e9e8d7626b2cc1561574 Mon Sep 17 00:00:00 2001 From: Stanimira Vlaeva Date: Thu, 7 Dec 2017 07:09:30 -0800 Subject: [PATCH] refactor: set parentNode property to ViewBase (#5134) Setter: You can set a '_templateParent' by setting node.parentNode. This won't affect the native parent of the node. Getter: Returns '_templateParent', if set, or the native parent otherwise. Reason: This will help us remove that abstraction from nativescript-angular as it matches the DOM Nodes API name. --- tns-core-modules/ui/core/view-base/view-base.d.ts | 5 +++++ tns-core-modules/ui/core/view-base/view-base.ts | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/tns-core-modules/ui/core/view-base/view-base.d.ts b/tns-core-modules/ui/core/view-base/view-base.d.ts index 8c5f7e280..34a79edcd 100644 --- a/tns-core-modules/ui/core/view-base/view-base.d.ts +++ b/tns-core-modules/ui/core/view-base/view-base.d.ts @@ -157,6 +157,11 @@ export abstract class ViewBase extends Observable { */ public readonly parent: ViewBase; + /** + * Gets the template parent or the native parent. Sets the template parent. + */ + public parentNode: ViewBase; + /** * Gets or sets the id for this view. */ diff --git a/tns-core-modules/ui/core/view-base/view-base.ts b/tns-core-modules/ui/core/view-base/view-base.ts index bdbdee00b..632215e52 100644 --- a/tns-core-modules/ui/core/view-base/view-base.ts +++ b/tns-core-modules/ui/core/view-base/view-base.ts @@ -149,6 +149,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition private _style: Style; private _isLoaded: boolean; private _visualState: string; + private _templateParent: ViewBase; private __nativeView: any; // private _disableNativeViewRecycling: boolean; public domNode: dnm.DOMNode; @@ -221,6 +222,14 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition this._style = new Style(this); } + get parentNode() { + return this._templateParent || this.parent; + } + + set parentNode(node: ViewBase) { + this._templateParent = node; + } + get nativeView(): any { // this._disableNativeViewRecycling = true; return this.nativeViewProtected;