[MacCatalyst] Get correct window associated with the Popup#1409
[MacCatalyst] Get correct window associated with the Popup#1409pictos merged 5 commits intoCommunityToolkit:mainfrom
Conversation
|
@microsoft-github-policy-service agree |
|
Love this! @pictos - Does this introduce any breaking changes to Popup? |
Nope. None so far. No method signature changes (e.g. parameters, return types). |
|
Oh sorry. Just noticed that you tagged someone else |
pictos
left a comment
There was a problem hiding this comment.
Thanks for the PR @babenkovitaliy, I was thinking here... We know what's the Popup.Parent, and it should be a Page, can't we get the information on that Page instead of looking up all available ViewControllers? Since we have a loop inside a loop it could be a O(n²)
From my review it doesn't have any break-change |
Co-authored-by: Pedro Jesus <[email protected]>
I tried doing that.
TLDR: Virtual Windows, Views, ViewControllers etc. know nothing about Native UIWindows, UIViews and UIViewControllers. However, Native UIWindows, UIViews and UIViewControllers do reference that Virtual Windows, ViewControllers and Views. |
|
@dotnet-policy-service agree |
You can do something like var pagehandler = VirtualView.Parent.Handler as PageHandler;
var viewController = pagehandler.ViewController;and we're sure it's a |
I'll try to look into this and update the PR if this indeed will work. This would be a much better solution. The small catch is that I may have to tackle this sometime this weekend. |
Use PageHandler to get native UIViewController associated with the popup.
…rged it with the variable assignment.
|
Alright. I have made the changes. I have tested out in a separate app I built where I referenced the compiled DLL files. The Popups work nicely now. Fun, but controversial sidenote: I never realized how much I got spoiled by Visual Studio for Windows IDE. The rebase process is so much more nicer when using the GUI vs the command line (when you are not familiar with the command line). Since I was using Visual Studio for Mac, the GUI rebase process is more painful, so I had to switch over to command line. Ashamed to admit that it took me longer than it should have. |
|
@babenkovitaliy if I told you how many times I missed up my branches using rebase, on both GUI and command line, you would not believe it kkkkk. Thanks for the update and glad that worked as expected (: |
|
These changes look good. Thanks @babenkovitaliy and @pictos Is it good to merge? |
|
Yes, it's. Enabled the auto-merge |


This PR solves an issue with where a MacCatalyst application has multi-windows enabled, but when creating a popup, it opens up to a random window instead of the correct one.
Description of Change
There is an issue with this line of code:
var rootViewController = WindowStateManager.Default.GetCurrentUIViewController() ?? throw new InvalidOperationException($"{nameof(PageHandler.ViewController)} cannot be null.");It assumes that the application will be in a single-window state (e.g. Shell app). However, with MacOS, apps can also be multi-window applications.
This fix looks through all windows, locates its "View" (e.g. ContentPage), then compares it against the Parent View of the Popup. If it matches, then that is where the popup will display. Previously, it displayed on whatever window this method returned:
WindowStateManager.Default.GetCurrentUIViewController()Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PR (fresh fork, nothing to rebase)Additional information
With these code changes, the existing demo app still works without issues. When it comes to creating a demo for this fix, this would require a massive rewrite of the demo app, since the main UI is coded as a Shell app (single window).