dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

MAUI Android Flyout Menu: Opening the Flyout Menu programmatically does not work correctly. #13233

Open lauchacarro opened 1 year ago

lauchacarro commented 1 year ago

Description

When I want to open the Flyout menu programmatically by clicking on a button. It does not work.

You have to manually open the menu for the first time and then it just works programmatically.

Steps to Reproduce

  1. Clone https://github.com/lauchacarro/Maui-FlyoutMenu-Programmatically

  2. Run Androd Project

  3. First click twice on button 1 and you will see that nothing happens.

  4. Now click once on button 2 and you will see the flyout menu open.

If you see the code in MainPage.xaml.cs, you will know why one button works and another does not.

Practically, there must be a UI interaction before using FlyoutIsPresented.

Link to public reproduction project repository

https://github.com/lauchacarro/Maui-FlyoutMenu-Programmatically

Version with bug

7.0 (current)

Last version that worked well

7.0 (current)

Affected platforms

Android

Affected platform versions

Android 21

Did you find any workaround?

Add an invisible label in MainPage.xaml

Then, in the button click event, edit the label text before using the FlyoutIsPresented property.

Relevant log output

No response

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

C0D3On3 commented 1 year ago

@lauchacarro thank you for the workaround! I too have this issue and your workaround did the trick. Hopefully this gets fixed in an expedited manner.

cat0363 commented 1 year ago

Hi, @lauchacarro It may be the same issue as Issue #8226. If it is the same case, you can avoid it with the following code. I was also in trouble with the same Issue.

Shell.Current.FlyoutBehavior = FlyoutBehavior.Locked;
Shell.Current.FlyoutBehavior = FlyoutBehavior.Flyout;
Shell.Current.FlyoutIsPresented = true;
XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.7.0 Preview 2.0. This issue does not repro on Windows 11 and iOS 16.4, repro on Android 13.0-API33 with below Project: 13233.zip

LeoKhariton commented 9 months ago

My small and shorter modification of the workaround in #8226

bool alreadyOpen = false;
#if ANDROID
        if (!alreadyOpen)
        {
            Shell.Current.FlyoutBehavior = FlyoutBehavior.Flyout;
            alreadyOpen = true;
            Shell.Current.FlyoutBehavior = FlyoutBehavior.Disabled;
        }
#endif

        Shell.Current.FlyoutIsPresented = !Shell.Current.FlyoutIsPresented;