From d3bc4d5b82879ccb83483f99585127d981b43b38 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sun, 30 May 2021 12:02:38 -0700 Subject: [PATCH] fix(core): guard unstable page/frame init contexts under async conditions (#9428) --- packages/core/ui/action-bar/index.ios.ts | 10 ++++++---- packages/core/ui/frame/index.ios.ts | 6 ++++-- packages/core/ui/page/index.ios.ts | 4 +++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/core/ui/action-bar/index.ios.ts b/packages/core/ui/action-bar/index.ios.ts index 1deafaffe..6dc494478 100644 --- a/packages/core/ui/action-bar/index.ios.ts +++ b/packages/core/ui/action-bar/index.ios.ts @@ -353,6 +353,9 @@ export class ActionBar extends ActionBarBase { } private setColor(navBar: UINavigationBar, color?: Color) { + if (!navBar) { + return; + } if (color) { navBar.titleTextAttributes = { [NSForegroundColorAttributeName]: color.ios, @@ -443,13 +446,12 @@ export class ActionBar extends ActionBarBase { } private get navBar(): UINavigationBar { - const page = this.page; // Page should be attached to frame to update the action bar. - if (!page || !page.frame) { + if (this.page?.frame?.ios?.controller) { + return (this.page.frame.ios.controller).navigationBar; + } else { return undefined; } - - return (page.frame.ios.controller).navigationBar; } [colorProperty.getDefault](): UIColor { diff --git a/packages/core/ui/frame/index.ios.ts b/packages/core/ui/frame/index.ios.ts index 856753b7a..bc8e93171 100644 --- a/packages/core/ui/frame/index.ios.ts +++ b/packages/core/ui/frame/index.ios.ts @@ -224,7 +224,7 @@ export class Frame extends FrameBase { this._ios._disableNavBarAnimation = disableNavBarAnimationCache; } - if (this._ios.controller.navigationBar) { + if (this._ios.controller?.navigationBar) { this._ios.controller.navigationBar.userInteractionEnabled = this.navigationQueueIsEmpty(); } @@ -666,7 +666,9 @@ class iOSFrame implements iOSFrameDefinition { } public set showNavigationBar(value: boolean) { this._showNavigationBar = value; - this._controller.setNavigationBarHiddenAnimated(!value, !this._disableNavBarAnimation); + if (this._controller) { + this._controller.setNavigationBarHiddenAnimated(!value, !this._disableNavBarAnimation); + } } public get navBarVisibility(): 'auto' | 'never' | 'always' { diff --git a/packages/core/ui/page/index.ios.ts b/packages/core/ui/page/index.ios.ts index 68f0f9bcc..42e54f8cf 100644 --- a/packages/core/ui/page/index.ios.ts +++ b/packages/core/ui/page/index.ios.ts @@ -177,7 +177,9 @@ class UIViewControllerImpl extends UIViewController { } // If page was shown with custom animation - we need to set the navigationController.delegate to the animatedDelegate. - frame.ios.controller.delegate = this[DELEGATE]; + if (frame.ios?.controller) { + frame.ios.controller.delegate = this[DELEGATE]; + } frame._processNavigationQueue(owner);