maui icon indicating copy to clipboard operation
maui copied to clipboard

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

Open albyrock87 opened this issue 1 year ago • 8 comments

Description of Change

Generalize recognition of text inputs in HideSoftInputOnTappedChangedManager so that 3rd party libraries with native handlers can leverage this new feature of ContentPage by simply adding a mapper the same way InputView does.

internal static void MapIsFocused(IViewHandler handler, IView view)
{
	handler
		?.GetService<HideSoftInputOnTappedChangedManager>()
		?.UpdateFocusForView(iv);
}

Unfortunately HideSoftInputOnTappedChangedManager is internal, but they can still use it via reflection.

I know it's suboptimal but I didn't want to change public API.

See more at: https://supportcenter.devexpress.com/ticket/details/t1201718/the-keyboard-remains-visible-on-a-click-outside-editors-even-if-the-contentpage

albyrock87 avatar Dec 29 '23 19:12 albyrock87

Hey there @albyrock87! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

ghost avatar Dec 29 '23 20:12 ghost

Can you add tests for this?

We have some existing tests for this here.

https://github.com/dotnet/maui/blob/409122477be6a8ddaea44771f28cc39007aa0a0b/src/Controls/samples/Controls.Sample.UITests/Issues/HideSoftInputOnTappedPage.cs#L9

PureWeen avatar Jan 04 '24 15:01 PureWeen

@PureWeen I think existing unit tests already cover this for the following reasons:

  • iOS => UISearchBar is generally a UIView which contains an UITextField first responder
  • Android => SearchView is a ViewGroup which contains an EditText control
  • existing unit tests cover the search bar control

Therefore, the fact that I removed specific reference to UISearchBar and SearchView and everything still works proofs implicitly that:

  • Search bar still works
  • Generalization works

I don't see what other kind of unit test I should add given that search bar is already an example of a native control which contains a text editor.

albyrock87 avatar Jan 04 '24 16:01 albyrock87

Bump!

jurganson avatar Jan 30 '24 09:01 jurganson

Hello, We are working on DevExpress .NET MAUI components, and functionality in our editors depend on this pull request. Could you kindly provide information on whether there are plans to incorporate it into .NET 8? This clarification is crucial for our ongoing work, as it will help us determine whether we can afford to wait for an update or if we should proceed with implementing a temporary workaround.

Alexgoon avatar Feb 01 '24 07:02 Alexgoon

@Alexgoon have you seen the workaround I proposed here? This is fully working and probably covers even more uses cases than what could be achieved with what I proposed here. I would like to help the "DevExpress Community" but your support center makes it impossible to comment on other tickets.

I will try to propose a different PR here with that strategy (which is completely different but more effective). But considering the type of change, I guess it'll eventually end up in .NET 9.

albyrock87 avatar Feb 01 '24 08:02 albyrock87

@albyrock87, thank you very much for your contribution! Yes, we've seen the workaround, and it can definitely be used as a temporary solution by our customers. We've mentioned this technique in the following thread: The Keyboard remains visible on a click outside editors even if the ContentPage.HideSoftInputOnTapped property is enabled

However, the workaround requires overriding a MauiAppCompatActivity method, but we would like to fix the issue on our side so that our customers can get a working solution in the default configuration. That's why we are hoping that this PR will be introduced in .NET. However, .NET 9 is too far away, and I'm afraid too many customers may face the issue until a new version is available.

Alexgoon avatar Feb 01 '24 11:02 Alexgoon

@Alexgoon if you want to avoid that, you can probably use reflection to add that part of my workaround here: https://github.com/dotnet/maui/blob/a01e1ee184d9dcde58f6d6f7d14f03a3222378c3/src/Controls/src/Core/Window/Window.Android.cs#L41

albyrock87 avatar Feb 01 '24 12:02 albyrock87

/rebase

PureWeen avatar Feb 28 '24 21:02 PureWeen

https://dev.azure.com/xamarin/public/_build/results?buildId=110133&view=results

PureWeen avatar Feb 29 '24 18:02 PureWeen

/azp run

PureWeen avatar Feb 29 '24 20:02 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Feb 29 '24 20:02 azure-pipelines[bot]

Failing tests are unrelated

PureWeen avatar Mar 01 '24 21:03 PureWeen