diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarTracker.cs index 9e09e669d717..21dd7ec31d72 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarTracker.cs @@ -35,6 +35,7 @@ namespace Microsoft.Maui.Controls.Platform.Compatibility { public class ShellToolbarTracker : Java.Lang.Object, AView.IOnClickListener, IShellToolbarTracker, IFlyoutBehaviorObserver { + const int _placeholderMenuItemId = 100; #region IFlyoutBehaviorObserver void IFlyoutBehaviorObserver.OnFlyoutBehaviorChanged(FlyoutBehavior behavior) @@ -632,7 +633,6 @@ protected virtual void UpdateTitleView(Context context, AToolbar toolbar, View t private void UpdateToolbarItemsTintColors(AToolbar toolbar) { var menu = toolbar.Menu; - int _placeholderMenuItemId = 100; if (menu.FindItem(_placeholderMenuItemId) is IMenuItem item) { using (var icon = item.Icon) @@ -643,7 +643,6 @@ private void UpdateToolbarItemsTintColors(AToolbar toolbar) protected virtual void UpdateToolbarItems(AToolbar toolbar, Page page) { var menu = toolbar.Menu; - int _placeholderMenuItemId = 100; SearchHandler = Shell.GetSearchHandler(page); if (SearchHandler != null && SearchHandler.SearchBoxVisibility != SearchBoxVisibility.Hidden) { @@ -662,6 +661,8 @@ protected virtual void UpdateToolbarItems(AToolbar toolbar, Page page) if (SearchHandler.SearchBoxVisibility == SearchBoxVisibility.Collapsible) { + menu.RemoveItem(_placeholderMenuItemId); + var placeholder = new Java.Lang.String(SearchHandler.Placeholder); var item = menu.Add(0, _placeholderMenuItemId, 0, placeholder); placeholder.Dispose(); diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/UpdateSearchHandlerMenuItemForTabNavigation.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/UpdateSearchHandlerMenuItemForTabNavigation.png new file mode 100644 index 000000000000..fc61f02e538f Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/UpdateSearchHandlerMenuItemForTabNavigation.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue21119.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue21119.cs new file mode 100644 index 000000000000..2ed0170267cf --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue21119.cs @@ -0,0 +1,108 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 21119, "Search Handler visual and functional bug in subtabs", PlatformAffected.Android)] +public class Issue21119 : Shell +{ + public Issue21119() + { + FlyoutBehavior = FlyoutBehavior.Flyout; + + var flyoutItem = new FlyoutItem + { + Route = "animals", + FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems + }; + + var domesticTab = new Tab + { + Title = "Domestic", + Route = "domestic" + }; + + domesticTab.Items.Add(new ShellContent + { + Title = "CatsPage", + Route = "cats", + ContentTemplate = new DataTemplate(typeof(_21119CatsPage)) + }); + + domesticTab.Items.Add(new ShellContent + { + Title = "DogsPage", + Route = "dogs", + ContentTemplate = new DataTemplate(typeof(_21119DogsPage)) + }); + + flyoutItem.Items.Add(domesticTab); + + Items.Add(flyoutItem); + } + + public class _21119CatsPage : ContentPage + { + public _21119CatsPage() + { + Title = "CatsPage"; + + var searchHandler = new _21119AnimalSearchHandler + { + Placeholder = "Search cats...", + ShowsResults = true + }; + + var catPageButton = new Button + { + Text = "CatPageButton", + AutomationId = "CatPageButton" + }; + + Content = new StackLayout + { + Children = + { + catPageButton + } + }; + + Shell.SetSearchHandler(this, searchHandler); + } + } + + public class _21119DogsPage : ContentPage + { + public _21119DogsPage() + { + Title = "DogsPage"; + + var searchHandler = new _21119AnimalSearchHandler + { + Placeholder = "Search dogs...", + ShowsResults = true + }; + + Shell.SetSearchHandler(this, searchHandler); + + var dogPageButton = new Button + { + Text = "DogPageButton", + AutomationId = "DogsPageButton" + }; + + Content = new StackLayout + { + Children = + { + dogPageButton + } + }; + } + } + + public class _21119AnimalSearchHandler : SearchHandler + { + public _21119AnimalSearchHandler() + { + SearchBoxVisibility = SearchBoxVisibility.Collapsible; + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/UpdateSearchHandlerMenuItemForTabNavigation.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/UpdateSearchHandlerMenuItemForTabNavigation.png new file mode 100644 index 000000000000..5ab0a1ba8a42 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/UpdateSearchHandlerMenuItemForTabNavigation.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue21119.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue21119.cs new file mode 100644 index 000000000000..b6eb60e250ad --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue21119.cs @@ -0,0 +1,35 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues +{ + public class Issue21119 : _IssuesUITest + { + public Issue21119(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "Search Handler visual and functional bug in subtabs"; + + [Test] + [Category(UITestCategories.Shell)] + public void UpdateSearchHandlerMenuItemForTabNavigation() + { +#if WINDOWS + App.Tap("navViewItem"); + App.WaitForElement("DogsPage"); + App.Tap("DogsPage"); + App.Tap("navViewItem"); + App.WaitForElement("CatsPage"); + App.Tap("CatsPage"); +#else + App.WaitForElement("CatPageButton"); + App.TapTab("DogsPage"); + App.WaitForElement("DogPageButton"); + App.TapTab("CatsPage"); +#endif + VerifyScreenshot(); + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/UpdateSearchHandlerMenuItemForTabNavigation.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/UpdateSearchHandlerMenuItemForTabNavigation.png new file mode 100644 index 000000000000..3ae615a908c0 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/UpdateSearchHandlerMenuItemForTabNavigation.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/UpdateSearchHandlerMenuItemForTabNavigation.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/UpdateSearchHandlerMenuItemForTabNavigation.png new file mode 100644 index 000000000000..0a0a7ece01cc Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/UpdateSearchHandlerMenuItemForTabNavigation.png differ