Ionic ionViewWillEnter not fire after becoming active from a NavController.pop()


#1

Hi,

let’s say we have a page A and a modal page B.

In page A we setup a lifecycle hook

onViewWillEnter()
{
 console.log("event onViewWillEnter fired");
 this.platform.registerBackButtonAction( () => {
  console.log("back button pressed!");
});
}

When we freshly enter into this page A the event is fired and the back button works as expected.
Let’s open up again page A, and from this page we show the model page B using the ModalController.present.
If we dismiss now page B (shown modal), the event onViewWillEnter is not being fired anymore while re-entering page A, but also the back button is not working anymore.

Accoring the ionic docs the event should be fired as page A becomes active again:

ionViewWillEnter void Runs when the page is about to enter and become the active page.

From my point of this sFrom my point of view this is a bug.
Or can someone explain this behaviour? What do you think?

Thanks
hako


#2

ionViewWillEnter(), not onViewWillEnter()


#3

I believe the behavior is correct, even if it’s a little confusing at first. Page A is still the current page, even while Modal B is open, as Modal B isn’t a true page. It’s still declared a page, and is conceptually a page, but it isn’t a page in the same sense that Page A is a page. Instead, it’s a “page” that is overlayed across Page A.

I’m fairly certain this is the case, but there is of course always the possibility that I’m wrong.


#4

@AaronSterling: yes, you’re absolutely right…

@SigmundFroyd: I could agree on that, but then the concept does not follow a red line. If so, the hw button should still be registered, even after coming back from a modal window…


#5

It fires in my app when a modal dismisses. My guess is you just typed it wrong.


#6

I just checked again., but the function is spelled right (it also works the first time i enter the page).

which version of ionic are u using?


#7

Framework 3.5, but I don’t think that makes a difference. Maybe post code.


#8

Here comes the code snippet:

 public ionViewWillEnter () {
    console.log("ionViewWillEnter fired");
    this.platform.registerBackButtonAction( () => {
      try {
        if (this.navCtrl.canGoBack) {
          this.navCtrl.pop();
        } else {
          this.viewCtrl.dismiss();
        }
      } catch (e) {
        console.log("unable to dismiss HW backbutton");
      }
    });
  }

the console.log is not being executed after a modal return


#9

Sorry, @SigmundFroyd is right and I’m wrong. I went back and looked, and ionViewWillEnter fires inside the modal when the modal enters. In the base page, when you present a modal, you don’t leave the base page, so ionViewWillLeave() doesn’t fire in the base page even though ionViewWillEnter() fires inside the modal. I had assumed that the one implied the other and it doesn’t.


#10

Hey Aaron,

thanks for your reply! Does someone know en event, which is fired each time a page becomes the primary shown one?


#11

Hey, did someone figure this out? I am also looking for an event/method that fires each time a page becomes the primary shown one (like viewDidAppear in iOS for example). My problem is when the app is in the background and I click on a local notification which brings the app forward, but neither the ionViewDidLoad, ionViewWillEnter or ionViewDidEnter fire. Btw, I am using side-menu, if that makes a difference.


#12

Is there any update on this issue? I was hoping it would be confirmed or fixed or maybe a workaround found for now.


#13

I need to call ionContent.resize when my login modal closes because the header/footer are dependent on user type. Unfortunately, since ionViewWillEnter, this isn’t working…

edit: since the data was changing on login, what I really needed to do was to use a ReplaySubject to listen for the loaded data and then trigger the ioncontent.resize method.


#14

Present the same problem, the only request that occurred to me was:

Change:
let addModal = this.modalCtrl.create (‘newPage’);
addModal.present ();

By:
this.navCtrl.push (‘newPage’);

And the ionViewWillEnter event will work normally.

If someone knows a better request please share.