From 88a047254bb9542106f52a204930342a76dbdded Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Fri, 28 Jun 2024 22:44:36 +0200 Subject: [PATCH] fix(android): dont add to parent from `_setupAsRootView` (#10554) --- packages/core/ui/core/view-base/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core/ui/core/view-base/index.ts b/packages/core/ui/core/view-base/index.ts index daab36d9e..aeea90503 100644 --- a/packages/core/ui/core/view-base/index.ts +++ b/packages/core/ui/core/view-base/index.ts @@ -1011,8 +1011,17 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition // } } + /** + * if _setupAsRootView is called it means it is not supposed to be + * added to a parent. However parent can be set before for the purpose + * of CSS variables/classes. That variable ensures that _addViewToNativeVisualTree + * is not called in _setupAsRootView + */ + mIsRootView = false; _setupAsRootView(context: any): void { + this.mIsRootView = true; this._setupUI(context); + this.mIsRootView = false; } /** @@ -1025,7 +1034,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition // this check is unnecessary as this function should never be called when this._context === context as it means the view was somehow detached, // which is only possible by setting reusable = true. Adding it either way for feature flag safety if (this.reusable) { - if (this.parent && !this._isAddedToNativeVisualTree) { + if (!this.mIsRootView && this.parent && !this._isAddedToNativeVisualTree) { const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex); this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex); } @@ -1100,7 +1109,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition this.setNativeView(nativeView); - if (this.parent) { + if (!this.mIsRootView && this.parent) { const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex); this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex); }