Rg.plugins.popup: Popup inside Navigation Page

Created on 15 May 2018  路  9Comments  路  Source: rotorgames/Rg.Plugins.Popup

Hi @rotorgames

I have a question.

I have a NavigationPage with some pages in the stack. One of these pages open a popup. When popup is visualized, i press Device's back button and the page (not the popup) is "popped" from the stack. Is it correct? I thought that the popup should be dismissed if I press hardware back button, not the "background" pase

Most helpful comment

@acaliaro Hi your the last example of code is not correct. You should not call PopAllPopupAsync. See this doc https://github.com/rotorgames/Rg.Plugins.Popup/wiki/Getting-started#android-back-button.

Also you just can do so:

public override void OnBackPressed()
        {
            Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed);
        }

You don't need to implement if else construction, the plugin will do all itself.

All 9 comments

@acaliaro Did you try overriding the BackButton pressed Event in the popup code file? There you can handle the close of this popup.

Can you explain better what Should I do?

something like

    protected override bool OnBackButtonPressed()
    {
        Application.Current.MainPage.Navigation.PopPopupAsync();
        return true;
    }

(this does nothing... I set a breakpoint but it does not stop...)

        public override void OnBackPressed()
        {
            if (Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed))
            {
                // Do something if there are some pages in the `PopupStack`
                App.Current.MainPage.Navigation.PopAllPopupAsync();
            }
            else
            {
                // Do something if there are not any pages in the `PopupStack`
            }
        }

It's ok with this.. thanks

@acaliaro Hi your the last example of code is not correct. You should not call PopAllPopupAsync. See this doc https://github.com/rotorgames/Rg.Plugins.Popup/wiki/Getting-started#android-back-button.

Also you just can do so:

public override void OnBackPressed()
        {
            Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed);
        }

You don't need to implement if else construction, the plugin will do all itself.

You should update the Wiki docs at https://github.com/rotorgames/Rg.Plugins.Popup/wiki/Getting-started#android-back-button as the code suggested by @acaliaro is exactly what is shown there.

@henda79 which version of @acaliaro are you mentioning here?

public override void OnBackPressed()
        {
            if (Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed))
            {
                // Do something if there are some pages in the `PopupStack`
                App.Current.MainPage.Navigation.PopAllPopupAsync();
            }
            else
            {
                // Do something if there are not any pages in the `PopupStack`
            }
        }

This code would pop all of the popups (as far as I am aware?) you have if you hit the background of the app. Which, while helpful to some, would not be considered universal behaviour.

@LuckyDucko, see this comment by the repo owner here.

@acaliaro Hi your the last example of code is not correct. You should not call PopAllPopupAsync. See this doc https://github.com/rotorgames/Rg.Plugins.Popup/wiki/Getting-started#android-back-button.

Also you just can do so:

public override void OnBackPressed()
        {
            Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed);
        }

You don't need to implement if else construction, the plugin will do all itself.

@henda79 ah, my bad I misunderstood.

the if/else construction is only important I guess to people who require some extra functionality. We use it for debugging in our samples

public override void OnBackPressed()
        {
            if (Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed))
            {
                Debug.WriteLine("Android back button: There are some pages in the PopupStack");
            }
            else
            {
                Debug.WriteLine("Android back button: There are not any pages in the PopupStack");
            }
        }

I'm thinking that the Wiki should have both, but mention the one-liner you pointed out as all that is required. that way we people browsing the wiki will see both the quick basic way, and more advanced usage

@LuckyDucko Yes, I agree with that.

Was this page helpful?
0 / 5 - 0 ratings