diff --git a/src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs b/src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs index 45f0907a86..688f0a3e52 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs @@ -215,7 +215,7 @@ public void ShowPopupAsync_Shell_WithViewType_ShowsPopup() var shellNavigation = Shell.Current.Navigation; // Act - shell.ShowPopup(viewWithQueryable, shellParameters: shellParameters); + shell.ShowPopup(viewWithQueryable, parameters: shellParameters); // Assert Assert.Single(shellNavigation.ModalStack); @@ -231,8 +231,8 @@ public async Task ShowPopupAsync_AwaitingShowPopupAsync_EnsurePreviousPopupClose var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); // Act - await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken); - await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken); + await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, token: TestContext.Current.CancellationToken); + await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, token: TestContext.Current.CancellationToken); // Assert Assert.Empty(navigation.ModalStack); @@ -289,7 +289,7 @@ public void ShowPopup_Shell_NavigationModalStackCountIncreases() Assert.Empty(shellNavigation.ModalStack); // Act - shell.ShowPopup(viewWithQueryable, shellParameters: shellParameters); + shell.ShowPopup(viewWithQueryable, parameters: shellParameters); // Assert Assert.Single(shellNavigation.ModalStack); @@ -720,7 +720,7 @@ public async Task ShowPopupAsync_CancellationTokenExpired() await Task.Delay(100, TestContext.Current.CancellationToken); // Ensure CancellationToken has expired // Assert - await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, cts.Token)); + await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, token: cts.Token)); } [Fact(Timeout = (int)TestDuration.Short)] @@ -757,7 +757,7 @@ public async Task ShowPopupAsyncWithView_CancellationTokenExpired() await Task.Delay(100, TestContext.Current.CancellationToken); // Ensure CancellationToken has expired // Assert - await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(view, PopupOptions.Empty, cts.Token)); + await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(view, PopupOptions.Empty, token: cts.Token)); } [Fact(Timeout = (int)TestDuration.Short)] @@ -795,7 +795,7 @@ public async Task ShowPopupAsync_CancellationTokenCanceled() await cts.CancelAsync(); // Ensure CancellationToken has expired // Assert - await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, cts.Token)); + await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, token: cts.Token)); } [Fact(Timeout = (int)TestDuration.Short)] @@ -817,7 +817,7 @@ public async Task ShowPopupAsync_Shell_CancellationTokenCanceled() await cts.CancelAsync(); // Assert - await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, cts.Token)); + await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, token: cts.Token)); Assert.NotEqual(shellParameterBackgroundColorValue, selfClosingPopup.BackgroundColor); } @@ -832,7 +832,7 @@ public async Task ShowPopupAsyncWithView_CancellationTokenCanceled() await cts.CancelAsync(); // Ensure CancellationToken has expired // Assert - await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(view, PopupOptions.Empty, cts.Token)); + await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(view, PopupOptions.Empty, token: cts.Token)); } [Fact(Timeout = (int)TestDuration.Short)] @@ -868,7 +868,7 @@ public async Task ShowPopupAsync_ShouldValidateProperBindingContext() var popupViewModel = ServiceProvider.GetRequiredService(); // Act - await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken); + await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, token: TestContext.Current.CancellationToken); // Assert Assert.Same(popupInstance.BindingContext, popupViewModel); @@ -906,7 +906,7 @@ public async Task ShowPopupAsyncWithView_ShouldValidateProperBindingContext() var popupViewModel = ServiceProvider.GetRequiredService(); // Act - var showPopupTask = navigation.ShowPopupAsync(view, PopupOptions.Empty, TestContext.Current.CancellationToken); + var showPopupTask = navigation.ShowPopupAsync(view, PopupOptions.Empty, token: TestContext.Current.CancellationToken); var popupPage = (PopupPage)navigation.ModalStack[0]; @@ -954,7 +954,7 @@ public async Task ShowPopupAsync_ShouldReturnResultOnceClosed() var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); // Act - var result = await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken); + var result = await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, token: TestContext.Current.CancellationToken); // Assert Assert.Same(mockPopup.Result, result.Result); @@ -994,7 +994,7 @@ public async Task ShowPopupAsyncWithView_ShouldReturnResultOnceClosed() var expectedPopupResult = new PopupResult(popupResultValue, false); // Act - var showPopupTask = navigation.ShowPopupAsync(view, PopupOptions.Empty, TestContext.Current.CancellationToken); + var showPopupTask = navigation.ShowPopupAsync(view, PopupOptions.Empty, token: TestContext.Current.CancellationToken); var popupPage = (PopupPage)navigation.ModalStack[0]; @@ -1044,7 +1044,7 @@ public async Task ShowPopupAsync_ShouldThrowArgumentNullException_WhenViewIsNull // Act/Assert #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(null, PopupOptions.Empty, TestContext.Current.CancellationToken)); + await Assert.ThrowsAsync(() => navigation.ShowPopupAsync(null, PopupOptions.Empty, token: TestContext.Current.CancellationToken)); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } @@ -1074,7 +1074,7 @@ public async Task ShowPopupAsync_ShouldThrowArgumentNullException_WhenNavigation // Act / Assert #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - await Assert.ThrowsAsync(() => PopupExtensions.ShowPopupAsync((INavigation?)null, selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken)); + await Assert.ThrowsAsync(() => PopupExtensions.ShowPopupAsync((INavigation?)null, selfClosingPopup, PopupOptions.Empty, token: TestContext.Current.CancellationToken)); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } @@ -1103,7 +1103,7 @@ public async Task ShowPopupAsync_ShouldReturnNullResult_WhenPopupIsClosedWithout // Arrange // Act - var showPopupTask = navigation.ShowPopupAsync(new Popup(), PopupOptions.Empty, TestContext.Current.CancellationToken); + var showPopupTask = navigation.ShowPopupAsync(new Popup(), PopupOptions.Empty, token: TestContext.Current.CancellationToken); var popupPage = (PopupPage)navigation.ModalStack.Last(); await popupPage.CloseAsync(new PopupResult(true), TestContext.Current.CancellationToken); diff --git a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs index e4abe072d5..7189976e92 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs @@ -90,8 +90,8 @@ public async Task ShowPopupAsync_AwaitingShowPopupAsync_EnsurePreviousPopupClose var popupService = ServiceProvider.GetRequiredService(); // Act - await popupService.ShowPopupAsync(navigation, PopupOptions.Empty, CancellationToken.None); - await popupService.ShowPopupAsync(navigation, PopupOptions.Empty, CancellationToken.None); + await popupService.ShowPopupAsync(navigation, PopupOptions.Empty, cancellationToken: CancellationToken.None); + await popupService.ShowPopupAsync(navigation, PopupOptions.Empty, cancellationToken: CancellationToken.None); // Assert Assert.Empty(navigation.ModalStack); @@ -109,8 +109,8 @@ public async Task ShowPopupAsync_UsingPage_AwaitingShowPopupAsync_EnsurePrevious } // Act - await popupService.ShowPopupAsync(page, PopupOptions.Empty, CancellationToken.None); - await popupService.ShowPopupAsync(page, PopupOptions.Empty, CancellationToken.None); + await popupService.ShowPopupAsync(page, PopupOptions.Empty, cancellationToken: CancellationToken.None); + await popupService.ShowPopupAsync(page, PopupOptions.Empty, cancellationToken: CancellationToken.None); // Assert Assert.Empty(navigation.ModalStack); @@ -194,7 +194,7 @@ public async Task ShowPopupAsyncWithNotRegisteredServiceShouldThrowInvalidOperat } // Act // Assert - await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, TestContext.Current.CancellationToken)); + await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, cancellationToken: TestContext.Current.CancellationToken)); } [Fact(Timeout = (int)TestDuration.Short)] @@ -213,7 +213,7 @@ public async Task ShowPopupAsync_CancellationTokenExpired() } // Assert - await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, cts.Token)); + await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, cancellationToken: cts.Token)); } [Fact(Timeout = (int)TestDuration.Short)] @@ -227,7 +227,7 @@ public async Task ShowPopupAsync_CancellationTokenCanceled() await cts.CancelAsync(); // Assert - await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(navigation, PopupOptions.Empty, cts.Token)); + await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(navigation, PopupOptions.Empty, cancellationToken: cts.Token)); } [Fact(Timeout = (int)TestDuration.Medium)] @@ -244,7 +244,7 @@ public async Task ShowPopupAsyncShouldValidateProperBindingContext() } // Act - await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, TestContext.Current.CancellationToken); + await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, cancellationToken: TestContext.Current.CancellationToken); // Assert @@ -264,7 +264,7 @@ public async Task ShowPopupAsyncShouldReturnResultOnceClosed() } // Act - var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, CancellationToken.None); + var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, cancellationToken: CancellationToken.None); // Assert Assert.Same(mockPopup.Result, result.Result); @@ -283,7 +283,7 @@ public async Task ShowPopupTAsyncShouldReturnResultOnceClosed() } // Act - var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, CancellationToken.None); + var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, cancellationToken: CancellationToken.None); // Assert Assert.False(result.WasDismissedByTappingOutsideOfPopup); @@ -297,7 +297,7 @@ public async Task ShowPopupAsync_UsingNavigation_ShouldThrowArgumentNullExceptio // Act // Assert #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - await Assert.ThrowsAsync(() => popupService.ShowPopupAsync((INavigation?)null, PopupOptions.Empty, CancellationToken.None)); + await Assert.ThrowsAsync(() => popupService.ShowPopupAsync((INavigation?)null, PopupOptions.Empty, cancellationToken: CancellationToken.None)); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } @@ -309,7 +309,7 @@ public async Task ShowPopupAsync_UsingPage_ShouldThrowArgumentNullException_When // Act // Assert #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - await Assert.ThrowsAsync(() => popupService.ShowPopupAsync((Page?)null, PopupOptions.Empty, CancellationToken.None)); + await Assert.ThrowsAsync(() => popupService.ShowPopupAsync((Page?)null, PopupOptions.Empty, cancellationToken: CancellationToken.None)); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } @@ -389,7 +389,7 @@ public async Task ShowPopupAsync_ShouldThrowArgumentNullException_WhenViewModelI } // Act // Assert - await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, CancellationToken.None)); + await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, cancellationToken: CancellationToken.None)); } [Fact(Timeout = (int)TestDuration.Short)] @@ -405,7 +405,7 @@ public async Task ShowPopupAsync_ShouldReturnDefaultResult_WhenPopupIsClosedWith } // Act - var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, CancellationToken.None); + var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, cancellationToken: CancellationToken.None); // Assert Assert.Equal(mockPopup.Result, result.Result); diff --git a/src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs b/src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs index 752946f673..2bb20fa9cd 100644 --- a/src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs +++ b/src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs @@ -14,12 +14,13 @@ public static class PopupExtensions /// The current page that provides access to the implementation. /// The that will be displayed as the content in the popup. /// The that enable support for customizing the display and behavior of the presented popup. - /// This is an method. Use to this method and return - public static void ShowPopup(this Page page, View view, IPopupOptions? options = null) + /// Parameters that will be passed into the or its associated BindingContext if they implement . + /// This is an method. Use to this method and return + public static void ShowPopup(this Page page, View view, IPopupOptions? options = null, IDictionary? parameters = null) { ArgumentNullException.ThrowIfNull(page); - ShowPopup(page.Navigation, view, options); + ShowPopup(page.Navigation, view, options, parameters); } /// @@ -28,13 +29,19 @@ public static void ShowPopup(this Page page, View view, IPopupOptions? options = /// The implementation responsible for displaying the popup. Make sure to use the one associated with the that you wish the popup to be displayed on. /// The that will be displayed as the content in the popup. /// The that enable support for customizing the display and behavior of the presented popup. - /// This is an method. Use to this method - public static async void ShowPopup(this INavigation navigation, View view, IPopupOptions? options = null) + /// Parameters that will be passed into the or its associated BindingContext if they implement . + /// This is an method. Use to this method + public static async void ShowPopup(this INavigation navigation, View view, IPopupOptions? options = null, IDictionary? parameters = null) { ArgumentNullException.ThrowIfNull(navigation); ArgumentNullException.ThrowIfNull(view); var popupPage = new PopupPage(view, options ?? PopupOptions.Empty); + + if (parameters is not null) + { + popupPage.ApplyQueryAttributes(parameters); + } await navigation.PushModalAsync(popupPage, false); } @@ -45,14 +52,14 @@ public static async void ShowPopup(this INavigation navigation, View view, IPopu /// Current /// The that will be displayed as the content in the popup. /// The that enable support for customizing the display and behavior of the presented popup. - /// Parameters that will be passed into the or its associated BindingContext if they implement . - /// This is an method. Use to this method - public static async void ShowPopup(this Shell shell, View view, IPopupOptions? options = null, IDictionary? shellParameters = null) + /// Parameters that will be passed into the or its associated BindingContext if they implement . + /// This is an method. Use to this method + public static async void ShowPopup(this Shell shell, View view, IPopupOptions? options = null, IDictionary? parameters = null) { ArgumentNullException.ThrowIfNull(shell); ArgumentNullException.ThrowIfNull(view); - await shell.ShowPopupAsync(view, options, shellParameters); + await shell.ShowPopupAsync(view, options, parameters); } /// @@ -61,13 +68,14 @@ public static async void ShowPopup(this Shell shell, View view, IPopupOptions? o /// The current page that provides access to the implementation. /// The that will be displayed as the content in the popup. /// The that enable support for customizing the display and behavior of the presented popup. + /// Parameters that will be passed into the or its associated BindingContext if they implement . /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is canceled. Make sure to check the value to determine how the popup was closed. - public static Task> ShowPopupAsync(this Page page, View view, IPopupOptions? options = null, CancellationToken token = default) + public static Task> ShowPopupAsync(this Page page, View view, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken token = default) { ArgumentNullException.ThrowIfNull(page); - return page.Navigation.ShowPopupAsync(view, options, token); + return page.Navigation.ShowPopupAsync(view, options, parameters, token); } /// @@ -76,11 +84,12 @@ public static Task> ShowPopupAsync(this Page page /// The implementation responsible for displaying the popup. Make sure to use the one associated with the that you wish the popup to be displayed on. /// The that will be displayed as the content in the popup. /// The that enable support for customizing the display and behavior of the presented popup. + /// Parameters that will be passed into the or its associated BindingContext if they implement . /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is canceled. Make sure to check the value to determine how the popup was closed. - public static async Task> ShowPopupAsync(this INavigation navigation, View view, IPopupOptions? options = null, CancellationToken token = default) + public static async Task> ShowPopupAsync(this INavigation navigation, View view, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken token = default) { - var result = await ShowPopupAsync(navigation, view, options, token); + var result = await ShowPopupAsync(navigation, view, options, parameters, token); return GetPopupResult(result); } @@ -91,12 +100,12 @@ public static async Task> ShowPopupAsync(this INa /// Current /// The that will be displayed as the content in the popup. /// The that enable support for customizing the display and behavior of the presented popup. - /// Parameters that will be passed into the or its associated BindingContext if they implement . + /// Parameters that will be passed into the or its associated BindingContext if they implement . /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is canceled. Make sure to check the value to determine how the popup was closed. - public static async Task> ShowPopupAsync(this Shell shell, View view, IPopupOptions? options = null, IDictionary? shellParameters = null, CancellationToken token = default) + public static async Task> ShowPopupAsync(this Shell shell, View view, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken token = default) { - var result = await ShowPopupAsync(shell, view, options, shellParameters, token); + var result = await ShowPopupAsync(shell, view, options, parameters, token); return GetPopupResult(result); } @@ -107,13 +116,14 @@ public static async Task> ShowPopupAsync(this She /// The current page that provides access to the implementation. /// The that will be displayed as the content in the popup. /// The that enable support for customizing the display and behavior of the presented popup. + /// Parameters that will be passed into the or its associated BindingContext if they implement . /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is canceled. Make sure to check the value to determine how the popup was closed. - public static Task ShowPopupAsync(this Page page, View view, IPopupOptions? options = null, CancellationToken token = default) + public static Task ShowPopupAsync(this Page page, View view, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken token = default) { ArgumentNullException.ThrowIfNull(page); - return ShowPopupAsync(page.Navigation, view, options, token); + return ShowPopupAsync(page.Navigation, view, options, parameters, token); } /// @@ -122,9 +132,10 @@ public static Task ShowPopupAsync(this Page page, View view, IPopu /// The implementation responsible for displaying the popup. Make sure to use the one associated with the that you wish the popup to be displayed on. /// The that will be displayed as the content in the popup. /// The that enable support for customizing the display and behavior of the presented popup. + /// Parameters that will be passed into the or its associated BindingContext if they implement . /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is canceled. Make sure to check the value to determine how the popup was closed. - public static async Task ShowPopupAsync(this INavigation navigation, View view, IPopupOptions? options, CancellationToken token = default) + public static async Task ShowPopupAsync(this INavigation navigation, View view, IPopupOptions? options, IDictionary? parameters = null, CancellationToken token = default) { ArgumentNullException.ThrowIfNull(navigation); ArgumentNullException.ThrowIfNull(view); @@ -135,6 +146,11 @@ public static async Task ShowPopupAsync(this INavigation navigatio var popupPage = new PopupPage(view, options ?? PopupOptions.Empty); popupPage.PopupClosed += HandlePopupClosed; + + if (parameters is not null) + { + popupPage.ApplyQueryAttributes(parameters); + } await navigation.PushModalAsync(popupPage, false).WaitAsync(token); return await taskCompletionSource.Task.WaitAsync(token); @@ -152,10 +168,10 @@ void HandlePopupClosed(object? sender, IPopupResult e) /// Current /// The that will be displayed as the content in the popup. /// The that enable support for customizing the display and behavior of the presented popup. - /// Parameters that will be passed into the or its associated BindingContext if they implement . + /// Parameters that will be passed into the or its associated BindingContext if they implement . /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is cancelled. Make sure to check the value to determine how the popup was closed. - public static async Task ShowPopupAsync(this Shell shell, View view, IPopupOptions? options, IDictionary? shellParameters = null, CancellationToken token = default) + public static async Task ShowPopupAsync(this Shell shell, View view, IPopupOptions? options, IDictionary? parameters = null, CancellationToken token = default) { ArgumentNullException.ThrowIfNull(shell); ArgumentNullException.ThrowIfNull(view); @@ -173,13 +189,13 @@ public static async Task ShowPopupAsync(this Shell shell, View vie try { - if (shellParameters is null) + if (parameters is null) { await shell.GoToAsync(popupPageRoute).WaitAsync(token); } else { - await shell.GoToAsync(popupPageRoute, shellParameters).WaitAsync(token); + await shell.GoToAsync(popupPageRoute, parameters).WaitAsync(token); } return await taskCompletionSource.Task.WaitAsync(token); diff --git a/src/CommunityToolkit.Maui/Interfaces/IPopupService.shared.cs b/src/CommunityToolkit.Maui/Interfaces/IPopupService.shared.cs index 2273b5232c..13fa88f01e 100644 --- a/src/CommunityToolkit.Maui/Interfaces/IPopupService.shared.cs +++ b/src/CommunityToolkit.Maui/Interfaces/IPopupService.shared.cs @@ -13,7 +13,8 @@ public interface IPopupService /// Supports both Popup Type or Popup ViewModel Type /// The current visible page /// The that enable support for customizing the display and behavior of the presented popup. - void ShowPopup(Page page, IPopupOptions? options = null) + /// Parameters that will be passed into the view or its associated BindingContext if they implement . + void ShowPopup(Page page, IPopupOptions? options = null, IDictionary? parameters = null) where T : notnull; /// @@ -22,7 +23,8 @@ void ShowPopup(Page page, IPopupOptions? options = null) /// Supports both Popup Type or Popup ViewModel Type /// The implementation responsible for displaying the popup. Make sure to use the one associated with the that you wish the popup to be displayed on. /// The that enable support for customizing the display and behavior of the presented popup. - void ShowPopup(INavigation navigation, IPopupOptions? options = null) + /// Parameters that will be passed into the view or its associated BindingContext if they implement . + void ShowPopup(INavigation navigation, IPopupOptions? options = null, IDictionary? parameters = null) where T : notnull; /// @@ -31,8 +33,8 @@ void ShowPopup(INavigation navigation, IPopupOptions? options = null) /// Supports both Popup Type or Popup ViewModel Type /// Current /// The that enable support for customizing the display and behavior of the presented popup. - /// Parameters that will be passed into the view or its associated BindingContext if they implement . - void ShowPopup(Shell shell, IPopupOptions? options = null, IDictionary? shellParameters = null) + /// Parameters that will be passed into the view or its associated BindingContext if they implement . + void ShowPopup(Shell shell, IPopupOptions? options = null, IDictionary? parameters = null) where T : notnull; /// @@ -43,7 +45,8 @@ void ShowPopup(Shell shell, IPopupOptions? options = null, IDictionaryThe that enable support for customizing the display and behavior of the presented popup. /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is cancelled. Make sure to check the value to determine how the popup was closed. - Task ShowPopupAsync(Page page, IPopupOptions? options = null, CancellationToken cancellationToken = default) + /// Parameters that will be passed into the view or its associated BindingContext if they implement . + Task ShowPopupAsync(Page page, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken cancellationToken = default) where T : notnull; /// @@ -54,7 +57,8 @@ Task ShowPopupAsync(Page page, IPopupOptions? options = null, C /// The that enable support for customizing the display and behavior of the presented popup. /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is cancelled. Make sure to check the value to determine how the popup was closed. - Task ShowPopupAsync(INavigation navigation, IPopupOptions? options = null, CancellationToken cancellationToken = default) + /// Parameters that will be passed into the view or its associated BindingContext if they implement . + Task ShowPopupAsync(INavigation navigation, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken cancellationToken = default) where T : notnull; /// @@ -63,10 +67,10 @@ Task ShowPopupAsync(INavigation navigation, IPopupOptions? opti /// Supports both Popup Type or Popup ViewModel Type /// Current /// The that enable support for customizing the display and behavior of the presented popup. - /// Parameters that will be passed into the view or its associated BindingContext if they implement . + /// Parameters that will be passed into the view or its associated BindingContext if they implement . /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is cancelled. Make sure to check the value to determine how the popup was closed. - Task ShowPopupAsync(Shell shell, IPopupOptions? options, IDictionary? shellParameters = null, CancellationToken cancellationToken = default) + Task ShowPopupAsync(Shell shell, IPopupOptions? options, IDictionary? parameters = null, CancellationToken cancellationToken = default) where T : notnull; /// @@ -78,7 +82,8 @@ Task ShowPopupAsync(Shell shell, IPopupOptions? options, IDicti /// The that enable support for customizing the display and behavior of the presented popup. /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is cancelled. Make sure to check the value to determine how the popup was closed. - Task> ShowPopupAsync(Page page, IPopupOptions? options = null, CancellationToken cancellationToken = default) + /// Parameters that will be passed into the view or its associated BindingContext if they implement . + Task> ShowPopupAsync(Page page, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken cancellationToken = default) where T : notnull; /// @@ -90,7 +95,8 @@ Task> ShowPopupAsync(Page page, IPopupOptions? /// The that enable support for customizing the display and behavior of the presented popup. /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is cancelled. Make sure to check the value to determine how the popup was closed. - Task> ShowPopupAsync(INavigation navigation, IPopupOptions? options = null, CancellationToken cancellationToken = default) + /// Parameters that will be passed into the view or its associated BindingContext if they implement . + Task> ShowPopupAsync(INavigation navigation, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken cancellationToken = default) where T : notnull; /// @@ -100,10 +106,10 @@ Task> ShowPopupAsync(INavigation navigation, I /// Popup Result Type /// Current /// The that enable support for customizing the display and behavior of the presented popup. - /// Parameters that will be passed into the view or its associated BindingContext if they implement . + /// Parameters that will be passed into the view or its associated BindingContext if they implement . /// A providing support for canceling the wait for a result to be returned. This will not close the popup. /// An when the popup is closed or the is cancelled. Make sure to check the value to determine how the popup was closed. - Task> ShowPopupAsync(Shell shell, IPopupOptions? options = null, IDictionary? shellParameters = null, CancellationToken cancellationToken = default) + Task> ShowPopupAsync(Shell shell, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken cancellationToken = default) where T : notnull; /// diff --git a/src/CommunityToolkit.Maui/Services/PopupService.shared.cs b/src/CommunityToolkit.Maui/Services/PopupService.shared.cs index a72243d25d..c1bfd88268 100644 --- a/src/CommunityToolkit.Maui/Services/PopupService.shared.cs +++ b/src/CommunityToolkit.Maui/Services/PopupService.shared.cs @@ -33,44 +33,44 @@ public PopupService() } /// - /// This is an method. Use to this method - public void ShowPopup(Page page, IPopupOptions? options = null) where T : notnull + /// This is an method. Use to this method + public void ShowPopup(Page page, IPopupOptions? options = null, IDictionary? parameters = null) where T : notnull { ArgumentNullException.ThrowIfNull(page); - ShowPopup(page.Navigation, options); + ShowPopup(page.Navigation, options, parameters); } /// - /// This is an method. Use to this method - public void ShowPopup(INavigation navigation, IPopupOptions? options = null) where T : notnull + /// This is an method. Use to this method + public void ShowPopup(INavigation navigation, IPopupOptions? options = null, IDictionary? parameters = null) where T : notnull { ArgumentNullException.ThrowIfNull(navigation); var popupContent = GetPopupContent(serviceProvider.GetRequiredService()); - navigation.ShowPopup(popupContent, options); + navigation.ShowPopup(popupContent, options, parameters); } /// /// This is an method. Use to this method - public void ShowPopup(Shell shell, IPopupOptions? options = null, IDictionary? shellParameters = null) where T : notnull + public void ShowPopup(Shell shell, IPopupOptions? options = null, IDictionary? parameters = null) where T : notnull { ArgumentNullException.ThrowIfNull(shell); var popupContent = GetPopupContent(serviceProvider.GetRequiredService()); - shell.ShowPopup(popupContent, options, shellParameters); + shell.ShowPopup(popupContent, options, parameters); } /// - public Task ShowPopupAsync(Page page, IPopupOptions? options = null, CancellationToken cancellationToken = default) where T : notnull + public Task ShowPopupAsync(Page page, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken cancellationToken = default) where T : notnull { ArgumentNullException.ThrowIfNull(page); - return ShowPopupAsync(page.Navigation, options, cancellationToken); + return ShowPopupAsync(page.Navigation, options, parameters, cancellationToken); } /// - public Task ShowPopupAsync(INavigation navigation, IPopupOptions? options = null, CancellationToken token = default) + public Task ShowPopupAsync(INavigation navigation, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken token = default) where T : notnull { ArgumentNullException.ThrowIfNull(navigation); @@ -79,11 +79,11 @@ public Task ShowPopupAsync(INavigation navigation, IPopupOption var popupContent = GetPopupContent(serviceProvider.GetRequiredService()); - return navigation.ShowPopupAsync(popupContent, options, token); + return navigation.ShowPopupAsync(popupContent, options, parameters, token); } /// - public Task ShowPopupAsync(Shell shell, IPopupOptions? options, IDictionary? shellParameters, CancellationToken token) where T : notnull + public Task ShowPopupAsync(Shell shell, IPopupOptions? options, IDictionary? parameters, CancellationToken token) where T : notnull { ArgumentNullException.ThrowIfNull(shell); @@ -91,20 +91,21 @@ public Task ShowPopupAsync(Shell shell, IPopupOptions? options, var popupContent = GetPopupContent(serviceProvider.GetRequiredService()); - return shell.ShowPopupAsync(popupContent, options, shellParameters, token); + return shell.ShowPopupAsync(popupContent, options, parameters, token); } /// - public Task> ShowPopupAsync(Page page, IPopupOptions? options = null, CancellationToken cancellationToken = default) where T : notnull + public Task> ShowPopupAsync(Page page, IPopupOptions? options = null, IDictionary? parameters = null, CancellationToken cancellationToken = default) where T : notnull { ArgumentNullException.ThrowIfNull(page); - return ShowPopupAsync(page.Navigation, options, cancellationToken); + return ShowPopupAsync(page.Navigation, options, parameters, cancellationToken); } /// public Task> ShowPopupAsync(INavigation navigation, IPopupOptions? options = null, + IDictionary? parameters = null, CancellationToken token = default) where T : notnull { @@ -113,18 +114,18 @@ public Task> ShowPopupAsync(INavigation naviga token.ThrowIfCancellationRequested(); var popupContent = GetPopupContent(serviceProvider.GetRequiredService()); - return navigation.ShowPopupAsync(popupContent, options, token); + return navigation.ShowPopupAsync(popupContent, options, parameters, token); } /// - public Task> ShowPopupAsync(Shell shell, IPopupOptions? options, IDictionary? shellParameters = null, CancellationToken token = default) where T : notnull + public Task> ShowPopupAsync(Shell shell, IPopupOptions? options, IDictionary? parameters = null, CancellationToken token = default) where T : notnull { ArgumentNullException.ThrowIfNull(shell); token.ThrowIfCancellationRequested(); var popupContent = GetPopupContent(serviceProvider.GetRequiredService()); - return shell.ShowPopupAsync(popupContent, options, shellParameters, token); + return shell.ShowPopupAsync(popupContent, options, parameters, token); } /// diff --git a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs index 8cd851161c..3b448335aa 100644 --- a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs +++ b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs @@ -161,7 +161,7 @@ void HandlePopupPropertyChanged(object? sender, PropertyChangedEventArgs e) } } - void IQueryAttributable.ApplyQueryAttributes(IDictionary query) + public void ApplyQueryAttributes(IDictionary query) { if (popup is IQueryAttributable popupIQueryAttributable) {