Skip to content

Commit

Permalink
Generalize HideSoftInputOnTapped on Android and iOS to support 3rd pa…
Browse files Browse the repository at this point in the history
…rty input controls (#19626)

* Generalize HideSoftInputOnTapped on Android and iOS to support 3rd party input controls.

* - remove predicate on iOS

* - fix

---------

Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
  • Loading branch information
albyrock87 and PureWeen authored Mar 5, 2024
1 parent 8cd9239 commit 11a387b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Android.Widget;
using Microsoft.Maui.Graphics;
using AView = Android.Views.View;
using AViewGroup = Android.Views.ViewGroup;

namespace Microsoft.Maui.Controls
{
Expand Down Expand Up @@ -43,21 +44,12 @@ page.Handler is IPlatformViewHandler pvh &&
// This is called from InputViews as they are added to the visual tree
IDisposable? SetupHideSoftInputOnTapped(AView aView)
{
if (aView is SearchView sv &&
sv.GetFirstChildOfType<EditText>() is EditText editText)
if (aView is AViewGroup vg &&
vg.GetFirstChildOfType<EditText>() is {} editText)
{
aView = editText;
}

if (aView is AndroidX.AppCompat.Widget.SearchView svX &&
svX.GetFirstChildOfType<EditText>() is EditText editTextX)
{
aView = editTextX;
}

if (aView is null)
return null;

if (!FeatureEnabled)
return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@ namespace Microsoft.Maui.Controls
{
partial class HideSoftInputOnTappedChangedManager
{
internal IDisposable? SetupHideSoftInputOnTapped(UIView uIView)
internal IDisposable? SetupHideSoftInputOnTapped(UIView uiView)
{
if (!FeatureEnabled || uIView.Window is null)
if (!FeatureEnabled || uiView.Window is null)
{
return null;
}

UIView? uiText = uiView;

if (uIView is UISearchBar searchBar &&
searchBar.GetSearchTextField() is UIView textField)
if (uiText is not (UITextField or UITextView))
{
uIView = textField;
uiText = uiView.FindDescendantView<UIView>((view) => view is (UITextField or UITextView));
}

if (uIView is null)
if (uiText is null)
{
return null;
}

return ResignFirstResponderTouchGestureRecognizer
.Update(uIView);
.Update(uiText);
}
}
}

0 comments on commit 11a387b

Please sign in to comment.