-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[macOS] Display alert by Window #14361
Conversation
src/Controls/src/Core/Platform/AlertManager/AlertManager.iOS.cs
Outdated
Show resolved
Hide resolved
src/Controls/src/Core/Platform/AlertManager/AlertManager.iOS.cs
Outdated
Show resolved
Hide resolved
src/Controls/src/Core/Platform/AlertManager/AlertManager.iOS.cs
Outdated
Show resolved
Hide resolved
bool PageIsInThisWindow(Page page) | ||
{ | ||
var window = page?.Window; | ||
var platformWindow = window?.MauiContext.GetPlatformWindow(); | ||
|
||
if (window is null || platformWindow is null) | ||
return false; | ||
|
||
return platformWindow == Window; | ||
} | ||
bool PageIsInThisWindow(Page page) => | ||
page?.Window == VirtualView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alert manager already knows about the window, so this is now possible. The iOS code had everything set up, but Windows just needed an extra constructor argument for the helper to simplify all this.
All the logic has been rewritten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On windows if you close a window while a dialog box is open then dialog boxes stop working all together
- open the Gallery
- navigate to core => multi window
- open a new window
- click "open dialog" on that new window
- close the new window without closing the dialog
- now try to click "open dialog" on the original window
Oh wow. Let me look at that then... |
static Task<bool>? CurrentAlert; | ||
static Task<string?>? CurrentPrompt; | ||
Task<bool>? CurrentAlert; | ||
Task<string?>? CurrentPrompt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PureWeen this was causing the issue. No need for statics anymore! We have multiple windows!
} | ||
|
||
internal void Unsubscribe(Window window) | ||
{ | ||
var platformWindow = window.MauiContext.GetPlatformWindow(); | ||
|
||
var toRemove = Subscriptions.Where(s => s.Window == platformWindow).ToList(); | ||
var toRemove = Subscriptions.Where(s => s.PlatformView == platformWindow).ToList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PureWeen I though that the use of LINQ was limited, should we remove it from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, I am surprised to see LINQ when a foreach would have worked and made the deps smaller.
/backport to net7.0 |
Started backporting to net7.0: https://github.com/dotnet/maui/actions/runs/5270383073 |
@hartez backporting to net7.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Display alert by Window on macOS
Applying: Unify the logic a bit
error: sha1 information is lacking or useless (src/Controls/src/Core/Platform/AlertManager/AlertManager.iOS.cs).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 Unify the logic a bit
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@hartez an error occurred while backporting to net7.0, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
* Display alert by Window on macOS * Unify the logic a bit --------- Co-authored-by: Matthew Leibowitz <[email protected]>
* Display alert by Window on macOS * Unify the logic a bit --------- Co-authored-by: Matthew Leibowitz <[email protected]>
Description of Change
Display alert by Window on macOS.
This fix is similar to #14229
To test the changes, launch the .NET MAUI Gallery and navigate to Core > MultiWindow. Open a secondary Window and then, tap the button to display an alert. The alert only must appear in the parent Window.
Issues Fixed
Fixes #14343