Skip to content
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

[Windows] Fix setting flyout width (#19068) #19070

Merged
merged 1 commit into from Dec 7, 2023

Conversation

molesmoke
Copy link
Contributor

@molesmoke molesmoke commented Nov 28, 2023

PaneContentGrid width/height will be zero if the flyout has not yet been shown

Description of Change

Ensures a valid size is calculated for the PaneContentGrid if the flyout has not been shown

Issues Fixed

Fixes #19068

@molesmoke molesmoke requested a review from a team as a code owner November 28, 2023 04:46
@ghost ghost added the community ✨ Community Contribution label Nov 28, 2023
@ghost
Copy link

ghost commented Nov 28, 2023

Hey there @molesmoke! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@Eilon Eilon added the area/layout 🔲 StackLayout, GridLayout, ScrollView, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Nov 28, 2023
@mattleibow
Copy link
Member

Are you able to add some device tests?

@jeremy-visionaid
Copy link
Contributor

Are you able to add some device tests?

@mattleibow Basically, no. Although I was able to get the Controls.DeviceTests project to build by removing the non-Windows and profiling projects from the solution filter, I can't for the life of me get the unit tests to run.

I was able to verify for myself that it fixed the crash by altering Maui.Controls.Sample, but it doesn't look to me like the following puts the project in a usable state to run the unit tests:

dotnet cake --target=VS --workloads=global --windows

Is there perhaps some documentation on how to run the tests that I'm missing?

The "Tests" output window is plastered with errors (17.9.0 Preview 1.1), and I wasn't able to get it to run from the command line either with dotnet test.

Could not determine target device configuration. Exception: System.Runtime.InteropServices.COMException (0x80020009): The method or operation is not implemented.
   at EnvDTE.Property.get_Value()
   at Microsoft.VisualStudio.TestWindow.ShellServices.ProjectDataImpl.<GetRemoteMachineAddressAsync>d__36.MoveNext()
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Could not find testhost
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo) in /_/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs:line 406
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs:line 223
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.InitializeDiscovery(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler, Boolean skipDefaultAdapters) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs:line 149
System.InvalidOperationException: The provided manager was not found in any slot.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ParallelOperationManager`3.ClearCompletedSlot(TManager completedManager)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ParallelOperationManager`3.RunNextWork(TManager completedManager) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelOperationManager.cs:line 265
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel.ParallelProxyDiscoveryManager.HandlePartialDiscoveryComplete(IProxyDiscoveryManager proxyDiscoveryManager, Int64 totalTests, IEnumerable`1 lastChunk, Boolean isAborted) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyDiscoveryManager.cs:line 200
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel.ParallelDiscoveryEventsHandler.HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable`1 lastChunk) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelDiscoveryEventsHandler.cs:line 75
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.InitializeDiscovery(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler, Boolean skipDefaultAdapters) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs:line 156
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs:line 177
System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: The provided manager was not found in any slot.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ParallelOperationManager`3.ClearCompletedSlot(TManager completedManager)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ParallelOperationManager`3.RunNextWork(TManager completedManager) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelOperationManager.cs:line 265
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel.ParallelProxyDiscoveryManager.HandlePartialDiscoveryComplete(IProxyDiscoveryManager proxyDiscoveryManager, Int64 totalTests, IEnumerable`1 lastChunk, Boolean isAborted) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyDiscoveryManager.cs:line 200
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel.ParallelDiscoveryEventsHandler.HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable`1 lastChunk) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelDiscoveryEventsHandler.cs:line 75
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs:line 189
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel.ParallelProxyDiscoveryManager.<>c__DisplayClass27_0.<DiscoverTestsOnConcurrentManager>b__0() in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyDiscoveryManager.cs:line 313
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.InvalidOperationException: The provided manager was not found in any slot.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ParallelOperationManager`3.ClearCompletedSlot(TManager completedManager)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ParallelOperationManager`3.RunNextWork(TManager completedManager) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelOperationManager.cs:line 265
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel.ParallelProxyDiscoveryManager.HandlePartialDiscoveryComplete(IProxyDiscoveryManager proxyDiscoveryManager, Int64 totalTests, IEnumerable`1 lastChunk, Boolean isAborted) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyDiscoveryManager.cs:line 200
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel.ParallelDiscoveryEventsHandler.HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable`1 lastChunk) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelDiscoveryEventsHandler.cs:line 75
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs:line 189
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel.ParallelProxyDiscoveryManager.<>c__DisplayClass27_0.<DiscoverTestsOnConcurrentManager>b__0() in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyDiscoveryManager.cs:line 313
   at System.Threading.Tasks.Task.Execute()<---

@PureWeen
Copy link
Member

PureWeen commented Dec 1, 2023

@jeremy-visionaid you can't run the device tests through Test Explorer :-(

You have to use the Visual Runner. So, set the Device Tests as your startup project and just launch it like you would any maui app.

https://github.com/dotnet/maui/wiki/DeviceTests#running-device-tests-from-the-ide-by-launching-the-projectdevicetests-app

@jeremy-visionaid
Copy link
Contributor

@PureWeen That's great thanks, definitely the article I was missing. However, even now knowing the article title, I wasn't able to find it from the other salient pages - or google. Maybe a hyperlink here or there might make that one a bit easier to find?

https://github.com/dotnet/maui/blob/main/.github/DEVELOPMENT.md
https://github.com/dotnet/maui/wiki/Testing

Excluding them from Test Explorer discovery if somehow possible would also be good (since the unit tets work from there, but the device tests don't). Still, in hindsight, I probably should have figured it out on my own 😅

I've updated the commit with a device test that would otherwise crash without the guard.

@jfversluis

This comment was marked as off-topic.

This comment was marked as off-topic.

@molesmoke
Copy link
Contributor Author

@dotnet-policy-service agree

@PureWeen
Copy link
Member

PureWeen commented Dec 6, 2023

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@@ -329,7 +329,7 @@ void UpdateFlyoutPaneSize()
if (PaneContentGrid == null)
return;

var newSize = new Size(OpenPaneLength, PaneContentGrid.ActualHeight - PaneContentGrid.RowDefinitions[1].Height.Value);
var newSize = new Size(OpenPaneLength, Math.Max(PaneContentGrid.ActualHeight - PaneContentGrid.RowDefinitions[1].Height.Value, 0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to let this continue if we know the layout hasn't occurred yet?

would something like this work?

This code is going to have to run a second time with correct values once the flyout is opened so it seems like we shouldn't really set anything quite yet.

			var newHeight = PaneContentGrid.ActualHeight - PaneContentGrid.RowDefinitions[1].Height.Value;
			if (newHeight < 0)
				return;

			var newSize = new Size(OpenPaneLength, newHeight);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was debating whether to go with the early return or the more minimal change. I prefer the early return myself, since I think it's technically better, but ironically thought the more minimal change was likely to be accepted. At the end of the day I just want my app not to crash, so I'm happy to change it.

PaneContentGrid width/height will be zero if the flyout has not yet been shown
@jfversluis
Copy link
Member

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis jfversluis merged commit 91a99f7 into dotnet:main Dec 7, 2023
47 checks passed
@jfversluis
Copy link
Member

Thank you so much for your contribution! ✨

@github-actions github-actions bot locked and limited conversation to collaborators Jan 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/layout 🔲 StackLayout, GridLayout, ScrollView, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter community ✨ Community Contribution platform/windows 🪟
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting Shell.FlyoutWidth in code-behind on Windows throws ArgumentOutOfRangeException
6 participants