xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

WebView losing selection on iOS on button tap #5175

Open carlos-ferreira opened 5 years ago

carlos-ferreira commented 5 years ago

Description

When we tap on a button with selected text on a webview, the keyboard closes and the text looses the selection.

It's working perfectly on Android but not on iOS.

This behavior doesn't happen by default on native iOS.

The native implementation is the following: alt text

Steps to Reproduce

  1. Create a content page with a webview with a content editable html page and a button
  2. Tap on the content editable element
  3. Write some text
  4. Select the text
  5. Tap on the button on the content page

Expected Behavior

The keyboard shouldn't close and the text shouldn't loose it's selection nor should the keyboard close.

Actual Behavior

The text looses selection and the keyboard closes.

Basic Information

Screenshots

Working:

alt text

Not working

alt text

Reproduction Link

https://github.com/carlos-ferreira/bug-reports/tree/master/Xamarin/Webview

arorasurbhi93 commented 5 years ago

Any resolution on this? I am also facing the same issue.

dillibabun commented 5 years ago

Hi Team,

Is there any updates on this ? Its a showstopper in our development works so please get rid of this issue ASAP.

ahmedalejo commented 5 years ago

@dillibabun please submit a pull request ASAP. This issue is very very important!

dillibabun commented 5 years ago

@ahmedalejo Even we are looking for the issue fix from Xamarin team and our development work stopped due to this issue.

carlos-ferreira commented 4 years ago

I tried to do some investigation to understand why this happened and i found out why.

On Xamarin.Forms.Platform.iOS the PageRenderer adds a UITapGestureRecognizer:

imagem

This is what is causing the blur on the webview and closing the keyboard.

A workaround for this would be creating a custom page renderer for the page that is using the webview, override the ViewDidLoad method and remove the Gesture Recognizer:

public override void ViewDidLoad()
{
    base.ViewDidLoad();

    this.NativeView.RemoveGestureRecognizer(this.NativeView.GestureRecognizers.First());
}

This way, when a button is pressed, the keyboard isn't dismissed and the focus isn't lost.

The true question now is, is this really a bug @samhouts ? Why does Xamarin.Forms add this Gesture Recognizer ?

andreas-siegmund commented 3 years ago

Hi,

I faced this issue now as well and after some investigation you find a lot of examples of people having a similar issue. Often it is about some text entry field losing the focus when another button on the page is pressed. The proposed solutions for those issues were always some dirty hacks. Hence I would assume that the root cause of this issue also affects those cases with the entry fields.

So the question remains why this gesture recognizer is added and what purpose it serves. Can anybody answer this, e.g. @samhouts?

As the native behaviour is clearly different I assume a fix would be necessary, right? Thanks in advance to anybody taking care of it.