-
Notifications
You must be signed in to change notification settings - Fork 3
Pop unsubscribing #26
Copy link
Copy link
Open
Description
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?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels