Skip to content

Commit 033e1ea

Browse files
manucorporatadamdbradley
authored andcommitted
fix(nav): adds public willLoad lifecycle event
* fix(nav): adds public willLoad lifecycle event * test(menu): adds more asserts
1 parent 504e6e0 commit 033e1ea

File tree

9 files changed

+195
-26
lines changed

9 files changed

+195
-26
lines changed

src/components/menu/menu.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, ContentChild, ElementRef, EventEmit
22

33
import { Backdrop } from '../backdrop/backdrop';
44
import { Config } from '../../config/config';
5-
import { isTrueProperty } from '../../util/util';
5+
import { isTrueProperty, assert } from '../../util/util';
66
import { Keyboard } from '../../util/keyboard';
77
import { MenuContentGesture } from './menu-gestures';
88
import { MenuController } from './menu-controller';
@@ -192,7 +192,6 @@ export class Menu {
192192
private _cntEle: HTMLElement;
193193
private _cntGesture: MenuContentGesture;
194194
private _type: MenuType;
195-
private _resizeUnreg: Function;
196195
private _isEnabled: boolean = true;
197196
private _isSwipeEnabled: boolean = true;
198197
private _isAnimating: boolean = false;
@@ -472,6 +471,8 @@ export class Menu {
472471
}
473472

474473
private _before() {
474+
assert(this._isAnimating === false, '_before should be called when we are not animating');
475+
475476
// this places the menu into the correct location before it animates in
476477
// this css class doesn't actually kick off any animations
477478
this.menuContent && this.menuContent.resize();
@@ -482,6 +483,8 @@ export class Menu {
482483
}
483484

484485
private _after(isOpen: boolean) {
486+
assert(this._isAnimating === true, '_after should be called when we are animating');
487+
485488
// keep opening/closing the menu disabled for a touch more yet
486489
// only add listeners/css if it's enabled and isOpen
487490
// and only remove listeners/css if it's not open
@@ -516,21 +519,21 @@ export class Menu {
516519
/**
517520
* @private
518521
*/
519-
open() {
522+
open(): Promise<boolean> {
520523
return this.setOpen(true);
521524
}
522525

523526
/**
524527
* @private
525528
*/
526-
close() {
529+
close(): Promise<boolean> {
527530
return this.setOpen(false);
528531
}
529532

530533
/**
531534
* @private
532535
*/
533-
toggle() {
536+
toggle(): Promise<boolean> {
534537
return this.setOpen(!this.isOpen);
535538
}
536539

@@ -633,12 +636,10 @@ export class Menu {
633636
this._events.unlistenAll();
634637
this._cntGesture && this._cntGesture.destroy();
635638
this._type && this._type.destroy();
636-
this._resizeUnreg && this._resizeUnreg();
637639

638640
this._cntGesture = null;
639641
this._type = null;
640642
this._cntEle = null;
641-
this._resizeUnreg = null;
642643
}
643644

644645
}

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-
ionViewWillLoad() {
33+
ionViewPreLoad() {
3434
this._load(this._navParams.data.component);
3535
}
3636

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export class E2EPage {
149149
<button ion-button full (click)="submit()">Submit</button>
150150
<p>ionViewCanEnter ({{called.ionViewCanEnter}})</p>
151151
<p>ionViewCanLeave ({{called.ionViewCanLeave}})</p>
152+
<p>ionViewWillLoad ({{called.ionViewWillLoad}})</p>
152153
<p>ionViewDidLoad ({{called.ionViewDidLoad}})</p>
153154
<p>ionViewWillEnter ({{called.ionViewWillEnter}})</p>
154155
<p>ionViewDidEnter ({{called.ionViewDidEnter}})</p>
@@ -178,6 +179,7 @@ export class ModalPassData {
178179
this.called = {
179180
ionViewCanEnter: 0,
180181
ionViewCanLeave: 0,
182+
ionViewWillLoad: 0,
181183
ionViewDidLoad: 0,
182184
ionViewWillEnter: 0,
183185
ionViewDidEnter: 0,
@@ -213,6 +215,11 @@ export class ModalPassData {
213215
});
214216
}
215217

218+
ionViewWillLoad() {
219+
console.log('ModalPassData ionViewWillLoad fired');
220+
this.called.ionViewWillLoad++;
221+
}
222+
216223
ionViewDidLoad() {
217224
console.log('ModalPassData ionViewDidLoad fired');
218225
this.called.ionViewDidLoad++;
@@ -400,6 +407,7 @@ export class ContactUs {
400407
<ion-content padding>
401408
<p>ionViewCanEnter ({{called.ionViewCanEnter}})</p>
402409
<p>ionViewCanLeave ({{called.ionViewCanLeave}})</p>
410+
<p>ionViewWillLoad ({{called.ionViewWillLoad}})</p>
403411
<p>ionViewDidLoad ({{called.ionViewDidLoad}})</p>
404412
<p>ionViewWillEnter ({{called.ionViewWillEnter}})</p>
405413
<p>ionViewDidEnter ({{called.ionViewDidEnter}})</p>
@@ -441,6 +449,7 @@ export class ModalFirstPage {
441449
this.called = {
442450
ionViewCanEnter: 0,
443451
ionViewCanLeave: 0,
452+
ionViewWillLoad: 0,
444453
ionViewDidLoad: 0,
445454
ionViewWillEnter: 0,
446455
ionViewDidEnter: 0,
@@ -479,6 +488,11 @@ export class ModalFirstPage {
479488
return true;
480489
}
481490

491+
ionViewWillLoad() {
492+
console.log('ModalFirstPage ionViewWillLoad fired');
493+
this.called.ionViewWillLoad++;
494+
}
495+
482496
ionViewDidLoad() {
483497
console.log('ModalFirstPage ionViewDidLoad fired');
484498
this.called.ionViewDidLoad++;

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import { NgModule, Component, ViewChild } from '@angular/core';
2-
import { App, AlertController, Content, DeepLinkConfig, IonicApp, IonicModule, Label, NavController, NavParams, Tabs, Tab, ModalController, ViewController } from '../../../..';
2+
import { App, AlertController, Content, DeepLinkConfig, IonicApp, IonicModule, NavController, NavParams, Tabs, Tab, ModalController, ViewController } from '../../../..';
3+
4+
@Component({
5+
selector: 'my-cmp2',
6+
template: `<span style="color:green">{{value}}</span>`
7+
})
8+
export class MyCmpTest2 {
9+
value: string = 'Test Failed';
10+
}
311

412
@Component({
513
selector: 'my-cmp',
6-
template: `<ion-label>My Custom Component Test <ion-icon name="star"></ion-icon>
7-
<span style="color:green">{{value}}</span></ion-label>`
14+
template: `<my-cmp2></my-cmp2> <span style="color:green">{{value}}</span>`
815
})
916
export class MyCmpTest {
10-
@ViewChild(Label) _label: Label;
11-
label: Label;
12-
value: string = '';
17+
@ViewChild(MyCmpTest2) _label: MyCmpTest2;
18+
label: MyCmpTest2;
19+
value: string = 'Test Failed';
1320

1421
ngOnInit() {
1522
this.label = this._label;
@@ -34,6 +41,7 @@ export class MyCmpTest {
3441
<div padding>
3542
<p>ionViewCanEnter ({{called.ionViewCanEnter}})</p>
3643
<p>ionViewCanLeave ({{called.ionViewCanLeave}})</p>
44+
<p>ionViewWillLoad ({{called.ionViewWillLoad}})</p>
3745
<p>ionViewDidLoad ({{called.ionViewDidLoad}})</p>
3846
<p>ionViewWillEnter ({{called.ionViewWillEnter}})</p>
3947
<p>ionViewDidEnter ({{called.ionViewDidEnter}})</p>
@@ -91,6 +99,7 @@ export class FirstPage {
9199
this.called = {
92100
ionViewCanEnter: 0,
93101
ionViewCanLeave: 0,
102+
ionViewWillLoad: 0,
94103
ionViewDidLoad: 0,
95104
ionViewWillEnter: 0,
96105
ionViewDidEnter: 0,
@@ -104,11 +113,11 @@ export class FirstPage {
104113
for (var i = 1; i <= 50; i++) {
105114
this.pages.push(i);
106115
}
107-
// if (!this.myCmp || !this.content || !this.myCmp.label) {
108-
// throw new Error('children are not loaded');
109-
// }
110-
this.myCmp.value = 'root!';
111-
// this.myCmp.label.color = 'primary';
116+
if (!this.myCmp || !this.content || !this.myCmp.label) {
117+
throw new Error('children are not loaded');
118+
}
119+
this.myCmp.value = '👍 self test passed!';
120+
this.myCmp.label.value = '👍 children test passed!';
112121
this.called.ionViewDidLoad++;
113122
}
114123

@@ -810,6 +819,7 @@ export const deepLinkConfig: DeepLinkConfig = {
810819
RedirectPage,
811820
AnotherPage,
812821
MyCmpTest,
822+
MyCmpTest2,
813823
FullPage,
814824
PrimaryHeaderPage,
815825
TabsPage,

src/components/picker/picker-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ export class PickerCmp {
423423
this.lastClick = 0;
424424
}
425425

426-
ionViewDidLoad() {
426+
ionViewWillLoad() {
427427
// normalize the data
428428
let data = this.d;
429429

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-
ionViewWillLoad() {
63+
ionViewPreLoad() {
6464
let activeElement: any = document.activeElement;
6565
if (document.activeElement) {
6666
activeElement.blur();
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { Component, NgModule } from '@angular/core';
2+
import { IonicApp, IonicModule, NavController, AlertController } from '../../../..';
3+
4+
//
5+
// Tab 1
6+
//
7+
@Component({
8+
template: `
9+
<ion-header>
10+
<ion-navbar>
11+
<ion-title>Lifecyles</ion-title>
12+
</ion-navbar>
13+
</ion-header>
14+
15+
<ion-content padding>
16+
<p>ionViewCanEnter ({{called.ionViewCanEnter}})</p>
17+
<p>ionViewCanLeave ({{called.ionViewCanLeave}})</p>
18+
<p>ionViewWillLoad ({{called.ionViewWillLoad}})</p>
19+
<p>ionViewDidLoad ({{called.ionViewDidLoad}})</p>
20+
<p>ionViewWillEnter ({{called.ionViewWillEnter}})</p>
21+
<p>ionViewDidEnter ({{called.ionViewDidEnter}})</p>
22+
<p>ionViewWillLeave ({{called.ionViewWillLeave}})</p>
23+
<p>ionViewDidLeave ({{called.ionViewDidLeave}})</p>
24+
25+
<button ion-button (click)="push()">push()</button>
26+
<button ion-button (click)="openAlert()">open alert</button>
27+
</ion-content>
28+
`
29+
})
30+
export class Tab1 {
31+
called: any;
32+
33+
constructor(private alertCtrl: AlertController, private navCtrl: NavController) {
34+
this.called = {
35+
ionViewCanEnter: 0,
36+
ionViewCanLeave: 0,
37+
ionViewWillLoad: 0,
38+
ionViewDidLoad: 0,
39+
ionViewWillEnter: 0,
40+
ionViewDidEnter: 0,
41+
ionViewWillLeave: 0,
42+
ionViewDidLeave: 0
43+
};
44+
}
45+
46+
push() {
47+
this.navCtrl.push(Tab1);
48+
}
49+
50+
openAlert() {
51+
this.alertCtrl.create({
52+
title: 'Example'
53+
}).present();
54+
}
55+
56+
ionViewCanEnter() {
57+
this.called.ionViewCanEnter++;
58+
return true;
59+
}
60+
61+
ionViewCanLeave() {
62+
this.called.ionViewCanLeave++;
63+
return true;
64+
}
65+
66+
ionViewWillLoad() {
67+
this.called.ionViewWillLoad++;
68+
}
69+
70+
ionViewDidLoad() {
71+
this.called.ionViewDidLoad++;
72+
}
73+
74+
ionViewWillEnter() {
75+
this.called.ionViewWillEnter++;
76+
}
77+
78+
ionViewDidEnter() {
79+
this.called.ionViewDidEnter++;
80+
}
81+
82+
ionViewWillLeave() {
83+
this.called.ionViewWillLeave++;
84+
}
85+
86+
ionViewDidLeave() {
87+
this.called.ionViewDidLeave++;
88+
}
89+
}
90+
91+
@Component({
92+
template: `
93+
<ion-tabs>
94+
<ion-tab tabTitle="Plain List" tabIcon="star" [root]="root"></ion-tab>
95+
<ion-tab tabTitle="Schedule" tabIcon="globe" [root]="root"></ion-tab>
96+
<ion-tab tabTitle="Stopwatch" tabIcon="logo-facebook" [root]="root"></ion-tab>
97+
</ion-tabs>
98+
`
99+
})
100+
export class TabsPage {
101+
root = Tab1;
102+
}
103+
104+
@Component({
105+
template: `<ion-nav [root]="root"></ion-nav>`
106+
})
107+
export class E2EApp {
108+
root = TabsPage;
109+
}
110+
111+
@NgModule({
112+
declarations: [
113+
E2EApp,
114+
Tab1,
115+
TabsPage
116+
],
117+
imports: [
118+
IonicModule.forRoot(E2EApp, {
119+
tabsHighlight: true,
120+
})
121+
],
122+
bootstrap: [IonicApp],
123+
entryComponents: [
124+
E2EApp,
125+
Tab1,
126+
TabsPage
127+
]
128+
})
129+
export class AppModule {}

0 commit comments

Comments
 (0)