Skip to content

Commit cf8df27

Browse files
BagavathiPerumalPureWeen
authored andcommitted
[Android] Fix for Search Handler visual and functional bug in subtabs (#30467)
* fix-21119-Made changes to ShellToolbarTracker.cs to prevent search handler stacking on Android Shell tab navigation by removing existing menu items before adding new ones. * fix-21119-Testcase and test snapshot added. * fix-21119-Updated code changes. Also added Mac and Windows snapshots.
1 parent 9e96d85 commit cf8df27

File tree

7 files changed

+146
-2
lines changed

7 files changed

+146
-2
lines changed

src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarTracker.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace Microsoft.Maui.Controls.Platform.Compatibility
3535
{
3636
public class ShellToolbarTracker : Java.Lang.Object, AView.IOnClickListener, IShellToolbarTracker, IFlyoutBehaviorObserver
3737
{
38+
const int _placeholderMenuItemId = 100;
3839
#region IFlyoutBehaviorObserver
3940

4041
void IFlyoutBehaviorObserver.OnFlyoutBehaviorChanged(FlyoutBehavior behavior)
@@ -632,7 +633,6 @@ protected virtual void UpdateTitleView(Context context, AToolbar toolbar, View t
632633
private void UpdateToolbarItemsTintColors(AToolbar toolbar)
633634
{
634635
var menu = toolbar.Menu;
635-
int _placeholderMenuItemId = 100;
636636
if (menu.FindItem(_placeholderMenuItemId) is IMenuItem item)
637637
{
638638
using (var icon = item.Icon)
@@ -643,7 +643,6 @@ private void UpdateToolbarItemsTintColors(AToolbar toolbar)
643643
protected virtual void UpdateToolbarItems(AToolbar toolbar, Page page)
644644
{
645645
var menu = toolbar.Menu;
646-
int _placeholderMenuItemId = 100;
647646
SearchHandler = Shell.GetSearchHandler(page);
648647
if (SearchHandler != null && SearchHandler.SearchBoxVisibility != SearchBoxVisibility.Hidden)
649648
{
@@ -662,6 +661,8 @@ protected virtual void UpdateToolbarItems(AToolbar toolbar, Page page)
662661

663662
if (SearchHandler.SearchBoxVisibility == SearchBoxVisibility.Collapsible)
664663
{
664+
menu.RemoveItem(_placeholderMenuItemId);
665+
665666
var placeholder = new Java.Lang.String(SearchHandler.Placeholder);
666667
var item = menu.Add(0, _placeholderMenuItemId, 0, placeholder);
667668
placeholder.Dispose();
35 KB
Loading
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 21119, "Search Handler visual and functional bug in subtabs", PlatformAffected.Android)]
4+
public class Issue21119 : Shell
5+
{
6+
public Issue21119()
7+
{
8+
FlyoutBehavior = FlyoutBehavior.Flyout;
9+
10+
var flyoutItem = new FlyoutItem
11+
{
12+
Route = "animals",
13+
FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems
14+
};
15+
16+
var domesticTab = new Tab
17+
{
18+
Title = "Domestic",
19+
Route = "domestic"
20+
};
21+
22+
domesticTab.Items.Add(new ShellContent
23+
{
24+
Title = "CatsPage",
25+
Route = "cats",
26+
ContentTemplate = new DataTemplate(typeof(_21119CatsPage))
27+
});
28+
29+
domesticTab.Items.Add(new ShellContent
30+
{
31+
Title = "DogsPage",
32+
Route = "dogs",
33+
ContentTemplate = new DataTemplate(typeof(_21119DogsPage))
34+
});
35+
36+
flyoutItem.Items.Add(domesticTab);
37+
38+
Items.Add(flyoutItem);
39+
}
40+
41+
public class _21119CatsPage : ContentPage
42+
{
43+
public _21119CatsPage()
44+
{
45+
Title = "CatsPage";
46+
47+
var searchHandler = new _21119AnimalSearchHandler
48+
{
49+
Placeholder = "Search cats...",
50+
ShowsResults = true
51+
};
52+
53+
var catPageButton = new Button
54+
{
55+
Text = "CatPageButton",
56+
AutomationId = "CatPageButton"
57+
};
58+
59+
Content = new StackLayout
60+
{
61+
Children =
62+
{
63+
catPageButton
64+
}
65+
};
66+
67+
Shell.SetSearchHandler(this, searchHandler);
68+
}
69+
}
70+
71+
public class _21119DogsPage : ContentPage
72+
{
73+
public _21119DogsPage()
74+
{
75+
Title = "DogsPage";
76+
77+
var searchHandler = new _21119AnimalSearchHandler
78+
{
79+
Placeholder = "Search dogs...",
80+
ShowsResults = true
81+
};
82+
83+
Shell.SetSearchHandler(this, searchHandler);
84+
85+
var dogPageButton = new Button
86+
{
87+
Text = "DogPageButton",
88+
AutomationId = "DogsPageButton"
89+
};
90+
91+
Content = new StackLayout
92+
{
93+
Children =
94+
{
95+
dogPageButton
96+
}
97+
};
98+
}
99+
}
100+
101+
public class _21119AnimalSearchHandler : SearchHandler
102+
{
103+
public _21119AnimalSearchHandler()
104+
{
105+
SearchBoxVisibility = SearchBoxVisibility.Collapsible;
106+
}
107+
}
108+
}
13.5 KB
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
public class Issue21119 : _IssuesUITest
8+
{
9+
public Issue21119(TestDevice testDevice) : base(testDevice)
10+
{
11+
}
12+
13+
public override string Issue => "Search Handler visual and functional bug in subtabs";
14+
15+
[Test]
16+
[Category(UITestCategories.Shell)]
17+
public void UpdateSearchHandlerMenuItemForTabNavigation()
18+
{
19+
#if WINDOWS
20+
App.Tap("navViewItem");
21+
App.WaitForElement("DogsPage");
22+
App.Tap("DogsPage");
23+
App.Tap("navViewItem");
24+
App.WaitForElement("CatsPage");
25+
App.Tap("CatsPage");
26+
#else
27+
App.WaitForElement("CatPageButton");
28+
App.TapTab("DogsPage");
29+
App.WaitForElement("DogPageButton");
30+
App.TapTab("CatsPage");
31+
#endif
32+
VerifyScreenshot();
33+
}
34+
}
35+
}
11 KB
Loading
40.2 KB
Loading

0 commit comments

Comments
 (0)