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 db8981fe9f27..36407b32aab1 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/SearchHandlerAppearanceTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/SearchHandlerAppearanceTracker.cs @@ -31,6 +31,8 @@ public SearchHandlerAppearanceTracker(IShellSearchView searchView, IShellContext _searchHandler = searchView.SearchHandler; _control = searchView.View; _searchHandler.PropertyChanged += SearchHandlerPropertyChanged; + _searchHandler.ShowKeyboardRequested += OnShowKeyboardRequested; + _searchHandler.HideKeyboardRequested += OnHideKeyboardRequested; _editText = (_control as ViewGroup).GetChildrenOfType().FirstOrDefault(); _editText.FocusChange += EditTextFocusChange; UpdateSearchBarColors(); @@ -211,6 +213,17 @@ void UpdateImageButtonIconColor(string tagName, Color toColor) } } + void OnShowKeyboardRequested(object sender, EventArgs e) + { + _editText?.RequestFocus(); + _control?.ShowSoftInput(); + } + + void OnHideKeyboardRequested(object sender, EventArgs e) + { + _control?.HideSoftInput(); + } + void UpdateInputType() { var keyboard = _searchHandler.Keyboard; @@ -259,6 +272,8 @@ protected virtual void Dispose(bool disposing) { _searchHandler.PropertyChanged -= SearchHandlerPropertyChanged; _editText.FocusChange -= EditTextFocusChange; + _searchHandler.ShowKeyboardRequested -= OnShowKeyboardRequested; + _searchHandler.HideKeyboardRequested -= OnHideKeyboardRequested; } _searchHandler = null; _control = null; diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs index 7d8e11076e63..2472635454c0 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs @@ -33,6 +33,8 @@ public SearchHandlerAppearanceTracker(UISearchBar searchBar, SearchHandler searc _fontManager = fontManager; _searchHandler = searchHandler; _searchHandler.PropertyChanged += SearchHandlerPropertyChanged; + _searchHandler.ShowKeyboardRequested += OnShowKeyboardRequested; + _searchHandler.HideKeyboardRequested += OnHideKeyboardRequested; _searchHandler.FocusChangeRequested += SearchHandlerFocusChangeRequested; _uiSearchBar = searchBar; _uiSearchBar.OnEditingStarted += OnEditingStarted; @@ -351,6 +353,17 @@ void OnSearchButtonClicked(object sender, EventArgs e) _uiSearchBar.ResignFirstResponder(); } + void OnShowKeyboardRequested(object sender, EventArgs e) + { + _uiSearchBar?.BecomeFirstResponder(); + } + + void OnHideKeyboardRequested(object sender, EventArgs e) + { + _uiSearchBar?.ResignFirstResponder(); + } + + UIToolbar CreateNumericKeyboardAccessoryView() { var keyboardWidth = UIScreen.MainScreen.Bounds.Width; @@ -408,6 +421,8 @@ protected virtual void Dispose(bool disposing) { _searchHandler.FocusChangeRequested -= SearchHandlerFocusChangeRequested; _searchHandler.PropertyChanged -= SearchHandlerPropertyChanged; + _searchHandler.ShowKeyboardRequested -= OnShowKeyboardRequested; + _searchHandler.HideKeyboardRequested -= OnHideKeyboardRequested; } _searchHandler = null; _uiSearchBar = null; diff --git a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt index dd12942a990f..fe1fff70f090 100644 --- a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt @@ -314,3 +314,5 @@ override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesSupport override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext? context) -> bool override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) -> System.ComponentModel.TypeConverter.StandardValuesCollection! Microsoft.Maui.Controls.IExtendedTypeConverter.ConvertFromInvariantString(string! value, System.IServiceProvider! serviceProvider) -> object? +Microsoft.Maui.Controls.SearchHandler.HideKeyboard() -> void +Microsoft.Maui.Controls.SearchHandler.ShowKeyboard() -> void diff --git a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 55385f69182f..07685bf3bfab 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -515,3 +515,5 @@ override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesSupport override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext? context) -> bool override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) -> System.ComponentModel.TypeConverter.StandardValuesCollection! Microsoft.Maui.Controls.IExtendedTypeConverter.ConvertFromInvariantString(string! value, System.IServiceProvider! serviceProvider) -> object? +Microsoft.Maui.Controls.SearchHandler.HideKeyboard() -> void +Microsoft.Maui.Controls.SearchHandler.ShowKeyboard() -> void \ No newline at end of file diff --git a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 051307bb2827..1d5068d2bba4 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -515,3 +515,5 @@ override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesSupport override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext? context) -> bool override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) -> System.ComponentModel.TypeConverter.StandardValuesCollection! Microsoft.Maui.Controls.IExtendedTypeConverter.ConvertFromInvariantString(string! value, System.IServiceProvider! serviceProvider) -> object? +Microsoft.Maui.Controls.SearchHandler.HideKeyboard() -> void +Microsoft.Maui.Controls.SearchHandler.ShowKeyboard() -> void \ No newline at end of file diff --git a/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt index 014df1989f1e..5cb5be8ecafd 100644 --- a/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt @@ -307,3 +307,5 @@ override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesSupport override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext? context) -> bool override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) -> System.ComponentModel.TypeConverter.StandardValuesCollection! Microsoft.Maui.Controls.IExtendedTypeConverter.ConvertFromInvariantString(string! value, System.IServiceProvider! serviceProvider) -> object? +Microsoft.Maui.Controls.SearchHandler.HideKeyboard() -> void +Microsoft.Maui.Controls.SearchHandler.ShowKeyboard() -> void \ No newline at end of file diff --git a/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt index b0f06cdbc222..26b94a70c977 100644 --- a/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt @@ -315,3 +315,5 @@ override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesSupport override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext? context) -> bool override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) -> System.ComponentModel.TypeConverter.StandardValuesCollection! Microsoft.Maui.Controls.IExtendedTypeConverter.ConvertFromInvariantString(string! value, System.IServiceProvider! serviceProvider) -> object? +Microsoft.Maui.Controls.SearchHandler.HideKeyboard() -> void +Microsoft.Maui.Controls.SearchHandler.ShowKeyboard() -> void \ No newline at end of file diff --git a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt index 961edef3dcc7..8545e22c98b1 100644 --- a/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt @@ -306,3 +306,5 @@ override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesSupport override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext? context) -> bool override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) -> System.ComponentModel.TypeConverter.StandardValuesCollection! Microsoft.Maui.Controls.IExtendedTypeConverter.ConvertFromInvariantString(string! value, System.IServiceProvider! serviceProvider) -> object? +Microsoft.Maui.Controls.SearchHandler.HideKeyboard() -> void +Microsoft.Maui.Controls.SearchHandler.ShowKeyboard() -> void diff --git a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt index 410f18fd3ace..831931be5cdd 100644 --- a/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt @@ -305,3 +305,5 @@ override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesSupport override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext? context) -> bool override Microsoft.Maui.Controls.LayoutOptionsConverter.GetStandardValues(System.ComponentModel.ITypeDescriptorContext? context) -> System.ComponentModel.TypeConverter.StandardValuesCollection! Microsoft.Maui.Controls.IExtendedTypeConverter.ConvertFromInvariantString(string! value, System.IServiceProvider! serviceProvider) -> object? +Microsoft.Maui.Controls.SearchHandler.HideKeyboard() -> void +Microsoft.Maui.Controls.SearchHandler.ShowKeyboard() -> void \ No newline at end of file diff --git a/src/Controls/src/Core/Shell/SearchHandler.cs b/src/Controls/src/Core/Shell/SearchHandler.cs index 8c6c20f5baaa..4376a83f6f30 100644 --- a/src/Controls/src/Core/Shell/SearchHandler.cs +++ b/src/Controls/src/Core/Shell/SearchHandler.cs @@ -20,6 +20,9 @@ public class SearchHandler : BindableObject, ISearchHandlerController, IPlacehol public event EventHandler Focused; public event EventHandler Unfocused; + + internal event EventHandler ShowKeyboardRequested; + internal event EventHandler HideKeyboardRequested; /// Bindable property for . public static readonly BindableProperty IsFocusedProperty = IsFocusedPropertyKey.BindableProperty; @@ -84,6 +87,16 @@ public void Unfocus() FocusChangeRequested?.Invoke(this, new FocusRequestArgs()); } + public void ShowKeyboard() + { + ShowKeyboardRequested?.Invoke(this, new EventArgs()); + } + + public void HideKeyboard() + { + HideKeyboardRequested?.Invoke(this, new EventArgs()); + } + protected virtual void OnFocused() { diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue29559.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue29559.xaml new file mode 100644 index 000000000000..6c24c99edb5d --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue29559.xaml @@ -0,0 +1,26 @@ + + + + + + + + +