maui-samples icon indicating copy to clipboard operation
maui-samples copied to clipboard

FlyoutPageSample OnSelectionChanged Bug

Open DeepWorksStudios opened this issue 3 years ago • 9 comments

Description

If you selected a flyout it breaks with the error

System.InvalidOperationException: 'Can't change IsPresented when setting Default'

Exception Details as log

image

Steps to Reproduce

  1. Pull current maui smaple

  2. Start Project FlyoutPageSample

  3. Target on Windows

  4. Start Application

  5. Select any Flyout Item

Version with bug

6.0.400 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

All Windows Versions

Did you find any workaround?

No

Relevant log output

exceptionBreak.txt

DeepWorksStudios avatar Jun 24 '22 14:06 DeepWorksStudios

for now I just comment out the line in order to run the app, but it's not clear to me what impact it has.

linkaiyu avatar Jun 28 '22 20:06 linkaiyu

Looks like functionality is correct as far as exception is concerned, https://github.com/dotnet/maui/blob/7efa74c205e40c9e849294eb47e6566139f80404/src/Controls/src/Core/FlyoutPage.cs#L269

Should update the demo to not have that option based on the scenario.

However, honestly we should not recommend flyoutpage and Shell should be used in all cases.

jamesmontemagno avatar Jun 28 '22 21:06 jamesmontemagno

Thanks James for the guidance. I've played with the shellflyout sample and it does make more sense.

linkaiyu avatar Jun 29 '22 00:06 linkaiyu

Looks like the documentation might also be incorrect, unless the current behaviour is a bug: https://docs.microsoft.com/en-us/dotnet/maui/user-interface/pages/flyoutpage

molesmoke avatar Jun 29 '22 05:06 molesmoke

I'm honest, it's really confusing since this is an official template with no changes and if I understood correctly, it shouldn't be used? Then the question is why even provide such a template in this case

DeepWorksStudios avatar Jun 29 '22 06:06 DeepWorksStudios

I wish I'd noticed this thread earlier. I dug into this a bit more and commented in the related #229. The problem is that IsPresented = false appears incompatible with a split layout (FlyoutLayoutBehavior.Split and SplitXXX).

On the Windows platform, where FlyoutLayoutBehavior.Default is implemented as FlyoutLayoutBehavior.Split, the exception occurs.

On the Android platform, where FlyoutLayoutBehavior.Default is implemented as FlyoutLayoutBehavior.Popover, everything seems to work fine.

My workaround was to simply add FlyoutLayoutBheavior = "Popover" to the FlyoutPage in AppFlyout.xaml. Then, things appear to work correctly on both platforms.

CodeSetting avatar Aug 21 '22 17:08 CodeSetting

I'm still learning MAUI, but I think I finally understand the full dimension of this problem.

The line IsPresented = false is primarily intended to dismiss a popover dialog. When using a split layout, instead of a popover layout, dismissing it does not make sense (and is not supported)...so it throws an InvalidOperationException.

The correct way to fix this is probably to change the following line in AppFlyout.xaml.cs:

IsPresented = false;

To only dismiss popover layouts, as follows:

if (!((IFlyoutPageController)this).ShouldShowSplitMode)
  IsPresented = false;

CodeSetting avatar Aug 21 '22 21:08 CodeSetting

The problem still exists today, and worse, the latest expansion makes it unbuildable unless removed the code of the FlyoutPage Sample.csproj

<ItemGroup>
		<KnownRuntimePack Update="@(KnownRuntimePack)">
			<LatestRuntimeFrameworkVersion Condition="'%(TargetFramework)' == 'net7.0'">6.0.4</LatestRuntimeFrameworkVersion>
		</KnownRuntimePack>
		<KnownFrameworkReference Update="@(KnownFrameworkReference)">
			<TargetingPackVersion Condition="'%(TargetFramework)' == 'net7.0'">6.0.4</TargetingPackVersion>
			<LatestRuntimeFrameworkVersion Condition="'%(TargetFramework)' == 'net7.0'">6.0.4</LatestRuntimeFrameworkVersion>
		</KnownFrameworkReference>
	</ItemGroup>

DeepWorksStudios avatar May 18 '23 22:05 DeepWorksStudios

Any updates?

DeepWorksStudios avatar Jan 05 '24 08:01 DeepWorksStudios