ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Inconsistent lifecycle events when working with modals

Open schlaus opened this issue 10 years ago • 8 comments

Short description of the problem:

When I'm on page P and I open the modal M, P will fire the lifecycle events onPageWillLeave and onPageDidLeave, and then M will fire onPageWillEnter and onPageDidEnter. When I'm dismissing M, it will fire onPageWillLeave and onPageDidLeave, but P wont fire any lifecycle events.

What behavior are you expecting?

I would expect P to fire onPageWillEnter and onPageDidEnter.

Which Ionic Version? 2.x

Run ionic info from terminal/cmd prompt: (paste output below) Cordova CLI: 6.1.0 (cordova-lib@undefined) Gulp version: CLI version 3.9.0 Gulp local: Local version 3.9.1 Ionic Version: 2.0.0-beta.3 Ionic CLI Version: 2.0.0-beta.19 Ionic App Lib Version: 2.0.0-beta.9 OS: Windows 7 SP1 Node Version: v5.7.0

schlaus avatar Mar 24 '16 10:03 schlaus

Hey @schlaus ! Thanks for opening an issue with us! Would you be able to make a codepen or plunker that demonstrates this issue?

jgw96 avatar May 05 '16 16:05 jgw96

Hello all! As it seems it has been a while since there was any activity on this issue i will be closing it for now. Feel free to comment if you are still running into this issue. Thanks for using Ionic!

jgw96 avatar May 10 '16 14:05 jgw96

same issue. creating modal like this:

let modal = Modal.create(NewTicketPage);
this.nav.present(modal);

normally the lifecycle onPageWillEnter() works perfect with all the other pages. the modal itself is also a page btw. so nothing special there. but since this sounds like a big issue, i do not know whether i did a mistake. the constructor itself is called everytime it should be called.

edit:

Your system information:

Cordova CLI: You have been opted out of telemetry. To change this, run: cordova telemetry on.
6.2.0

Ionic Framework Version: 2.0.0-beta.7
Ionic CLI Version: 2.0.0-beta.29
Ionic App Lib Version: 2.0.0-beta.16
OS: Distributor ID: Fedora Description: Fedora release 23 (Twenty Three) 
Node Version: v5.10.1

edit2: well...after updating to the latest ionic beta everything is fine now...should have done it in the first place. also the renaming was important.

Your system information:

Cordova CLI: 6.2.0
Ionic Framework Version: 2.0.0-beta.9
Ionic CLI Version: 2.0.0-beta.29
Ionic App Lib Version: 2.0.0-beta.16
OS: Distributor ID: Fedora Description: Fedora release 23 (Twenty Three) 
Node Version: v5.10.1

tolgamalachi avatar Jun 18 '16 13:06 tolgamalachi

This seems to be an issue again on current master (ccf6ae5) with ModalController:

let modal = this.modalCtrl.create(ReportDetailsPage, {report: report})
modal.present();

and later dismissing the modal

this.viewCtrl.dismiss(this.report);

ionViewWillEnter will not be called.

leezu avatar Aug 03 '16 07:08 leezu

Is there a workaround in Beta 11 until this is fixed, perhaps to manual way to fire or subscribe to the ionViewWillEnter and ionViewDidEnter events?

All my views are populated according to the ViewController lifecycle, using the ionViewWillEnter and ionViewDidEnter events, so would rather not refactor that code if this will be fixed in an upcoming beta.

Note, the ionViewLoaded event is still being fired when using the ModalController, just not the other lifecycle events.

dalezak avatar Sep 06 '16 19:09 dalezak

Ok, this is strange, but if I override the showBackdrop and enableBackdropDismiss options, then the modal fires the ionViewWillEnter and ionViewDidEnter events as expected.

let modal = this.modalController.create(ModalPage,
  {},
  { showBackdrop: false, enableBackdropDismiss:false });
modal.present();

Perhaps a workaround until this issue has been fixed...

dalezak avatar Sep 06 '16 20:09 dalezak

I am using @dalezak 's workaround ATM. (I don't want to know what they had to do to arrive at this workaround. 😬) I am using a view that can be called from many places in the app, so it really needs to be a "modal." [RC4] Setting those options works for me on those specific modals, as this is only "phone"-sized devices. After adding those options, I am getting expected results from dismissing the modal and re-entering it.

MT-- avatar Jan 11 '17 00:01 MT--

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Sep 05 '18 05:09 ionitron-bot[bot]