Skip to content

Commit ba557ac

Browse files
committed
fix(nav): ion-nav inside ion-content work properly
1 parent 3283347 commit ba557ac

File tree

8 files changed

+60
-21
lines changed

8 files changed

+60
-21
lines changed

src/components/content/content.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ export class Content extends Ion {
173173
this._sbPadding = config.getBoolean('statusbarPadding', false);
174174

175175
if (viewCtrl) {
176-
viewCtrl._setContent(this);
177-
viewCtrl._setContentRef(elementRef);
176+
viewCtrl._setIONContent(this);
177+
viewCtrl._setIONContentRef(elementRef);
178178
}
179179
}
180180

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class MyCmpTest {}
4040
<button ion-item [navPush]="'FirstPage'">Push w/ [navPush] and string view name</button>
4141
<button ion-item (click)="setPages()">setPages() (Go to PrimaryHeaderPage)</button>
4242
<button ion-item (click)="setRoot()">setRoot(PrimaryHeaderPage) (Go to PrimaryHeaderPage)</button>
43-
<button ion-item (click)="navCtrl.pop()">Pop</button>
43+
<button ion-item (click)="pop()">Pop</button>
4444
<ion-item>
4545
<ion-label>Toggle Can Leave</ion-label>
4646
<ion-toggle (click)="canLeave = !canLeave"></ion-toggle>
@@ -174,6 +174,10 @@ export class FirstPage {
174174
}, 250);
175175
}
176176

177+
pop() {
178+
this.navCtrl.pop().catch(() => {});
179+
}
180+
177181
viewDismiss() {
178182
this.viewCtrl.dismiss();
179183
}

src/components/nav/test/child-navs/app-module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ export class E2EApp {
2727
})
2828
export class LandingPage {
2929

30-
constructor(public navCtrl: NavController) {
31-
}
30+
constructor(public navCtrl: NavController) {}
3231

3332
goToPage() {
3433
this.navCtrl.push(FirstPage);
3534
}
35+
36+
ionViewDidLoad() {
37+
this.goToPage();
38+
}
3639
}
3740

3841
@Component({

src/components/nav/test/child-navs/e2e.ts

Whitespace-only changes.

src/components/tabs/tabs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ export class Tabs extends Ion implements AfterViewInit {
421421
// to refresh the tabbar and content dimensions to be sure
422422
// they're lined up correctly
423423
if (alreadyLoaded && selectedPage) {
424-
let content = <Content>selectedPage.getContent();
425-
if (content && content instanceof Content) {
424+
let content = <Content>selectedPage.getIONContent();
425+
if (content) {
426426
content.resize();
427427
}
428428
}

src/navigation/nav-controller-base.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,17 @@ export class NavControllerBase extends Ion implements NavController {
175175
}
176176

177177
ti.resolve = (hasCompleted: boolean, isAsync: boolean, enteringName: string, leavingName: string, direction: string) => {
178-
this.setTransitioning(false);
179-
180178
// transition has successfully resolved
181179
this._trnsId = null;
182180
resolve && resolve(hasCompleted, isAsync, enteringName, leavingName, direction);
183181
this._sbCheck();
184182

185183
// let's see if there's another to kick off
184+
this.setTransitioning(false);
186185
this._nextTrns();
187186
};
188187

189188
ti.reject = (rejectReason: any, trns: Transition) => {
190-
this.setTransitioning(false);
191-
192189
// rut row raggy, something rejected this transition
193190
this._trnsId = null;
194191
this._queue.length = 0;
@@ -209,6 +206,7 @@ export class NavControllerBase extends Ion implements NavController {
209206

210207
reject && reject(false, false, rejectReason);
211208

209+
this.setTransitioning(false);
212210
this._nextTrns();
213211
};
214212

@@ -248,6 +246,8 @@ export class NavControllerBase extends Ion implements NavController {
248246
if (!ti) {
249247
return false;
250248
}
249+
// set that this nav is actively transitioning
250+
this.setTransitioning(true);
251251

252252
// Get entering and leaving views
253253
const leavingView = this.getActive();
@@ -325,7 +325,6 @@ export class NavControllerBase extends Ion implements NavController {
325325

326326
_postViewInit(enteringView: ViewController, leavingView: ViewController, ti: TransitionInstruction, resolve: TransitionResolveFn) {
327327
const opts = ti.opts || {};
328-
329328
const insertViews = ti.insertViews;
330329
const removeStart = ti.removeStart;
331330

@@ -822,8 +821,8 @@ export class NavControllerBase extends Ion implements NavController {
822821
swipeBackProgress(stepValue: number) {
823822
if (this._sbTrns && this._sbGesture) {
824823
// continue to disable the app while actively dragging
825-
this._app.setEnabled(false, ACTIVE_TRANSITION_MAX_TIME);
826-
this.setTransitioning(true, ACTIVE_TRANSITION_MAX_TIME);
824+
this._app.setEnabled(false, ACTIVE_TRANSITION_DEFAULT);
825+
this.setTransitioning(true);
827826

828827
// set the transition animation's progress
829828
this._sbTrns.progressStep(stepValue);
@@ -890,7 +889,7 @@ export class NavControllerBase extends Ion implements NavController {
890889
return (this._trnsTm > Date.now());
891890
}
892891

893-
setTransitioning(isTransitioning: boolean, durationPadding: number = 2000) {
892+
setTransitioning(isTransitioning: boolean, durationPadding: number = ACTIVE_TRANSITION_DEFAULT) {
894893
this._trnsTm = (isTransitioning ? (Date.now() + durationPadding + ACTIVE_TRANSITION_OFFSET) : 0);
895894
}
896895

@@ -962,5 +961,5 @@ export class NavControllerBase extends Ion implements NavController {
962961
let ctrlIds = -1;
963962

964963
const DISABLE_APP_MINIMUM_DURATION = 64;
965-
const ACTIVE_TRANSITION_MAX_TIME = 5000;
964+
const ACTIVE_TRANSITION_DEFAULT = 5000;
966965
const ACTIVE_TRANSITION_OFFSET = 2000;

src/navigation/view-controller.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Navbar } from '../components/navbar/navbar';
66
import { NavControllerBase } from './nav-controller-base';
77
import { NavOptions, ViewState } from './nav-util';
88
import { NavParams } from './nav-params';
9+
import { Content } from '../components/content/content';
910

1011

1112
/**
@@ -28,6 +29,8 @@ import { NavParams } from './nav-params';
2829
export class ViewController {
2930
private _cntDir: any;
3031
private _cntRef: ElementRef;
32+
private _ionCntDir: Content;
33+
private _ionCntRef: ElementRef;
3134
private _hdrDir: Header;
3235
private _ftrDir: Footer;
3336
private _isHidden: boolean = false;
@@ -308,7 +311,7 @@ export class ViewController {
308311
/**
309312
* @returns {component} Returns the Page's Content component reference.
310313
*/
311-
getContent() {
314+
getContent(): any {
312315
return this._cntDir;
313316
}
314317

@@ -326,6 +329,36 @@ export class ViewController {
326329
return this._cntRef;
327330
}
328331

332+
/**
333+
* @private
334+
*/
335+
_setIONContent(content: Content) {
336+
this._setContent(content);
337+
this._ionCntDir = content;
338+
}
339+
340+
/**
341+
* @private
342+
*/
343+
getIONContent(): Content {
344+
return this._ionCntDir;
345+
}
346+
347+
/**
348+
* @private
349+
*/
350+
_setIONContentRef(elementRef: ElementRef) {
351+
this._setContentRef(elementRef);
352+
this._ionCntRef = elementRef;
353+
}
354+
355+
/**
356+
* @private
357+
*/
358+
getIONContentRef(): ElementRef {
359+
return this._ionCntRef;
360+
}
361+
329362
/**
330363
* @private
331364
*/

src/transitions/page-transition.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export class PageTransition extends Transition {
2424
* DOM READ
2525
*/
2626
readDimensions() {
27-
const content = <Content>this.enteringView.getContent();
28-
if (content && content instanceof Content) {
27+
const content = <Content>this.enteringView.getIONContent();
28+
if (content) {
2929
content.readDimensions();
3030
}
3131
}
@@ -34,8 +34,8 @@ export class PageTransition extends Transition {
3434
* DOM WRITE
3535
*/
3636
writeDimensions() {
37-
const content = <Content>this.enteringView.getContent();
38-
if (content && content instanceof Content) {
37+
const content = <Content>this.enteringView.getIONContent();
38+
if (content) {
3939
content.writeDimensions();
4040
}
4141
}

0 commit comments

Comments
 (0)