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.04k stars 1.73k forks source link

Search Handler visual and functional bug in subtabs #21119

Open sandeshkarki55 opened 6 months ago

sandeshkarki55 commented 6 months ago

Description

Issue #7184 is back on the latest MAUI version(8.0.7).

Steps to Reproduce

  1. Clone https://github.com/sandeshkarki55/SearchHandlerAndroidBug/tree/development
  2. Run on Android

Link to public reproduction project repository

No response

Version with bug

8.0.3 GA

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

No response

QianaJiao commented 6 months ago

Verified this issue with Visual Studio 17.10.0 Preview 1. Can repro on Android platform. Animation

sandeshkarki55 commented 5 months ago

Workaround:

Create custom ShellRenderer:

class CustomShellHandler : ShellRenderer
{
#if ANDROID
    protected override IShellToolbarTracker CreateTrackerForToolbar(AToolbar toolbar)
    {
        return new CustomShellToolbarTracker(this, toolbar, ((IShellContext)this).CurrentDrawerLayout);
    }
#endif
}

Create CustomShellToolbarTracker class and override UpdateToolbarItems with the following code. This removes any duplicate search handler menu item.

#if ANDROID
class CustomShellToolbarTracker(IShellContext shellContext, AToolbar toolbar, DrawerLayout drawerLayout) : ShellToolbarTracker(shellContext, toolbar, drawerLayout)
{
    protected override void UpdateToolbarItems(AToolbar toolbar, Page page)
    {
        // hacky way to remove the duplicate search icon in the toolbar
        var menu = toolbar.Menu;

        var menuSize = menu.Size();

       for (var i = 0; i < menuSize; i++)
       {
         var menuItem = menu.GetItem(i);

         if (menuItem != null && menuItem.ActionView is ShellSearchView)
         {
             menu.RemoveItem(menuItem.ItemId);
         }
      }

        base.UpdateToolbarItems(toolbar, page);
    }
}
#endif

This should fix it.