Skip to content

Commit 11a387b

Browse files
albyrock87PureWeen
andauthored
Generalize HideSoftInputOnTapped on Android and iOS to support 3rd party 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 <[email protected]>
1 parent 8cd9239 commit 11a387b

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.Android.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Android.Widget;
44
using Microsoft.Maui.Graphics;
55
using AView = Android.Views.View;
6+
using AViewGroup = Android.Views.ViewGroup;
67

78
namespace Microsoft.Maui.Controls
89
{
@@ -43,21 +44,12 @@ page.Handler is IPlatformViewHandler pvh &&
4344
// This is called from InputViews as they are added to the visual tree
4445
IDisposable? SetupHideSoftInputOnTapped(AView aView)
4546
{
46-
if (aView is SearchView sv &&
47-
sv.GetFirstChildOfType<EditText>() is EditText editText)
47+
if (aView is AViewGroup vg &&
48+
vg.GetFirstChildOfType<EditText>() is {} editText)
4849
{
4950
aView = editText;
5051
}
5152

52-
if (aView is AndroidX.AppCompat.Widget.SearchView svX &&
53-
svX.GetFirstChildOfType<EditText>() is EditText editTextX)
54-
{
55-
aView = editTextX;
56-
}
57-
58-
if (aView is null)
59-
return null;
60-
6153
if (!FeatureEnabled)
6254
return null;
6355

src/Controls/src/Core/ContentPage/HideSoftInputOnTappedChanged/HideSoftInputOnTappedChangedManager.iOS.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,27 @@ namespace Microsoft.Maui.Controls
77
{
88
partial class HideSoftInputOnTappedChangedManager
99
{
10-
internal IDisposable? SetupHideSoftInputOnTapped(UIView uIView)
10+
internal IDisposable? SetupHideSoftInputOnTapped(UIView uiView)
1111
{
12-
if (!FeatureEnabled || uIView.Window is null)
12+
if (!FeatureEnabled || uiView.Window is null)
13+
{
1314
return null;
15+
}
16+
17+
UIView? uiText = uiView;
1418

15-
if (uIView is UISearchBar searchBar &&
16-
searchBar.GetSearchTextField() is UIView textField)
19+
if (uiText is not (UITextField or UITextView))
1720
{
18-
uIView = textField;
21+
uiText = uiView.FindDescendantView<UIView>((view) => view is (UITextField or UITextView));
1922
}
2023

21-
if (uIView is null)
24+
if (uiText is null)
25+
{
2226
return null;
27+
}
2328

2429
return ResignFirstResponderTouchGestureRecognizer
25-
.Update(uIView);
30+
.Update(uiText);
2631
}
2732
}
2833
}

0 commit comments

Comments
 (0)