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

ShouldShowToolbarButton() override on FlyoutPage not working #15111

Closed
GODston opened this issue May 16, 2023 · 6 comments · Fixed by #18522
Closed

ShouldShowToolbarButton() override on FlyoutPage not working #15111

GODston opened this issue May 16, 2023 · 6 comments · Fixed by #18522
Labels
area-controls-flyoutpage FlyoutPage fixed-in-8.0.10 fixed-in-9.0.0-preview.3.10457 platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@GODston
Copy link

GODston commented May 16, 2023

Description

Im trying to have a custom navigation bar.
I have a FlyoutPage that sets a custom Detail (a NavigationPage that contains a TabbedPage). In the tabbed page constructor i load a custom view to my navigationPage title view, wich works correctly, but since im using a FlyoutPage the burger 'Open Flyout' button is still present.
After looking around i found that i could override the ShouldShowToolbarButton() in my FlyoutPage to make it always return false, thus making it not show the button, but this does not work. Im doing my testing on Android.

Steps to Reproduce

1- Create new .net MAUI app.
2- Create new FlyoutPage
3- Load a custom ContentPage as Flyout in the constructor (example 1)
4- Load a custom TabbedPage inside a NavigationPage as Detail (emaple 1)

<--- Example 1 --->
public Flyout()
{
InitializeComponent();

Flyout = new MainPage();
Detail = new NavigationPage( new TabbedP() );
}

5- Load a custom View as TitleView in the TabbedPage
NavigationPage.SetTitleView(this, new NewContent2());
6- Override the ShouldShowToolbarButton method in the FlyoutPage so it always returns false.

public override bool ShouldShowToolbarButton()
{
    return false;
}

Link to public reproduction project repository

https://github.com/GODston/Public

Version with bug

8.0 previews

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android 13 API 33

Did you find any workaround?

No response

Relevant log output

No response

@GODston GODston added the t/bug Something isn't working label May 16, 2023
@GODston
Copy link
Author

GODston commented May 16, 2023

If there is a known workaround to remove the burger button, i would like to know.
Thanks!

@Eilon Eilon added the area-controls-flyoutpage FlyoutPage label May 16, 2023
@thomaskaelin
Copy link

thomaskaelin commented Jun 30, 2023

While migrating an existing app from Xamarin.Forms to MAUI, I came across this bug as well. I was able to test on Android and iOS:

  • Android: not working. The method ShouldShowToolbarButton is never called. Tested on Android 11, 12 and 13.
  • iOS: working. Tested on iOS 16.4.

No workaround known to me.

@bradencohen
Copy link
Contributor

bradencohen commented Aug 2, 2023

Found a pretty ugly workaround to hide the icon in the handler (for Android):

public class ToolbarHandler : Microsoft.Maui.Handlers.ToolbarHandler
{
    protected override void ConnectHandler( MaterialToolbar platformView )
    {
        ( VirtualView as Toolbar ).PropertyChanged += ToolbarHandler_PropertyChanged;
        base.ConnectHandler( platformView );
    }

    protected override void DisconnectHandler( MaterialToolbar platformView )
    {
        ( VirtualView as Toolbar ).PropertyChanged -= ToolbarHandler_PropertyChanged;
        base.DisconnectHandler( platformView );
    }

    private void ToolbarHandler_PropertyChanged( object sender, System.ComponentModel.PropertyChangedEventArgs e )
    {
        if( sender is not Toolbar toolbar || !toolbar.DrawerToggleVisible )
        {
            return;
        }

        // This property doesn't invoke a property changed.
        // Somewhere in the source, this is being set to 'true'
        // and doesn't reference ShouldShowToolbarButton().
        // There might be somewhere better to call this but this gets the job done.
        toolbar.DrawerToggleVisible = false;
    }
}

I couldn't find anywhere better to call this, and this seems to catch it in my use case. It isn't the best solution because you're assuming that there is a property change after DrawerToggleVisible has been updated that will trigger the event.... But that's why its a workaround :P. Don't forget to register the handler in your app builder.

@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Sep 18, 2023
@XamlTest
Copy link

Verified this on Visual Studio Enterprise 17.8.0 Preview 2.0. Repro on Android 13.0-API33(8.0.0-rc.1), not repro on iOS 16.4 with below Project:
ExampleFlyoutBurgerButton.zip

image

@schinkenwuerfel
Copy link

@samhouts I just tested if this is fixed in version 8.0.14 but it seems the issue still is there.
Im overriding the method my FlyoutPage with public override bool ShouldShowToolbarButton() => false; but i still have the burger menu button in the titlebar.
image

@bradencohen
Copy link
Contributor

Seems to be working on main @schinkenwuerfel :

class App : Application
{
	protected override Window CreateWindow(IActivationState? activationState)
	{
		// To test shell scenarios, change this to true
		bool useShell = false;

		if (!useShell)
		{
			var flyout = new Flyout();
			flyout.Flyout = new ContentPage { Title = "Flyout" };
			flyout.Detail = new NavigationPage(new MainPage());

			return new Window(flyout);
		}
		else
		{
			return new Window(new SandboxShell());
		}
	}

	class Flyout : FlyoutPage 
	{
		public override bool ShouldShowToolbarButton()
		{
			return false;	
		}
	}
}

image

I have a hunch that the fix made only fixes when the root page is a NavigationPage.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-flyoutpage FlyoutPage fixed-in-8.0.10 fixed-in-9.0.0-preview.3.10457 platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

7 participants