apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.16k stars 988 forks source link

Including input focus fix from cordova-plugin-wkwebview-engine #972

Closed u01jmg3 closed 4 years ago

u01jmg3 commented 4 years ago

Bug Report

Problem

I realise Cordova iOS 6.1.0 was released with its own copy of the WKWebView engine. I just wanted to know whether fixes previously included in cordova-plugin-wkwebview-engine for fixing input focus will be incorporated into this repo?

I also realise that KeyboardDisplayRequiresUserAction was part of the now deprecated UIWebView and in order to get similar functionality on WKWebView requires swizzling private methods. This means any fix can break if Apple decide to change their code.

What is expected to happen?

The keyboard should show when focusing an input element.

document.querySelector('input').focus()

What does actually happen?

The keyboard does not show when focusing an input element.

Information

Environment, Platform, Device

iOS 12.4.8

Version information

Cordova 10.0.0 Cordova iOS 6.1.0

Checklist

dpogue commented 4 years ago

in order to get similar functionality on WKWebView requires swizzling private methods

It is against Apple's rules to use private methods and might lead to apps being rejected, so we will not add any code to Cordova itself that makes use of them.

It should be possible for someone to write a 3rd party plugin that provides this behaviour.

u01jmg3 commented 4 years ago

@dpogue: is there no other way to allow focussing to work correctly on iOS 12 and 13 without a third-party plugin? Do you know why this is broken in the first place?

dpogue commented 4 years ago

According to Apple's view, it's not broken. This is intentional on their part: opening the keyboard always requires a user action like clicking on the page.

u01jmg3 commented 4 years ago

Thanks for the info. This seems contradictory when previously they offered the KeyboardDisplayRequiresUserAction option in UIWebView which allowed an app developer to control this very behaviour. But I guess UIWebView is now deprecated so perhaps it is no longer considered good practice. 🤷‍♂️

phemets commented 3 years ago

Is there a plugin or workaround that fixes this for Cordova iOS 6+? Seems like a lot of people are missing this, according to the end user feedback I get.

breautek commented 3 years ago

Is there a plugin or workaround that fixes this for Cordova iOS 6+? Seems like a lot of people are missing this, according to the end user feedback I get.

You can try deriving from this PR https://github.com/apache/cordova-plugin-wkwebview-engine/pull/122/files

But like Darryl says, you're going against what Apple believes to be correct. Afaik, you can only accomplish this by using private APIs, which is grounds for app rejection. It can also makes your code brittle as private APIs can change with no warning.

This seems contradictory when previously they offered the KeyboardDisplayRequiresUserAction option in UIWebView which allowed an app developer to control this very behaviour.

KeyboardDisplayRequiresUserAction is also deprecated, so I think Apple indeed reconsidered what is considered good practice.

u01jmg3 commented 3 years ago

so I think Apple indeed reconsidered what is considered good practice

But as @phemets has said, user feedback suggests this feature is missed. Are Apple correct to be dictating what our users should want? Either way, there's nothing we can do. :pensive:

breautek commented 3 years ago

Are Apple correct to be dictating what our users should want?

This isn't really anything new for Apple. They always valued simplistic design, which often includes removing features.

The proper way to get this addressed is to get into contact with Apple and request the feature. There isn't anything that can be done from Cordova.

u01jmg3 commented 3 years ago

For iOS 13+: https://github.com/adaptabi/cordova-plugin-wkwebview-inputfocusfix

phemets commented 3 years ago

Amazing! Works for me! Thank you, u01jmg3!

u01jmg3 commented 3 years ago

Thank @onderceylan who put me onto the fork @adaptabi created

phemets commented 3 years ago

Thank you very much @adaptabi, @onderceylan and @u01jmg3! My users will be very happy! The app update is already done and waiting for review!