maui icon indicating copy to clipboard operation
maui copied to clipboard

[Mac Catalyst] Set window dimensions

Open MartyIX opened this issue 1 year ago • 13 comments

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

MartyIX avatar Aug 04 '24 07:08 MartyIX

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.

mattleibow avatar Aug 14 '24 19:08 mattleibow

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.)

MartyIX avatar Aug 14 '24 21:08 MartyIX

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.

MartyIX avatar Aug 14 '24 21:08 MartyIX

/azp run

mattleibow avatar Aug 15 '24 16:08 mattleibow

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Aug 15 '24 16:08 azure-pipelines[bot]

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).

MartyIX avatar Aug 15 '24 21:08 MartyIX

@mattleibow Could you take a look please?

MartyIX avatar Aug 20 '24 07:08 MartyIX

@MartyIX to run the failing test you need to set this in your vs code Screenshot 2024-10-16 at 20 10 06

after a successful build, you should see the following screen:

Screenshot 2024-10-16 at 20 11 24

then to run this particular test do as I did in this video:

https://github.com/user-attachments/assets/8cf95ea8-7f90-4fe5-ad5a-b39d6227cb95

kubaflo avatar Oct 16 '24 18:10 kubaflo

@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.

MartyIX avatar Oct 16 '24 18:10 MartyIX

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).

MartyIX avatar Oct 16 '24 18:10 MartyIX

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 18 '24 07:10 azure-pipelines[bot]

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 20 '24 18:10 azure-pipelines[bot]

/azp run

PureWeen avatar Nov 03 '24 15:11 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Nov 03 '24 15:11 azure-pipelines[bot]

/azp run

PureWeen avatar Nov 15 '24 20:11 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Nov 15 '24 20:11 azure-pipelines[bot]

@mattleibow Hey, could you take another look please?

MartyIX avatar Nov 23 '24 07:11 MartyIX

@drasticactions Could you take a look please?

MartyIX avatar Nov 25 '24 13:11 MartyIX

/azp run

PureWeen avatar Nov 27 '24 04:11 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Nov 27 '24 04:11 azure-pipelines[bot]

@mattleibow Could you take a look please?

MartyIX avatar Dec 04 '24 13:12 MartyIX

Would this also fix the window positioning error?

axolmain avatar Dec 05 '24 09:12 axolmain

Would this also fix the window positioning error?

Could you explain more in detail what you mean?

MartyIX avatar Dec 05 '24 09:12 MartyIX

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)

axolmain avatar Dec 06 '24 18:12 axolmain

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)

image

"Center window" works for me, so it appears it works.

MartyIX avatar Dec 07 '24 09:12 MartyIX

/azp run

rmarinho avatar Dec 16 '24 16:12 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Dec 16 '24 16:12 azure-pipelines[bot]

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.

MartyIX avatar Dec 17 '24 10:12 MartyIX

/azp run

PureWeen avatar Dec 17 '24 21:12 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Dec 17 '24 21:12 azure-pipelines[bot]