Modal display called in ionViewDidEnter shows twice
See original GitHub issueShort description of the problem:
I had a problem previously reported in #6062 whereby a modal was displaying twice when called in ionViewDidEnter
: immediately after dismissing it, it would show again. And after dismissing it a second time it would hide.
@jgw96 very kindly showed an altered Plunker which suggested I check the NavController
’s length()
property to ensure it’s !== 2 before proceeding (check previous issue with said Plunker).
However, in ionic@2.0.0-beta.11 we now present modals using a ModalController
which means we have lost the ability to check the length and as a result, the bug has crept back in.
Help! 😅
What behavior are you expecting?
A modal is appearing twice, immediately being shown after being dismissed the first time. I am expecting it to remain hidden after displaying the first time and dismissing it.
Steps to reproduce:
- Clone the following repository: https://github.com/kelvindart/ionic-modal
- Add the iOS platform via
ionic platform add ios
(at the time this is 4.2.0) - Run it in an emulator (I ran it in an iOS 9.3 emulator, i.e. the latest)
- Observe the modal displaying, dismiss it and observe it displaying again.
- Dismiss the modal and observe it no longer displaying it.
Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)
Check my repository of the uploaded code (unfortunately I could not find a Ionic 2 beta 11 Plunker template): https://github.com/kelvindart/ionic-modal
Clone this, and add the platform as per the replication steps above and observe!
Which Ionic Version? 2.0.0-beta.11
Plunker that shows an example of your issue
As above - no Plunker but please reference the Git repo.
Run ionic info
from terminal/cmd prompt: (paste output below)
Ionic Framework Version: 2.0.0-beta.11 Ionic CLI Version: 2.0.0-beta.37 Ionic App Lib Version: 2.0.0-beta.20 ios-deploy version: Not installed ios-sim version: 5.0.8 OS: Mac OS X El Capitan Node Version: v4.4.1 Xcode version: Xcode 7.3.1 Build version 7D1014
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (12 by maintainers)
No problem at all 😃 ! So because you are opening your modal in
ionViewDidEnter
the modal was originally opening twice becausefireOtherLifecycles
makes whatever you are pushing onto the nav stack (a modal in this case) fire the lifecycle events of the page its being pushed from. Therefore when the page is loadedionViewDidEnter
fires (like it should) and opens the modal. Then, when the modal opens it causesionViewDidEnter
to be fired again on the main page your opening the modal from, therefore opening the modal a second time. Hope all that makes sense!Awesome - that works perfectly for me too! Five more minutes and you should see it raised 😃. Thanks!