Hi All. Running into a problem hoping someone else has solved, looked everywhere and nobody has said anything about it. Seems like there is possibly an omission on the way ion-tabs works. When transitioning from a login page that has no tabs, to a tabs page - containing a home page that requires a ionViewCanEnter promise to be completed - the ion-tabs doesn’t wait for the promise of the home page even though it is the default (selected index) tab. So what happens is you get a flash of white (or whatever nav-decor is) while the home page resolves it’s CanEnter. Here is a simple dumbed-down example:
pages/login.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { TabsPage } from './tabs';
@Component({
selector: 'page-login',
template: '<ion-content style="background-color: #00f"><button (click)="login()">Login</button></ion-content>'
})
export class LoginPage {
constructor(public navCtrl: NavController) {}
login() {
this.navCtrl.push(TabsPage);
}
}
pages/tabs.ts
import { Component } from '@angular/core';
import { HomePage } from './home';
@Component({
template: '<ion-tabs selectedIndex="0"><ion-tab [root]="homeRoot" tabTitle="Home" tabIcon="home"></ion-tab></ion-tabs>'
})
export class TabsPage {
homeRoot: any = HomePage;
constructor() { }
ionViewCanEnter() {
// Wishing this would wait for HomePage's ionViewCanEnter
}
}
pages/home.ts
import { Component } from '@angular/core';
@Component({
selector: 'page-home',
template: '<ion-content style="background-color: #0f0">Welcome Back!</ion-content>'
})
export class HomePage {
constructor() { }
ionViewCanEnter() {
// imagine we are doing http stuff that takes 5 seconds...
return new Promise(function(resolve, reject) {
setTimeout(resolve, 5000);
});
}
}
How can I make it so TabsPage.ionViewCanEnter waits for the HomePage.ionViewCanEnter? Any ideas would be greatly appreciated. Would be great if it were not a hack, lol. Seems like Ionic should handle this automatically. I tried making TabsPage.ionViewCanEnter = homeRoot.ionViewCanEnter but it didn’t do anything.
In ionic1, we had something like Controller(HomePage, function() { … }).factory(function(Http) { return { Http.get(…) } }); on the HomePage, which resolved all the http requests before displaying itself, and there was no flash between login and tabs/home…
Thanks!