Skip to content

Commit f04b5ee

Browse files
authored
refactor: set parentNode property to ViewBase (NativeScript#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.
1 parent 8973a6f commit f04b5ee

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tns-core-modules/ui/core/view-base/view-base.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ export abstract class ViewBase extends Observable {
157157
*/
158158
public readonly parent: ViewBase;
159159

160+
/**
161+
* Gets the template parent or the native parent. Sets the template parent.
162+
*/
163+
public parentNode: ViewBase;
164+
160165
/**
161166
* Gets or sets the id for this view.
162167
*/

tns-core-modules/ui/core/view-base/view-base.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
149149
private _style: Style;
150150
private _isLoaded: boolean;
151151
private _visualState: string;
152+
private _templateParent: ViewBase;
152153
private __nativeView: any;
153154
// private _disableNativeViewRecycling: boolean;
154155
public domNode: dnm.DOMNode;
@@ -221,6 +222,14 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
221222
this._style = new Style(this);
222223
}
223224

225+
get parentNode() {
226+
return this._templateParent || this.parent;
227+
}
228+
229+
set parentNode(node: ViewBase) {
230+
this._templateParent = node;
231+
}
232+
224233
get nativeView(): any {
225234
// this._disableNativeViewRecycling = true;
226235
return this.nativeViewProtected;

0 commit comments

Comments
 (0)