fix(android): dont add to parent from _setupAsRootView (#10554)

This commit is contained in:
farfromrefuge
2024-06-28 22:44:36 +02:00
committed by GitHub
parent 12dd329ed1
commit 88a047254b

View File

@ -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 { _setupAsRootView(context: any): void {
this.mIsRootView = true;
this._setupUI(context); 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, // 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 // which is only possible by setting reusable = true. Adding it either way for feature flag safety
if (this.reusable) { if (this.reusable) {
if (this.parent && !this._isAddedToNativeVisualTree) { if (!this.mIsRootView && this.parent && !this._isAddedToNativeVisualTree) {
const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex); const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex);
this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex); this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex);
} }
@ -1100,7 +1109,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
this.setNativeView(nativeView); this.setNativeView(nativeView);
if (this.parent) { if (!this.mIsRootView && this.parent) {
const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex); const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex);
this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex); this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex);
} }