question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modal display called in ionViewDidEnter shows twice

See original GitHub issue

Short 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:

  1. Clone the following repository: https://github.com/kelvindart/ionic-modal
  2. Add the iOS platform via ionic platform add ios (at the time this is 4.2.0)
  3. Run it in an emulator (I ran it in an iOS 9.3 emulator, i.e. the latest)
  4. Observe the modal displaying, dismiss it and observe it displaying again.
  5. 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:closed
  • Created 7 years ago
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
jgw96commented, Aug 23, 2016

No problem at all 😃 ! So because you are opening your modal in ionViewDidEnter the modal was originally opening twice because fireOtherLifecycles 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 loaded ionViewDidEnter fires (like it should) and opens the modal. Then, when the modal opens it causes ionViewDidEnter 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!

1reaction
kelvindartcommented, Sep 6, 2016

Awesome - that works perfectly for me too! Five more minutes and you should see it raised 😃. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modal display called in ionViewDidEnter shows twice #7839
Therefore when the page is loaded ionViewDidEnter fires (like it should) and opens the modal. Then, when the modal opens it causes ...
Read more >
Ionic Vue Modal shows content twice - Stack Overflow
In an Ionic Vue app I'm trying to display some simple content in a modal. However the content is always displayed twice.
Read more >
ionViewDidLoad triggers twice - ionic-v3
The event is called twice if I directly visit the page. But if I navigate via the launch page, it's called once. Any...
Read more >
Modal - Bootstrap
Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Read more >
Using ARIA role=dialog to implement a modal dialog box
Note on focus management. When using custom dialogs, it is vital that authors use scripting to move the focus to the displayed dialog...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found