-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG FIX: adding count check for navigation stack before getting last item, adding check for mainpage as current page as additional failover. #2379
base: main
Are you sure you want to change the base?
Conversation
…ding check for mainpage as last resort
@dotnet-policy-service agree company="Final Level Inc" |
@dotnet-policy-service agree |
@nixkuroi the command you issued was incorrect. Please try again. Examples are:
and
|
@dotnet-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no suggestions.
{ | ||
currentPage = page; | ||
return true; | ||
} | ||
|
||
if (Application.Current != null && Application.Current.MainPage != null && Application.Current.MainPage is Page mainPage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI - Once #2215 is merged, we will need to modify this to use Application.Current.Window
instead of Application.Current.MainPage
because MainPage
is deprecated in .NET 9: https://learn.microsoft.com/en-us/dotnet/maui/whats-new/dotnet-9?view=net-maui-9.0#mainpage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also FYI - you can ignore the current build errors in our CI pipeline. Those too will be resolved when we merge #2215
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Is there anything I need to do for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description of Change
In the MauiMediaElement.macios.cs code, there is an instance where it looks at the navigation stack and gets the last item for the current page, but this can cause an error when there are zero items in the navigation stack.
I've also added as a further attempt to get the current page, checking to see if the Application.Current.MainPage is null and if it's not, trying to get and use that as well.
The Fix:
// If not using Shell or a Modal Page, return the visible page in the (non-modal) NavigationStack
if (window.Navigation.NavigationStack.Count > 0 && window.Navigation.NavigationStack[^1] is Page page)
{
currentPage = page;
return true;
}
if (Application.Current != null && Application.Current.MainPage != null && Application.Current.MainPage is Page mainPage)
{
currentPage = mainPage;
return true;
}
Additional Notes:
These helped prevent errors when loading the MediaElement on Android. In the future, this code should maybe be moved to a shared platform location instead of living in iOS code because it becomes confusing when it seems to be throwing an iOS related error while debugging for Android.