From 4551da075b074f4c67da52f5279e2823169731ec Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 24 Apr 2023 13:45:31 -0700 Subject: [PATCH] fix(ios): resilience to nativeView access under edge cases (#10276) --- packages/core/ui/core/view/index.ios.ts | 22 ++++++++++++--------- packages/core/ui/layouts/layout-base.ios.ts | 4 +++- packages/core/ui/list-view/index.ios.ts | 4 +++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/core/ui/core/view/index.ios.ts b/packages/core/ui/core/view/index.ios.ts index 2c05682bf..f30052e5b 100644 --- a/packages/core/ui/core/view/index.ios.ts +++ b/packages/core/ui/core/view/index.ios.ts @@ -898,13 +898,15 @@ export class View extends ViewCommon implements ViewDefinition { CATransaction.begin(); } - if (value instanceof UIColor) { - this.nativeViewProtected.backgroundColor = value; - } else { - iosBackground.createBackgroundUIColor(this, (color: UIColor) => { - this.nativeViewProtected.backgroundColor = color; - }); - this._setNativeClipToBounds(); + if (this.nativeViewProtected) { + if (value instanceof UIColor) { + this.nativeViewProtected.backgroundColor = value; + } else { + iosBackground.createBackgroundUIColor(this, (color: UIColor) => { + this.nativeViewProtected.backgroundColor = color; + }); + this._setNativeClipToBounds(); + } } if (!updateSuspended) { @@ -915,8 +917,10 @@ export class View extends ViewCommon implements ViewDefinition { } _setNativeClipToBounds() { - const backgroundInternal = this.style.backgroundInternal; - this.nativeViewProtected.clipsToBounds = (this.nativeViewProtected instanceof UIScrollView || backgroundInternal.hasBorderWidth() || backgroundInternal.hasBorderRadius()) && !backgroundInternal.hasBoxShadow(); + if (this.nativeViewProtected) { + const backgroundInternal = this.style.backgroundInternal; + this.nativeViewProtected.clipsToBounds = (this.nativeViewProtected instanceof UIScrollView || backgroundInternal.hasBorderWidth() || backgroundInternal.hasBorderRadius()) && !backgroundInternal.hasBoxShadow(); + } } private _setupPopoverControllerDelegate(controller: UIViewController, parent: View) { diff --git a/packages/core/ui/layouts/layout-base.ios.ts b/packages/core/ui/layouts/layout-base.ios.ts index a7eb4205f..e6a8e3cbc 100644 --- a/packages/core/ui/layouts/layout-base.ios.ts +++ b/packages/core/ui/layouts/layout-base.ios.ts @@ -23,7 +23,9 @@ export class LayoutBase extends LayoutBaseCommon { _setNativeClipToBounds() { if (this.clipToBounds) { - this.nativeViewProtected.clipsToBounds = true; + if (this.nativeViewProtected) { + this.nativeViewProtected.clipsToBounds = true; + } } else { super._setNativeClipToBounds(); } diff --git a/packages/core/ui/list-view/index.ios.ts b/packages/core/ui/list-view/index.ios.ts index 71b6993bd..790abf1ed 100644 --- a/packages/core/ui/list-view/index.ios.ts +++ b/packages/core/ui/list-view/index.ios.ts @@ -275,7 +275,9 @@ export class ListView extends ListViewBase { _setNativeClipToBounds() { // Always set clipsToBounds for list-view - this.ios.clipsToBounds = true; + if (this.ios) { + this.ios.clipsToBounds = true; + } } @profile