Ionic-framework: Nav.getActive() returns null if an overlay is shown

Created on 8 Aug 2016  Â·  12Comments  Â·  Source: ionic-team/ionic-framework

Short description of the problem:

When I present an overlay (alert, popover etc.), the app's NavController method getActive returns null.

What behavior are you expecting?

I don't know whether it should return the underlying page or the active overlay, but returning null seems like a bug to me, especially when it returns the active page before the overlay is shown.
It seems to me that it should return the active overlay, becuse nav.isActive(overlay) returns true.

Steps to reproduce:

  1. Present an overlay and wait for it's promise
  2. Check the return result of app.getActiveNav().getActive()
app.getActiveNav().getActive(); // returns ViewController with the current page
alert.present().then(() => {
   app.getActiveNav().getActive(); // returns null
   app.getAciveNav().isActive(alert); // returns true
});

Which Ionic Version? 1.x or 2.x
2.0.0-beta.11

Run ionic info from terminal/cmd prompt: (paste output below)
Cordova CLI: 6.1.1
Gulp version: CLI version 3.9.1
Gulp local: Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.11
Ionic CLI Version: 2.0.0-beta.36
Ionic App Lib Version: 2.0.0-beta.19
OS:
Node Version: v6.2.0

Most helpful comment

Please remove me from conversations of your development !!! I have nothing
to with your company and your spamming mail with tens of mails a day.
PLEASE STOP SENDING ME THESE MAILS !!!

On Aug 13, 2016 7:25 PM, "Jakub Beránek" [email protected] wrote:

I'm on vacation and won't be able to test it until next week, sorry x)

However I would like to get the active view from a singleton service that
manages the overlays and UI, so using an injected NavController directly
isn't an option there. Is it possible to get the active view from the
root/active nav? It seems that it should be working, it returns the page
correctly, however after an overlay is shown, it suddenly returns null.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/driftyco/ionic/issues/7609#issuecomment-239629209,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AH3Ui5pM4VEbYOkUhG4Zo-ATiS6uXVAQks5qfe_6gaJpZM4JfV4l
.

All 12 comments

Hello, thanks for opening an issue with us! Are you opening this alert in a lifecycle event?

I'm opening it in reaction to a button (click) event, thus the page should be fully initialized.

Tested it on Android and in browser, with the same results.

Hello @Kobzol ! Thanks for the info! Would you mind trying this?

alert.present().then(() => {
   this.navCtrl.getActive() //should return true
});

I'm on vacation and won't be able to test it until next week, sorry x)

However I would like to get the active view from a singleton service that manages the overlays and UI, so using an injected NavController directly isn't an option there. Is it possible to get the active view from the root/active nav? It seems that it should be working, it returns the page correctly, however after an overlay is shown, it suddenly returns null.

Please remove me from conversations of your development !!! I have nothing
to with your company and your spamming mail with tens of mails a day.
PLEASE STOP SENDING ME THESE MAILS !!!

On Aug 13, 2016 7:25 PM, "Jakub Beránek" [email protected] wrote:

I'm on vacation and won't be able to test it until next week, sorry x)

However I would like to get the active view from a singleton service that
manages the overlays and UI, so using an injected NavController directly
isn't an option there. Is it possible to get the active view from the
root/active nav? It seems that it should be working, it returns the page
correctly, however after an overlay is shown, it suddenly returns null.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/driftyco/ionic/issues/7609#issuecomment-239629209,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AH3Ui5pM4VEbYOkUhG4Zo-ATiS6uXVAQks5qfe_6gaJpZM4JfV4l
.

Hello @TomasKatz ! We do not send the github notification emails, Github does this. Most likely you have set the ionic framework repo to "watched" which means that you will get emails for all activity on our repo. I would recommend checking out your github notification settings and making sure that you don't have our repo set as watched. Also, since we do not have any control over github notification emails I would recommend that you contact github support instead. Thanks!

@jgw96 you closed the issue, so will this be fixed or is it a usage of the NavController that won't be supported? :-)

Hello @Kobzol sorry for the misunderstanding! With beta.11 we made it to where overlay components now have their own NavController that is completely separate from the root NavController as this lines up better with how overlay components work in native apps. From my understanding of your use case it seems as if you may need to make a few changes to account for this. Hopefully this explains everything better. Thanks!

Thanks for the explanation, now I understand its behaviour. Is there any way to get the active NavController universally? I can store the active overlays if I create them, but not when some other component does (i. e. Ionic's DatePicker). When the datepicker is shown, I don't know how to get the active overlay or it's navcontroller.

I wanted to use it like this to emulate the default Ionic backbutton behaviour (i.e. to close the active overlay or pop the page if there's no overlay), because with platform.registerBackbuttonAction I could only override it, not extend it (#7590).

@Kobzol No problem! So actually back button issues are gonna be fixed for good in a later release so that you will not have to hack around it. At this time their is no way that i could think of for you to get the navcontroller of something like the datepicker component. Sorry about that! If i think of a solution i will comment here. Thanks for using Ionic!

Actually this is a problem and should be fixed in my opinion.

Example/usecase: our app is checking for some settings/whatever in the background (using setInterval). And when this check returns TRUE we want to show modal with some info. So the problem is app will be broken in case of another overlay is active at the moment. What can we do in such cases? I thought about using getActive().isOverlay flag, but it doesn't work :/

Was this page helpful?
0 / 5 - 0 ratings