Add TryShowPopupAsync and TryClosePopupAsync#3244
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a standardized Try/Result pattern for popups (and aligns it with existing storage results) by introducing TryShowPopupAsync / TryClosePopupAsync APIs and a shared IResult interface. It also moves Folder into the CommunityToolkit.Maui.Core namespace (breaking change).
Changes:
- Add
TryShowPopupAsyncandTryClosePopupAsyncextension methods returningIShowPopupResult(*)/IClosePopupResult(*)with standardizedIResultsemantics. - Introduce
IResultand apply it acrossFileSaverResult,FolderPickerResult, and new popup result types. - Move
FolderfromCommunityToolkit.Maui.Core.PrimitivestoCommunityToolkit.Maui.Core.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs | Minor argument validation cleanup for shellRoute. |
| src/CommunityToolkit.Maui/Primitives/ShowPopupResult.shared.cs | Adds concrete result types implementing IShowPopupResult(*). |
| src/CommunityToolkit.Maui/Primitives/PopupResult.shared.cs | Makes PopupResult<T> inheritable to support new result wrappers; formats exception message. |
| src/CommunityToolkit.Maui/Primitives/ClosePopupResult.cs | Adds concrete result types implementing IClosePopupResult(*). |
| src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs | Adds TryShowPopupAsync / TryClosePopupAsync APIs and refactors some internal calls. |
| src/CommunityToolkit.Maui.UnitTests/Views/Popup/PopupTests.cs | Adds test for typed popup completion via CloseAsync(result). |
| src/CommunityToolkit.Maui.UnitTests/Views/Popup/PopupResultTests.cs | Adds unit tests validating default IResult behavior. |
| src/CommunityToolkit.Maui.UnitTests/Views/Popup/PopupPageTests.cs | Adds tests for Shell argument validation and query attribute forwarding edge cases. |
| src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs | Adds additional constructor and cancellation behavior tests. |
| src/CommunityToolkit.Maui.UnitTests/Mocks/FolderPickerImplementationMock.cs | Updates namespace import for Folder move. |
| src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs | Adds extensive coverage for new Try* popup APIs across Page/INavigation/Shell. |
| src/CommunityToolkit.Maui.UnitTests/Essentials/FolderPickerTests.cs | Adds IResult semantics tests for FolderPickerResult. |
| src/CommunityToolkit.Maui.UnitTests/Essentials/FileSaverTests.cs | Adds IResult semantics tests for FileSaverResult. |
| src/CommunityToolkit.Maui.Core/Primitives/Folder.shared.cs | Moves Folder into CommunityToolkit.Maui.Core namespace (breaking). |
| src/CommunityToolkit.Maui.Core/Interfaces/IShowPopupResult.cs | Introduces IShowPopupResult(*) interfaces combining IPopupResult(*) + IResult. |
| src/CommunityToolkit.Maui.Core/Interfaces/IResult.shared.cs | Introduces standardized IResult interface with default implementations. |
| src/CommunityToolkit.Maui.Core/Interfaces/IClosePopupResult.cs | Introduces IClosePopupResult(*) interfaces combining IPopupResult(*) + IResult. |
| src/CommunityToolkit.Maui.Core/Essentials/FolderPicker/FolderPickerResult.shared.cs | Implements IResult on FolderPickerResult. |
| src/CommunityToolkit.Maui.Core/Essentials/FolderPicker/FolderPickerImplementation.windows.cs | Updates namespace import for Folder move. |
| src/CommunityToolkit.Maui.Core/Essentials/FolderPicker/FolderPickerImplementation.net.cs | Updates namespace import for Folder move. |
| src/CommunityToolkit.Maui.Core/Essentials/FolderPicker/FolderPickerImplementation.macios.cs | Updates namespace import for Folder move. |
| src/CommunityToolkit.Maui.Core/Essentials/FolderPicker/FolderPickerImplementation.android.cs | Updates namespace import for Folder move. |
| src/CommunityToolkit.Maui.Core/Essentials/FileSaver/FileSaverResult.shared.cs | Implements IResult on FileSaverResult. |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
…om/CommunityToolkit/Maui into Add-TryShowPopup-and-TryClosePopup
| namespace CommunityToolkit.Maui; | ||
|
|
||
| /// <inheritdoc cref="IClosePopupResult" /> | ||
| record ClosePopupResult(bool WasDismissedByTappingOutsideOfPopup, Exception? Exception) |
There was a problem hiding this comment.
ClosePopupResult and PopupResult as for me technically the same. We can't get result from not closed Popup. I suggest keeping only PopupResult
| /// </summary> | ||
| /// <param name="WasDismissedByTappingOutsideOfPopup">True if Popup is closed by tapping outside popup</param> | ||
| /// <param name="Exception">Exception if operation failed</param> | ||
| record ShowPopupResult(bool WasDismissedByTappingOutsideOfPopup, Exception? Exception) : PopupResult(WasDismissedByTappingOutsideOfPopup), IShowPopupResult; |
There was a problem hiding this comment.
The same here. ShowPopupResult sounds like result that is returned right after Popup is shown. And in that case WasDismissedByTappingOutsideOfPopup is not relevant.
| /// <summary> | ||
| /// Closes the most recent popup and returns an <see cref="IClosePopupResult"/> that provides details about the closure. | ||
| /// </summary> | ||
| public static async Task<IClosePopupResult> TryClosePopupAsync(this INavigation navigation, CancellationToken token = default) |
There was a problem hiding this comment.
Do we really need interfaces for Popup results? We always return ClosePopupResult.
Description of Change
As discussed in the June 2026 Standup, this Pull Request implements
TryShowPopupAsyncandTryClosePopupAsync.This PR also adds
IResultto standardize the Try/Result pattern acrossFileSaverResult,FolderPickerResult,ShowPopupResultandClosePopupResult.PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
There is a breaking change in this PR: I removed the
CommunityToolkit.Maui.Core.Primitivesnamespace. This should've never existed;Folderhad been using the incorrect namespace.