Skip to content

Pop unsubscribing  #26

@petarkekez

Description

@petarkekez

Hi, to start thanks for the framework.

I had an issue with stuff not unsubscribing with Shell.

This happened because the unsubscription automaticly happend only on the navigation page, code:

if (sender is Application && e.PropertyName == "MainPage")
{
    var page = (sender as Application).MainPage;

    if (page is NavigationPage)
    {
        BindEvents(page as NavigationPage);
    }
}

because of this i needed to update this method to this:

static void App_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
    if (sender is Application && e.PropertyName == "MainPage")
    {
        var page = (sender as Application).MainPage;

        if (page is NavigationPage)
        {
            BindEvents(page as NavigationPage);
        }
        else if (page is Shell s)
        {
            s.Navigating += Shell_Navigating;
        }
    }
}
private static void Shell_Navigating(object sender, ShellNavigatingEventArgs e)
{
    if (e.Source == ShellNavigationSource.Pop
        || e.Source == ShellNavigationSource.Remove)
    {
        if (sender is Shell s)
        {
            UnsubscribePage(s.CurrentPage);
        }
    }

    if (e.Source == ShellNavigationSource.PopToRoot)
    {
        if (sender is Shell s)
        {

            UnsubscribePage(s.CurrentPage);
        }
    }

    if (e.Source == ShellNavigationSource.Unknown)
    {
        if(sender is Shell s)
        {
            if( !(s.CurrentPage is MainView) ) // On initial shell setup this is triggered..
            {
                UnsubscribePage(s.CurrentPage);
            }
        }
    }
}

I can add this to a PR if you would like to review/merge it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions