Skip to content

Provide an extension method to detect if popup was previous page #2767

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

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

Conversation

bijington
Copy link
Contributor

@bijington bijington commented Jun 25, 2025

Description of Change

This introduces the ability for developers to determine whether the previous page displayed in their app was a PopupPage as below

public class MyPage : Page
{
    protected override void OnNavigatedTo(NavigatedToEventArgs args)
    {
        base.OnNavigatedTo(args);

        if (args.WasPreviousPageAToolkitPopup() is true)
        {
            return;
        }

        // do other stuff
    }
}

The reason for the extension method over allowing a developer to just check the PreviousPage property is twofold:

  1. PreviousPage is currently internal
  2. PopupPage is also internal

I understand that internal access to MAUI will be removed from MAUI for .NET 10.0 but it also appears that this will be introduced dotnet/maui#28384. If that is the case the code in this PR will continue to function when .NET 10.0 ships.

Linked Issues

  • Fixes #

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description) - the constructor for NavigatedToEventArgs is internal so it would require some reflection to construct something to test.
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

@Copilot Copilot AI review requested due to automatic review settings June 25, 2025 05:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds an extension method to NavigatedToEventArgs that allows developers to detect if the previous page was a Toolkit popup.

  • Introduces WasPreviousPageAToolkitPopup extension.
  • Checks args.PreviousPage is PopupPage.
  • Adds new file under Extensions namespace.
Comments suppressed due to low confidence (2)

src/CommunityToolkit.Maui/Extensions/NavigatedToEventArgsExtensions.shared.cs:11

  • The XML comment references but the method checks for PopupPage; update the cref to for consistency.
	/// Determines whether the previous page was a Community Toolkit <see cref="Popup"/>.

src/CommunityToolkit.Maui/Extensions/NavigatedToEventArgsExtensions.shared.cs:15

  • Consider adding unit tests covering the cases where the previous page is a PopupPage and when it's not to ensure the extension behaves correctly.
	public static bool WasPreviousPageAToolkitPopup(this NavigatedToEventArgs args) => args.PreviousPage is PopupPage;

@bijington
Copy link
Contributor Author

Thanks for the approval @pictos

@jfversluis do you have any understanding on whether dotnet/maui#28384 will make it into .NET 10.0?

@jfversluis
Copy link
Member

Asked @PureWeen or maybe @jsuarezruiz knows

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.

3 participants