From 33cd05871884a164eaf2f984e898862aa9944232 Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Fri, 15 Dec 2017 15:26:23 +0200 Subject: [PATCH] Call loaded/unloaded on the rootView when application is resumed/suspended Remove dead code from frame.ios --- .../application/application.ios.ts | 13 +++++++ tns-core-modules/ui/frame/frame.ios.ts | 35 ++++++++++--------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/tns-core-modules/application/application.ios.ts b/tns-core-modules/application/application.ios.ts index a9e1f04c7..8d8d1d38c 100644 --- a/tns-core-modules/application/application.ios.ts +++ b/tns-core-modules/application/application.ios.ts @@ -126,6 +126,11 @@ class IOSApplication implements IOSApplicationDefinition { const ios = utils.ios.getter(UIApplication, UIApplication.sharedApplication); const object = this; notify({ eventName: resumeEvent, object, ios }); + const rootView = this._rootView; + if (rootView && !rootView.isLoaded) { + rootView.callLoaded(); + } + if (!displayedOnce) { notify({ eventName: displayedEvent, object, ios }); displayedOnce = true; @@ -134,10 +139,18 @@ class IOSApplication implements IOSApplicationDefinition { private didEnterBackground(notification: NSNotification) { notify({ eventName: suspendEvent, object: this, ios: utils.ios.getter(UIApplication, UIApplication.sharedApplication) }); + const rootView = this._rootView; + if (rootView && rootView.isLoaded) { + rootView.callUnloaded(); + } } private willTerminate(notification: NSNotification) { notify({ eventName: exitEvent, object: this, ios: utils.ios.getter(UIApplication, UIApplication.sharedApplication) }); + const rootView = this._rootView; + if (rootView && rootView.isLoaded) { + rootView.callUnloaded(); + } } private didReceiveMemoryWarning(notification: NSNotification) { diff --git a/tns-core-modules/ui/frame/frame.ios.ts b/tns-core-modules/ui/frame/frame.ios.ts index fc8627f51..0a9039e90 100644 --- a/tns-core-modules/ui/frame/frame.ios.ts +++ b/tns-core-modules/ui/frame/frame.ios.ts @@ -46,15 +46,9 @@ export function reloadPage(): void { export class Frame extends FrameBase { public viewController: UINavigationControllerImpl; - private _ios: iOSFrame; public _animatedDelegate = UINavigationControllerAnimatedDelegate.new(); - public _shouldSkipNativePop: boolean = false; - public _navigateToEntry: BackstackEntry; - public _widthMeasureSpec: number; - public _heightMeasureSpec: number; - public _right: number; - public _bottom: number; + private _ios: iOSFrame; constructor() { super(); @@ -173,19 +167,17 @@ export class Frame extends FrameBase { public _goBackCore(backstackEntry: BackstackEntry) { super._goBackCore(backstackEntry); - navDepth = backstackEntry[NAV_DEPTH]; - if (!this._shouldSkipNativePop) { - let controller = backstackEntry.resolvedPage.ios; - let animated = this._currentEntry ? this._getIsAnimatedNavigation(this._currentEntry.entry) : false; + let controller = backstackEntry.resolvedPage.ios; + let animated = this._currentEntry ? this._getIsAnimatedNavigation(this._currentEntry.entry) : false; - this._updateActionBar(backstackEntry.resolvedPage); - if (traceEnabled()) { - traceWrite(`${this}.popToViewControllerAnimated(${controller}, ${animated}); depth = ${navDepth}`, traceCategories.Navigation); - } - this._ios.controller.popToViewControllerAnimated(controller, animated); + this._updateActionBar(backstackEntry.resolvedPage); + if (traceEnabled()) { + traceWrite(`${this}.popToViewControllerAnimated(${controller}, ${animated}); depth = ${navDepth}`, traceCategories.Navigation); } + + this._ios.controller.popToViewControllerAnimated(controller, animated); } public _updateActionBar(page?: Page, disableNavBarAnimation: boolean = false): void { @@ -377,11 +369,20 @@ class UINavigationControllerImpl extends UINavigationController { public viewWillAppear(animated: boolean): void { super.viewWillAppear(animated); const owner = this._owner.get(); - if (owner && (!owner.isLoaded && !owner.parent)) { + if (owner && !owner.isLoaded && !owner.parent) { owner.callLoaded(); } } + @profile + public viewDidDisappear(animated: boolean): void { + super.viewDidDisappear(animated); + const owner = this._owner.get(); + if (owner && owner.isLoaded && !owner.parent && !this.presentedViewController) { + owner.callUnloaded(); + } + } + private animateWithDuration(navigationTransition: NavigationTransition, nativeTransition: UIViewAnimationTransition, transitionType: string,