Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nixkuroi
Copy link

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.

@nixkuroi
Copy link
Author

@dotnet-policy-service agree company="Final Level Inc"

@nixkuroi
Copy link
Author

@dotnet-policy-service agree

Copy link
Contributor

@nixkuroi the command you issued was incorrect. Please try again.

Examples are:

@dotnet-policy-service agree

and

@dotnet-policy-service agree company="your company"

@nixkuroi
Copy link
Author

@dotnet-policy-service agree

@brminnick brminnick requested a review from Copilot December 11, 2024 20:39

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)
Copy link
Collaborator

@brminnick brminnick Dec 11, 2024

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

Copy link
Collaborator

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

Copy link
Author

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?

Copy link
Collaborator

@brminnick brminnick Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are in a code freeze until we merge #2215.

You'll need to fix this before we can merge this PR because it will cause a compiler error in .NET 9. This PR will not be merged before #2215.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants