Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize HideSoftInputOnTapped on Android and iOS to support 3rd party input controls #19626

Merged
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 @@ -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);
}
}
}
Loading