Skip to content

Navigation

Kirill edited this page Oct 3, 2019 · 3 revisions

The plugin supports some ways of navigation but I recommend to use Rg.Plugins.Popup.Services.PopupNavigation.Instance.

You must initialize the plugin before to use it.

PopupNavigation.Instance (IPopupNavigation)

You should use it in priority. It is flexible solution for dependency injection, unit tests and etc.

namespace Rg.Plugins.Popup.Contracts
{
    public interface IPopupNavigation
    {
        // Invokes before adding to PopupStack
        // A page is not visible and animation has not been started at this moment
        event EventHandler<PopupNavigationEventArgs> Pushing;

        // Invokes after animation finished
        // A page is visible and animation has been finished at this moment
        event EventHandler<PopupNavigationEventArgs> Pushed;

        // Invokes before removing from PopupStack
        // A page is visible and animation has not been started at this moment
        event EventHandler<PopupNavigationEventArgs> Popping;

        // Invokes after animation finished and removing from PopupStack
        // A page is not visible and animation has been finished at this moment.
        event EventHandler<PopupNavigationEventArgs> Popped;

        // List of PopupPages which are in the scree
        IReadOnlyList<PopupPage> PopupStack { get; }

        // Open a PopupPage
        Task PushAsync(PopupPage page, bool animate = true);

        // Close the last PopupPage int the PopupStack
        Task PopAsync(bool animate = true);

        // Close all PopupPages in the PopupStack
        Task PopAllAsync(bool animate = true);

        // Close an one PopupPage in the PopupStack even if the page is not the last
        Task RemovePageAsync(PopupPage page, bool animate = true);
    }
}

Xamarin.Forms.INavigation (NavigationExtension)

I don't recommend to use it but you can if you want. To apply it you should use Rg.Plugins.Popup.Extensions.NavigationExtension. It allows to use the popup navigation in your xamarin forms pages.

using Rg.Plugins.Popup.Pages;
using Xamarin.Forms;

using Rg.Plugins.Popup.Extensions;

namespace Demo.Pages
{
    public class MyContentPage : ContentPage
    {
        private async void ExampleMethod(PopupPage page)
        {
            // Open a PopupPage
            await Navigation.PushPopupAsync(page);

            // Close the last PopupPage int the PopupStack
            await Navigation.PopPopupAsync();

            // Close all PopupPages in the PopupStack
            await Navigation.PopAllPopupAsync();

            // Close an one PopupPage in the PopupStack even if the page is not the last
            await Navigation.RemovePopupPageAsync(page);
        }
    }
}