10000 fix(android): dont add to parent from `_setupAsRootView` (#10554) · NativeScript/NativeScript@88a0472 · GitHub
[go: up one dir, main page]

Skip to content

Commit 88a0472

Browse files
authored
fix(android): dont add to parent from _setupAsRootView (#10554)
1 parent 12dd329 commit 88a0472

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/core/ui/core/view-base/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,17 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
10111011
// }
10121012
}
10131013

1014+
/**
1015+
* if _setupAsRootView is called it means it is not supposed to be
1016+
* added to a parent. However parent can be set before for the purpose
1017+
* of CSS variables/classes. That variable ensures that _addViewToNativeVisualTree
1018+
* is not called in _setupAsRootView
1019+
*/
1020+
mIsRootView = false;
10141021
_setupAsRootView(context: any): void {
1022+
this.mIsRootView = true;
10151023
this._setupUI(context);
1024+
this.mIsRootView = false;
10161025
}
10171026

10181027
/**
@@ -1025,7 +1034,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
10251034
// this check is unnecessary as this function should never be called when this._context === context as it means the view was somehow detached,
10261035
// which is only possible by setting reusable = true. Adding it either way for feature flag safety
10271036
if (this.reusable) {
1028-
if (this.parent && !this._isAddedToNativeVisualTree) {
1037+
if (!this.mIsRootView && this.parent && !this._isAddedToNativeVisualTree) {
10291038
const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex);
10301039
this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex);
10311040
}
@@ -1100,7 +1109,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
11001109

11011110
this.setNativeView(nativeView);
11021111

1103-
if (this.parent) {
1112+
if (!this.mIsRootView && this.parent) {
11041113
const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex);
11051114
this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex);
11061115
}

0 commit comments

Comments
 (0)
0