Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

CB-10376, CB-12037: (ios) Fix bug where WKWebView doesnt respect the KeyboardDisplayRequiresUserAction setting - #37

Closed
ccorcos wants to merge 9 commits into
apache:masterfrom
ccorcos:master
Closed

ccorcos wants to merge 9 commits into
apache:masterfrom
ccorcos:master

Conversation

@ccorcos

@ccorcos ccorcos commented Jun 9, 2017 •

Copy link
Copy Markdown
Contributor

Platforms affected

  • iOS

What does this PR do?

This PR does some magic to allow .focus() to bring up the keyboard in WKWebView. I read about this approach in a few places and saw this commit in another plugin. From what I understand, its basically accessing a private method in WKWebView.

What testing has been done on this change?

Using it on my iPhone 7 and in the Simulator and it definitely works :) I'm not a native developer so I could use some guidance getting this PR to the point where its mergeable. But its definitely useful and absolutely necessary for the app I'm building.

Checklist

  • Reported an issue in the JIRA database
  • Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
  • Added automated test coverage as appropriate for this change.

@ccorcos ccorcos changed the title CB-10376: (ios) Fix bug where WKWebView doesnt respect the KeyboardDisplayRequiresUserAction setting CB-10376, CB-12037: (ios) Fix bug where WKWebView doesnt respect the KeyboardDisplayRequiresUserAction setting Jun 9, 2017
@cordova-qa

Copy link
Copy Markdown

Cordova CI Build has completed successfully.

Commit - Link
Dashboard - Link

2 tests run, 0 skipped, 0 failed.

@ccorcos

ccorcos commented Jun 12, 2017

Copy link
Copy Markdown
Contributor Author

@shazron @stevengill any thoughts?

@shazron

shazron commented Jun 12, 2017

Copy link
Copy Markdown
Member

We appreciate the PR, but ultimately we can't accept it. Please see this thread for a similar PR that uses undocumented/private API: #26

@ccorcos

ccorcos commented Jun 12, 2017

Copy link
Copy Markdown
Contributor Author

I see. But I figured that why we test on the next iOS before it comes out.

@SeanHub

SeanHub commented Jun 14, 2017

Copy link
Copy Markdown

Given a private (unsupported) function cannot be used, does anybody know of any workarounds to force programmatic focus of an input using WKWebView?

@ccorcos

ccorcos commented Jun 14, 2017

Copy link
Copy Markdown
Contributor Author

@SeanHub here's what I've learned so far:

  • you can call .focus() so long as its in the same tick as a user action. For example, you can call .focus() on an element synchronously in click event handler.

  • you can call event.preventDefault() on the mousedown event to prevent the input from being blurred

Or if you want, you can use my fork and then.focus() just works!

<plugin name="cordova-plugin-wkwebview-engine" spec="https://github.com/ccorcos/cordova-plugin-wkwebview-engine#e994874583d7e5f4ae1713643dbd8e01c60a0a03" />

@cjpearson

cjpearson commented Jun 15, 2017 •

Copy link
Copy Markdown
Contributor

Since this change just swizzles the WKWebView class, you can make it separate plugin instead of a fork. It might make maintenance easier. Look in #30 for an example.

@cordova-qa

Copy link
Copy Markdown

Cordova CI Build has completed successfully.

Commit - Link
Dashboard - Link

2 tests run, 0 skipped, 0 failed.

@cordova-qa

Copy link
Copy Markdown

Cordova CI Build has one or more failures.

Commit - Link
Dashboard - Link

0 tests run, 0 skipped, 0 failed.

@cordova-qa

Copy link
Copy Markdown

Cordova CI Build has one or more failures.

Commit - Link
Dashboard - Link

0 tests run, 0 skipped, 0 failed.

@cordova-qa

Copy link
Copy Markdown

Cordova CI Build has completed successfully.

Commit - Link
Dashboard - Link

2 tests run, 0 skipped, 0 failed.

@cordova-qa

Copy link
Copy Markdown

Cordova CI Build has completed successfully.

Commit - Link
Dashboard - Link

2 tests run, 0 skipped, 0 failed.

@ccorcos

ccorcos commented Jun 19, 2017

Copy link
Copy Markdown
Contributor Author

@cjpearson really cool. I'll do that.

@onderceylan

Copy link
Copy Markdown

I just created a class catalog as a cordova plugin to enable focus on WKWebView. You can install it from https://www.npmjs.com/package/cordova-plugin-wkwebview-inputfocusfix.

@hirbod

hirbod commented Mar 31, 2018

Copy link
Copy Markdown

This doesn't work on iOS 11.3 anymore. Our App is half-broken now. Is there any chance someone could fix this? I don't have any exp. swizzling code...

@steodor

steodor commented Aug 1, 2018

Copy link
Copy Markdown

https://www.npmjs.com/package/cordova-plugin-wkwebview-inputfocusfix works again, like a charm. Thank you very much @hirbod and @onderceylan !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants