Skip to content

Commit 451ffe1

Browse files
manucorporatadamdbradley
authored andcommitted
fix(nav): ionViewDidLoad is called in modals
fixes #8449
1 parent 8f39fec commit 451ffe1

File tree

6 files changed

+115
-53
lines changed

6 files changed

+115
-53
lines changed

src/components/loading/loading-component.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Config } from '../../config/config';
44
import { isDefined, isUndefined } from '../../util/util';
55
import { NavParams } from '../../navigation/nav-params';
66
import { ViewController } from '../../navigation/view-controller';
7-
7+
import { LoadingOptions } from './loading-options';
88

99
/**
1010
* @private
@@ -25,15 +25,7 @@ import { ViewController } from '../../navigation/view-controller';
2525
encapsulation: ViewEncapsulation.None,
2626
})
2727
export class LoadingCmp {
28-
d: {
29-
spinner?: string;
30-
content?: string;
31-
cssClass?: string;
32-
showBackdrop?: boolean;
33-
dismissOnPageChange?: boolean;
34-
delay?: number;
35-
duration?: number;
36-
};
28+
d: LoadingOptions;
3729
id: number;
3830
showSpinner: boolean;
3931
durationTimeout: number;

src/components/modal/modal-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class ModalCmp {
3030
this._bdDismiss = _navParams.data.opts.enableBackdropDismiss;
3131
}
3232

33-
ngAfterViewInit() {
33+
ionViewWillLoad() {
3434
this._load(this._navParams.data.component);
3535
}
3636

src/components/modal/test/basic/app-module.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,18 @@ export class E2EPage {
130130
</ion-item>
131131
</ion-list>
132132
<button ion-button full (click)="submit()">Submit</button>
133+
<p>ionViewDidLoad ({{called.ionViewDidLoad}})</p>
134+
<p>ionViewWillEnter ({{called.ionViewWillEnter}})</p>
135+
<p>ionViewDidEnter ({{called.ionViewDidEnter}})</p>
136+
<p>ionViewWillLeave ({{called.ionViewWillLeave}})</p>
137+
<p>ionViewDidLeave ({{called.ionViewDidLeave}})</p>
133138
</ion-content>
134139
`,
135140
providers: [SomeComponentProvider]
136141
})
137142
export class ModalPassData {
138143
data: any;
144+
called: any;
139145

140146
constructor(
141147
public viewCtrl: ViewController,
@@ -148,6 +154,14 @@ export class ModalPassData {
148154
name: someComponentProvider.getName()
149155
};
150156
console.log('SomeAppProvider Data', someAppProvider.getData());
157+
158+
this.called = {
159+
ionViewDidLoad: 0,
160+
ionViewWillEnter: 0,
161+
ionViewDidEnter: 0,
162+
ionViewWillLeave: 0,
163+
ionViewDidLeave: 0
164+
};
151165
}
152166

153167
submit() {
@@ -157,10 +171,12 @@ export class ModalPassData {
157171

158172
ionViewDidLoad() {
159173
console.log('ModalPassData ionViewDidLoad fired');
174+
this.called.ionViewDidLoad++;
160175
}
161176

162177
ionViewWillEnter() {
163178
console.log('ModalPassData ionViewWillEnter fired');
179+
this.called.ionViewWillEnter++;
164180
}
165181

166182
ionViewDidEnter() {
@@ -169,14 +185,17 @@ export class ModalPassData {
169185
message: 'test toast',
170186
duration: 1000
171187
}).present();
188+
this.called.ionViewDidEnter++;
172189
}
173190

174191
ionViewWillLeave() {
175192
console.log('ModalPassData ionViewWillLeave fired');
193+
this.called.ionViewWillLeave++;
176194
}
177195

178196
ionViewDidLeave() {
179197
console.log('ModalPassData ionViewDidLeave fired');
198+
this.called.ionViewDidLeave++;
180199
}
181200
}
182201

@@ -341,6 +360,11 @@ export class ContactUs {
341360
<p>
342361
<button ion-button (click)="openActionSheet()">Open Action Sheet</button>
343362
</p>
363+
<p>ionViewDidLoad ({{called.ionViewDidLoad}})</p>
364+
<p>ionViewWillEnter ({{called.ionViewWillEnter}})</p>
365+
<p>ionViewDidEnter ({{called.ionViewDidEnter}})</p>
366+
<p>ionViewWillLeave ({{called.ionViewWillLeave}})</p>
367+
<p>ionViewDidLeave ({{called.ionViewDidLeave}})</p>
344368
<div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div>
345369
<div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div>
346370
<ion-list>
@@ -353,6 +377,7 @@ export class ContactUs {
353377
})
354378
export class ModalFirstPage {
355379
items: any[] = [];
380+
called: any;
356381

357382
constructor(
358383
public navCtrl: NavController,
@@ -364,6 +389,14 @@ export class ModalFirstPage {
364389
value: (i + 1)
365390
});
366391
}
392+
393+
this.called = {
394+
ionViewDidLoad: 0,
395+
ionViewWillEnter: 0,
396+
ionViewDidEnter: 0,
397+
ionViewWillLeave: 0,
398+
ionViewDidLeave: 0
399+
};
367400
}
368401

369402
push() {
@@ -379,10 +412,12 @@ export class ModalFirstPage {
379412

380413
ionViewDidLoad() {
381414
console.log('ModalFirstPage ionViewDidLoad fired');
415+
this.called.ionViewDidLoad++;
382416
}
383417

384418
ionViewWillEnter() {
385419
console.log('ModalFirstPage ionViewWillEnter fired');
420+
this.called.ionViewWillEnter++;
386421
}
387422

388423
ionViewDidEnter() {
@@ -397,6 +432,15 @@ export class ModalFirstPage {
397432
]
398433
});
399434
alert.present();
435+
this.called.ionViewDidEnter++;
436+
}
437+
438+
ionViewWillLeave() {
439+
this.called.ionViewWillLeave++;
440+
}
441+
442+
ionViewDidLeave() {
443+
this.called.ionViewDidLeave++;
400444
}
401445

402446
openActionSheet() {

src/components/popover/popover-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class PopoverCmp {
6060
this.id = (++popoverIds);
6161
}
6262

63-
ngAfterViewInit() {
63+
ionViewWillLoad() {
6464
let activeElement: any = document.activeElement;
6565
if (document.activeElement) {
6666
activeElement.blur();

src/navigation/nav-controller-base.ts

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,20 @@ export class NavControllerBase extends Ion implements NavController {
187187
}
188188

189189
ti.resolve = (hasCompleted: boolean, isAsync: boolean, enteringName: string, leavingName: string, direction: string) => {
190+
this.setTransitioning(false);
191+
190192
// transition has successfully resolved
191193
this._trnsId = null;
192194
resolve && resolve(hasCompleted, isAsync, enteringName, leavingName, direction);
193195
this._sbCheck();
194196

195197
// let's see if there's another to kick off
196-
this.setTransitioning(false);
197198
this._nextTrns();
198199
};
199200

200201
ti.reject = (rejectReason: any, trns: Transition) => {
202+
this.setTransitioning(false);
203+
201204
// rut row raggy, something rejected this transition
202205
this._trnsId = null;
203206
this._queue.length = 0;
@@ -218,7 +221,6 @@ export class NavControllerBase extends Ion implements NavController {
218221

219222
reject && reject(false, false, rejectReason);
220223

221-
this.setTransitioning(false);
222224
this._nextTrns();
223225
};
224226

@@ -390,17 +392,9 @@ export class NavControllerBase extends Ion implements NavController {
390392
// batch all of lifecycles together
391393
var view = destroyQueue[i];
392394
if (view && view !== enteringView && view !== leavingView) {
393-
view._willLeave();
394-
this.viewWillLeave.emit(view);
395-
this._app.viewWillLeave.emit(view);
396-
397-
view._didLeave();
398-
this.viewDidLeave.emit(view);
399-
this._app.viewDidLeave.emit(view);
400-
401-
view._willUnload();
402-
this.viewWillUnload.emit(view);
403-
this._app.viewWillUnload.emit(view);
395+
this._willLeave(view);
396+
this._didLeave(view);
397+
this._willUnload(view);
404398
}
405399
}
406400
for (var i = 0; i < destroyQueue.length; i++) {
@@ -571,20 +565,19 @@ export class NavControllerBase extends Ion implements NavController {
571565

572566
_viewInsert(view: ViewController, componentRef: ComponentRef<any>, viewport: ViewContainerRef) {
573567
// successfully finished loading the entering view
574-
// fire off the "loaded" lifecycle events
575-
view._didLoad();
576-
this.viewDidLoad.emit(view);
577-
this._app.viewDidLoad.emit(view);
568+
// fire off the "didLoad" lifecycle events
569+
this._willLoad(view);
570+
this._didLoad(view);
578571

579572
// render the component ref instance to the DOM
580573
// ******** DOM WRITE ****************
581574
viewport.insert(componentRef.hostView, viewport.length);
582575
view._state = ViewState.PRE_RENDERED;
583576

584-
// the ElementRef of the actual ion-page created
585-
const pageElement = componentRef.location.nativeElement;
586-
587577
if (view._cssClass) {
578+
// the ElementRef of the actual ion-page created
579+
var pageElement = componentRef.location.nativeElement;
580+
588581
// ******** DOM WRITE ****************
589582
this._renderer.setElementClass(pageElement, view._cssClass, true);
590583
}
@@ -666,17 +659,8 @@ export class NavControllerBase extends Ion implements NavController {
666659

667660
_viewsWillLifecycles(enteringView: ViewController, leavingView: ViewController) {
668661
// call each view's lifecycle events
669-
if (enteringView) {
670-
enteringView._willEnter();
671-
this.viewWillEnter.emit(enteringView);
672-
this._app.viewWillEnter.emit(enteringView);
673-
}
674-
675-
if (leavingView) {
676-
leavingView._willLeave();
677-
this.viewWillLeave.emit(leavingView);
678-
this._app.viewWillLeave.emit(leavingView);
679-
}
662+
enteringView && this._willEnter(enteringView);
663+
leavingView && this._willLeave(leavingView);
680664
}
681665

682666
_trnsFinish(trns: Transition, opts: NavOptions, resolve: TransitionResolveFn) {
@@ -690,16 +674,12 @@ export class NavControllerBase extends Ion implements NavController {
690674
// transition has completed (went from 0 to 1)
691675
if (trns.enteringView) {
692676
enteringName = trns.enteringView.name;
693-
trns.enteringView._didEnter();
694-
this.viewDidEnter.emit(trns.enteringView);
695-
this._app.viewDidEnter.emit(trns.enteringView);
677+
this._didEnter(trns.enteringView);
696678
}
697679

698680
if (trns.leavingView) {
699681
leavingName = trns.leavingView.name;
700-
trns.leavingView._didLeave();
701-
this.viewDidLeave.emit(trns.leavingView);
702-
this._app.viewDidLeave.emit(trns.leavingView);
682+
this._didLeave(trns.leavingView);
703683
}
704684

705685
this._cleanup(trns.enteringView);
@@ -744,9 +724,7 @@ export class NavControllerBase extends Ion implements NavController {
744724
if (i > activeViewIndex) {
745725
// this view comes after the active view
746726
// let's unload it
747-
view._willUnload();
748-
this.viewWillUnload.emit(view);
749-
this._app.viewWillUnload.emit(view);
727+
this._willUnload(view);
750728
view._destroy(this._renderer);
751729

752730
} else if (i < activeViewIndex && !this._isPortal) {
@@ -769,6 +747,47 @@ export class NavControllerBase extends Ion implements NavController {
769747
}
770748
}
771749

750+
_willLoad(view: ViewController) {
751+
view._willLoad();
752+
}
753+
754+
_didLoad(view: ViewController) {
755+
view._didLoad();
756+
this.viewDidLoad.emit(view);
757+
this._app.viewDidLoad.emit(view);
758+
}
759+
760+
_willEnter(view: ViewController) {
761+
view._willEnter();
762+
this.viewWillEnter.emit(view);
763+
this._app.viewWillEnter.emit(view);
764+
}
765+
766+
_didEnter(view: ViewController) {
767+
view._didEnter();
768+
this.viewDidEnter.emit(view);
769+
this._app.viewDidEnter.emit(view);
770+
}
771+
772+
_willLeave(view: ViewController) {
773+
view._willLeave();
774+
this.viewWillLeave.emit(view);
775+
this._app.viewWillLeave.emit(view);
776+
}
777+
778+
_didLeave(view: ViewController) {
779+
view._didLeave();
780+
this.viewDidLeave.emit(view);
781+
this._app.viewDidLeave.emit(view);
782+
}
783+
784+
_willUnload(view: ViewController) {
785+
view._willUnload();
786+
this.viewWillUnload.emit(view);
787+
this._app.viewWillUnload.emit(view);
788+
}
789+
790+
772791
getActiveChildNav(): any {
773792
return this._children[this._children.length - 1];
774793
}
@@ -980,4 +999,4 @@ let ctrlIds = -1;
980999

9811000
const DISABLE_APP_MINIMUM_DURATION = 64;
9821001
const ACTIVE_TRANSITION_MAX_TIME = 5000;
983-
const ACTIVE_TRANSITION_OFFSET = 400;
1002+
const ACTIVE_TRANSITION_OFFSET = 2000;

src/navigation/view-controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ export class ViewController {
408408
}
409409
}
410410

411+
/**
412+
* @private
413+
*/
414+
_willLoad() {
415+
ctrlFn(this, 'WillLoad');
416+
}
417+
411418
/**
412419
* @private
413420
* The view has loaded. This event only happens once per view being

0 commit comments

Comments
 (0)