mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
fix(android): dont add to parent from _setupAsRootView
(#10554)
This commit is contained in:
@ -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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user