Skip to content

Commit 33cd058

Browse files
Hristo HristovHristo Hristov
authored andcommitted
Call loaded/unloaded on the rootView when application is resumed/suspended
Remove dead code from frame.ios
1 parent 4e74c37 commit 33cd058

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

tns-core-modules/application/application.ios.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ class IOSApplication implements IOSApplicationDefinition {
126126
const ios = utils.ios.getter(UIApplication, UIApplication.sharedApplication);
127127
const object = this;
128128
notify(<ApplicationEventData>{ eventName: resumeEvent, object, ios });
129+
const rootView = this._rootView;
130+
if (rootView && !rootView.isLoaded) {
131+
rootView.callLoaded();
132+
}
133+
129134
if (!displayedOnce) {
130135
notify(<ApplicationEventData>{ eventName: displayedEvent, object, ios });
131136
displayedOnce = true;
@@ -134,10 +139,18 @@ class IOSApplication implements IOSApplicationDefinition {
134139

135140
private didEnterBackground(notification: NSNotification) {
136141
notify(<ApplicationEventData>{ eventName: suspendEvent, object: this, ios: utils.ios.getter(UIApplication, UIApplication.sharedApplication) });
142+
const rootView = this._rootView;
143+
if (rootView && rootView.isLoaded) {
144+
rootView.callUnloaded();
145+
}
137146
}
138147

139148
private willTerminate(notification: NSNotification) {
140149
notify(<ApplicationEventData>{ eventName: exitEvent, object: this, ios: utils.ios.getter(UIApplication, UIApplication.sharedApplication) });
150+
const rootView = this._rootView;
151+
if (rootView && rootView.isLoaded) {
152+
rootView.callUnloaded();
153+
}
141154
}
142155

143156
private didReceiveMemoryWarning(notification: NSNotification) {

tns-core-modules/ui/frame/frame.ios.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,9 @@ export function reloadPage(): void {
4646

4747
export class Frame extends FrameBase {
4848
public viewController: UINavigationControllerImpl;
49-
private _ios: iOSFrame;
5049
public _animatedDelegate = <UINavigationControllerDelegate>UINavigationControllerAnimatedDelegate.new();
5150

52-
public _shouldSkipNativePop: boolean = false;
53-
public _navigateToEntry: BackstackEntry;
54-
public _widthMeasureSpec: number;
55-
public _heightMeasureSpec: number;
56-
public _right: number;
57-
public _bottom: number;
51+
private _ios: iOSFrame;
5852

5953
constructor() {
6054
super();
@@ -173,19 +167,17 @@ export class Frame extends FrameBase {
173167

174168
public _goBackCore(backstackEntry: BackstackEntry) {
175169
super._goBackCore(backstackEntry);
176-
177170
navDepth = backstackEntry[NAV_DEPTH];
178171

179-
if (!this._shouldSkipNativePop) {
180-
let controller = backstackEntry.resolvedPage.ios;
181-
let animated = this._currentEntry ? this._getIsAnimatedNavigation(this._currentEntry.entry) : false;
172+
let controller = backstackEntry.resolvedPage.ios;
173+
let animated = this._currentEntry ? this._getIsAnimatedNavigation(this._currentEntry.entry) : false;
182174

183-
this._updateActionBar(backstackEntry.resolvedPage);
184-
if (traceEnabled()) {
185-
traceWrite(`${this}.popToViewControllerAnimated(${controller}, ${animated}); depth = ${navDepth}`, traceCategories.Navigation);
186-
}
187-
this._ios.controller.popToViewControllerAnimated(controller, animated);
175+
this._updateActionBar(backstackEntry.resolvedPage);
176+
if (traceEnabled()) {
177+
traceWrite(`${this}.popToViewControllerAnimated(${controller}, ${animated}); depth = ${navDepth}`, traceCategories.Navigation);
188178
}
179+
180+
this._ios.controller.popToViewControllerAnimated(controller, animated);
189181
}
190182

191183
public _updateActionBar(page?: Page, disableNavBarAnimation: boolean = false): void {
@@ -377,11 +369,20 @@ class UINavigationControllerImpl extends UINavigationController {
377369
public viewWillAppear(animated: boolean): void {
378370
super.viewWillAppear(animated);
379371
const owner = this._owner.get();
380-
if (owner && (!owner.isLoaded && !owner.parent)) {
372+
if (owner && !owner.isLoaded && !owner.parent) {
381373
owner.callLoaded();
382374
}
383375
}
384376

377+
@profile
378+
public viewDidDisappear(animated: boolean): void {
379+
super.viewDidDisappear(animated);
380+
const owner = this._owner.get();
381+
if (owner && owner.isLoaded && !owner.parent && !this.presentedViewController) {
382+
owner.callUnloaded();
383+
}
384+
}
385+
385386
private animateWithDuration(navigationTransition: NavigationTransition,
386387
nativeTransition: UIViewAnimationTransition,
387388
transitionType: string,

0 commit comments

Comments
 (0)