diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/SearchHandlerAppearanceTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/SearchHandlerAppearanceTracker.cs index 8bc9f38e1e4e..6b21640b0ca2 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/SearchHandlerAppearanceTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/SearchHandlerAppearanceTracker.cs @@ -32,6 +32,7 @@ public SearchHandlerAppearanceTracker(IShellSearchView searchView, IShellContext _control = searchView.View; _searchHandler.PropertyChanged += SearchHandlerPropertyChanged; _editText = (_control as ViewGroup).GetChildrenOfType().FirstOrDefault(); + _editText.FocusChange += EditTextFocusChange; UpdateSearchBarColors(); UpdateFont(); UpdateHorizontalTextAlignment(); @@ -83,6 +84,11 @@ protected virtual void SearchHandlerPropertyChanged(object sender, System.Compon } } + void EditTextFocusChange(object s, AView.FocusChangeEventArgs args) + { + _searchHandler.SetIsFocused(_editText.IsFocused); + } + void UpdateSearchBarColors() { UpdateBackgroundColor(); @@ -221,6 +227,7 @@ protected virtual void Dispose(bool disposing) if (_searchHandler != null) { _searchHandler.PropertyChanged -= SearchHandlerPropertyChanged; + _editText.FocusChange -= EditTextFocusChange; } _searchHandler = null; _control = null; diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24670.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue24670.cs new file mode 100644 index 000000000000..83c66d175040 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24670.cs @@ -0,0 +1,27 @@ +namespace Maui.Controls.Sample.Issues +{ + [XamlCompilation(XamlCompilationOptions.Compile)] + [Issue(IssueTracker.ManualTest, "24670", "SearchHandler.Focused event never fires", PlatformAffected.All)] + public partial class Issue24670 : Shell + { + public Issue24670() + { + InitializeComponent(); + } + + private void SearchHandler_Focused(object sender, EventArgs e) + { + focusedLabel.Text = "Focused: True"; + } + + private void SearchHandler_Unfocused(object sender, EventArgs e) + { + unfocusedLabel.Text = "Unfocused: True"; + } + + private void Button_Clicked(object sender, EventArgs e) + { + searchHandler.SetIsFocused(!searchHandler.IsFocused); + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24670.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue24670.xaml new file mode 100644 index 000000000000..338f531f0048 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24670.xaml @@ -0,0 +1,30 @@ + + + + + + + + + +