[Mac Catalyst] Set window dimensions
Description of Change
This PR demonstrates that Mac Catalyst applications can change window dimensions.
Demo
https://github.com/user-attachments/assets/64e0a875-24b9-4410-9b5c-774ad746cb2a
Issues Fixed
Fixes #9704
Resources
- #4942 introduced window sizing in MAUI
- https://developer.apple.com/documentation/uikit/uiwindowscene/3975944-requestgeometryupdate
- https://developer.apple.com/documentation/uikit/uiwindowscene/3975943-effectivegeometry
- This property is key-value observing (KVO) compliant. Observing effectiveGeometry is the recommended way to receive notifications of changes to the window scene’s geometry. These changes can occur because of user interaction or as a result of the system resolving a geometry request.
- https://stackoverflow.com/questions/72281147/center-the-main-window-of-an-app-in-mac-catalyst
- https://stackoverflow.com/questions/58159414/how-to-detect-window-resizing-in-mac-catalyst
- https://github.com/mandel-macaque/xamarin-macios/blob/9b64421e488655386d31e02fc81f232c82c6a523/src/uikit.cs#L27311
I think all this looks good, just had a nit about collapsing and reducing the if block complexity. Then you are going to have to use the proxy event system as anything referencing maui from the native world will leak the entire universe as they are all linked.
Although now with @PureWeen magic in net9 this may not be the case. But, for net8 we are going to have to proxy all the things.
I think all this looks good, just had a nit about collapsing and reducing the if block complexity. Then you are going to have to use the proxy event system as anything referencing maui from the native world will leak the entire universe as they are all linked.
I noticed an issue when initial window dimension was not correctly handled (window was placed always to X=0 and Y=0). I'm not sure how else to fix it than to do: 3e17515e1f144ddc109128d7d042e421f2a5c1cf (where I basically wait until the new API sends an event with proper window dimensions, at first, some values are NaNs.)
tl;dr: The controls sample app I use for testing appears to work correctly with the latest commit (3e17515e1f144ddc109128d7d042e421f2a5c1cf).
But I guess there are more scenarios which should be tested, hopefully tests cover some of those scenarios.
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Hm, PageLayoutDoesNotExceedWindowBounds failed. That looks like it might be an issue. However, I'm not really sure how to run that test on my mac machine (in VS Code).
@mattleibow Could you take a look please?
@MartyIX to run the failing test you need to set this in your vs code
after a successful build, you should see the following screen:
then to run this particular test do as I did in this video:
https://github.com/user-attachments/assets/8cf95ea8-7f90-4fe5-ad5a-b39d6227cb95
@MartyIX to run the failing test you need to set this in your vs code
Yeah, I figured it out in the meanwhile. Sorry for not updating the post. However, I'm very much unsure how to fix the test.
Basically, this https://github.com/dotnet/maui/pull/24001/files#diff-3dbcd72ac0c8c03db5b1be3c27ad840dd2e0b30ab72ecb22a9f33d9b9bdd62b4R22 makes sure that we get effectiveGeometry updates but those updates take some time to come. But the test supposes that we know immediately window dimensions (I think).
Azure Pipelines successfully started running 3 pipeline(s).
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
@mattleibow Hey, could you take another look please?
@drasticactions Could you take a look please?
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
@mattleibow Could you take a look please?
Would this also fix the window positioning error?
Would this also fix the window positioning error?
Could you explain more in detail what you mean?
Would this also fix the window positioning error?
Could you explain more in detail what you mean?
If I understand right from the video (I haven't cloned and ran this), your changes would fix the error of being unable to change window dimensions programmatically on mac. If that's right, does your change also address moving the location of the app's window itself? (App.X / App.Y)
Would this also fix the window positioning error?
Could you explain more in detail what you mean?
If I understand right from the video (I haven't cloned and ran this), your changes would fix the error of being unable to change window dimensions programmatically on mac. If that's right, does your change also address moving the location of the app's window itself? (App.X / App.Y)
"Center window" works for me, so it appears it works.
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
It appears that
dbug: 2024-12-17 02:30:28.774949-0800 Microsoft.Maui.Controls.DeviceTests[21489:51508457] at Microsoft.Maui.DeviceTests.ShellTests.PageLayoutDoesNotExceedWindowBounds() in /_/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs:line 73
dbug: --- End of stack trace from previous location ---
dbug: 2024-12-17 02:30:28.775023-0800 Microsoft.Maui.Controls.DeviceTests[21489:51508457] Execution time: 0.1023795
dbug: 2024-12-17 02:30:28.775085-0800 Microsoft.Maui.Controls.DeviceTests[21489:51508457] Test trait name: Category
dbug: 2024-12-17 02:30:28.775152-0800 Microsoft.Maui.Controls.DeviceTests[21489:51508457] value: Shell
dbug: 2024-12-17 02:30:28.775204-0800 Microsoft.Maui.Controls.DeviceTests[21489:51508457] value: Shell
dbug: 2024-12-17 02:30:28.775260-0800 Microsoft.Maui.Controls.DeviceTests[21489:51508457] value: Shell
dbug: 2024-12-17 02:30:28.775348-0800 Microsoft.Maui.Controls.DeviceTests[21489:51508457] value: Shell
dbug: 2024-12-17 02:30:28.775406-0800 Microsoft.Maui.Controls.DeviceTests[21489:51508457] value: Shell
dbug: 2024-12-17 02:30:28.775471-0800 Microsoft.Maui.Controls.DeviceTests[21489:51508457] [FAIL] PageLayoutDoesNotExceedWindowBounds
dbug: 2024-12-17 02:30:28.775538-0800 Microsoft.Maui.Controls.DeviceTests[21489:51508457] [FAIL] PageLayoutDoesNotExceedWindowBounds Test name: PageLayoutDoesNotExceedWindowBounds
fails on iOS.
/azp run
Azure Pipelines successfully started running 3 pipeline(s).