-
Notifications
You must be signed in to change notification settings - Fork 410
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
[Proposal] Add Popup.CloseAsync()
#1222
Comments
Approve. Can we change only return type from void to Task/ValueTask and keep the name “Close”? The app will behave the same until user fix the warning and await method |
Thanks Vlad! That was my initial plan, but I decided against replacing the existing
That being said, you know how much I love async/await and I always love to push developers to use the "better" API, so if the other maintainers agree that we should replace |
Approve. I like the solution you propose @brminnick for the following reasons:
|
I'm happy to approve this also |
Great! Approved ✅ |
Hey, quick question. Does it solve #1111 ? |
Yup! Thanks, I've added linked it to the PR. |
Reopening Proposal. Only Proposals moved to the |
Feature name
Add
Popup.CloseAsync()
Link to discussion
Discussed in June 2023 Standup:
https://github.com/CommunityToolkit/Maui/wiki/2023-June-Standup
Progress tracker
Popup.CloseAsync()
MicrosoftDocs/CommunityToolkit#285Summary
This Proposal adds the following API to
Popup
:CloseAsync()
returns once the operating system has dismissedPopup
from the page.Motivation
Currently,
Popup
only offers one method to programmatically dismiss it from the screen:public void Close();
.However, on MacCatalyst and iOS, the code required to dismiss the Popup uses async/await to dismiss the
UIViewController
:Maui/src/CommunityToolkit.Maui.Core/Handlers/Popup/PopupHandler.macios.cs
Lines 14 to 23 in e89e7da
The existing
Close()
API is thus acting in a fire-and-forget manner; the method is returning to the caller before the Popup has been dismissed on iOS + MacCatalyst.Detailed Design
IPopup.shared.cs
This API update requires a
TaskCompletionSource
inIPopup
that can be referenced by both the Handler and the Control.This is required because the PropertyMappers / CommandMappers that .NET MAUI use for Handlers are not asynchronous (they cannot be
await
d).We will instead tell the Control to
await PopupDismissedTaskCompletionSource.Task
afterIPopup.Closed()
has been called. Then, inPopupHandler.MapOnClosed
, we will callPopupDismissedTaskCompletionSource TrySetResult()
after the operating system has dismissed thePopup
from the page.Popup.shared.cs
This Proposal also requires a new API
public Task Popup.CloseAsync(object? result = null)
;Usage Syntax
Drawbacks
Only iOS + MacCatalyst defer to a different thread when dismissing the Popup; Android and Windows can dismiss the Popup synchronously. Adding a method that returns
Task
adds a bit of overhead to our users, however, the overhead should be negligible as users typically only display, and subsequently close, one Popup at a time.Alternatives
This Proposal can be updated to remove the fire-and-forget method,
void Close()
.However, removing an existing API is a breaking change.
Unresolved Questions
Should we instead return
ValueTask
?The text was updated successfully, but these errors were encountered: