Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,10 @@ protected virtual void UpdateToolbarItems(AToolbar toolbar, Page page)
{
var menu = toolbar.Menu;
SearchHandler = Shell.GetSearchHandler(page);
if (SearchHandler != null && SearchHandler.SearchBoxVisibility != SearchBoxVisibility.Hidden)
if (SearchHandler is not null && SearchHandler.SearchBoxVisibility != SearchBoxVisibility.Hidden)
{
var context = ShellContext.AndroidContext;
if (_searchView == null)
if (_searchView is null)
{
_searchView = GetSearchView(context);
_searchView.SearchHandler = SearchHandler;
Expand All @@ -673,21 +673,31 @@ protected virtual void UpdateToolbarItems(AToolbar toolbar, Page page)
icon.SetColorFilter(TintColor.ToPlatform(Colors.White), FilterMode.SrcAtop);
item.SetShowAsAction(ShowAsAction.IfRoom | ShowAsAction.CollapseActionView);

if (_searchView.View.Parent != null)
if (_searchView.View.Parent is not null)
{
_searchView.View.RemoveFromParent();
}

item.SetActionView(_searchView.View);
item.Dispose();
}
else if (SearchHandler.SearchBoxVisibility == SearchBoxVisibility.Expanded)
{
// Remove the placeholder menu item, if it exists, added for collapsible mode.
if (menu.FindItem(_placeholderMenuItemId) is not null)
{
menu.RemoveItem(_placeholderMenuItemId);
}

if (_searchView.View.Parent != _platformToolbar)
{
_platformToolbar.AddView(_searchView.View);
}
}
}
else
{
if (_searchView != null)
if (_searchView is not null)
{
_searchView.View.RemoveFromParent();
_searchView.View.ViewAttachedToWindow -= OnSearchViewAttachedToWindow;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue33772.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 33772, "Shell SearchHandler SearchBoxVisibility does not update when changed dynamically", PlatformAffected.Android)]
public class Issue33772 : Shell
{
readonly SearchHandler _searchHandler;
readonly Label _statusLabel;

public Issue33772()
{
_searchHandler = new SearchHandler
{
Placeholder = "Search here...",
AutomationId = "SearchHandler",
SearchBoxVisibility = SearchBoxVisibility.Collapsible
};

_statusLabel = new Label
{
Text = "Current: Collapsible",
FontSize = 18,
HorizontalOptions = LayoutOptions.Center,
AutomationId = "StatusLabel"
};

var expandButton = new Button
{
Text = "Change to Expanded",
AutomationId = "ExpandButton",
HorizontalOptions = LayoutOptions.Center
};

expandButton.Clicked += OnExpandedClicked;

var collapsibleButton = new Button
{
Text = "Change to Collapsible",
AutomationId = "CollapsibleButton",
HorizontalOptions = LayoutOptions.Center
};

collapsibleButton.Clicked += OnCollapsibleClicked;

var contentPage = new ContentPage
{
Title = "SearchHandler Visibility Test",
Content = new VerticalStackLayout
{
Padding = 10,
Spacing = 25,
Children =
{
new Label
{
Text = "SearchHandler SearchBoxVisibility Test",
FontSize = 18,
HorizontalOptions = LayoutOptions.Center,
AutomationId = "TitleLabel"
},
expandButton,
collapsibleButton,
_statusLabel
}
}
};

SetSearchHandler(contentPage, _searchHandler);

Items.Add(new ShellContent { Content = contentPage });
}

void OnExpandedClicked(object sender, EventArgs e)
{
_searchHandler.SearchBoxVisibility = SearchBoxVisibility.Expanded;
_statusLabel.Text = "Current: Expanded";
}

void OnCollapsibleClicked(object sender, EventArgs e)
{
_searchHandler.SearchBoxVisibility = SearchBoxVisibility.Collapsible;
_statusLabel.Text = "Current: Collapsible";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue33772 : _IssuesUITest
{
public Issue33772(TestDevice testDevice) : base(testDevice) { }

public override string Issue => "Shell SearchHandler SearchBoxVisibility does not update when changed dynamically";

[Test, Order(1)]
[Category(UITestCategories.Shell)]
public void SearchHandlerVisibilityChangesToExpanded()
{
App.WaitForElement("TitleLabel");
App.Tap("ExpandButton");
VerifyScreenshot();
}

[Test, Order(2)]
[Category(UITestCategories.Shell)]
public void SearchHandlerVisibilityChangesToCollapsible()
{
// Wait for the page to load
App.WaitForElement("TitleLabel");
App.Tap("CollapsibleButton");
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading