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

Conversation

@ccorcos
Copy link
Contributor

@ccorcos ccorcos commented Jun 9, 2017

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

Cordova CI Build has completed successfully.

Commit - Link
Dashboard - Link

2 tests run, 0 skipped, 0 failed.

@ccorcos
Copy link
Contributor Author

ccorcos commented Jun 12, 2017

@shazron @stevengill any thoughts?

@shazron
Copy link
Member

shazron commented Jun 12, 2017

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
Copy link
Contributor Author

ccorcos commented Jun 12, 2017

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

@SeanHub
Copy link

SeanHub commented Jun 14, 2017

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

@ccorcos
Copy link
Contributor Author

ccorcos commented Jun 14, 2017

@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
Copy link
Contributor

cjpearson commented Jun 15, 2017

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

Cordova CI Build has completed successfully.

Commit - Link
Dashboard - Link

2 tests run, 0 skipped, 0 failed.

@cordova-qa
Copy link

Cordova CI Build has one or more failures.

Commit - Link
Dashboard - Link

0 tests run, 0 skipped, 0 failed.

@cordova-qa
Copy link

Cordova CI Build has one or more failures.

Commit - Link
Dashboard - Link

0 tests run, 0 skipped, 0 failed.

@cordova-qa
Copy link

Cordova CI Build has completed successfully.

Commit - Link
Dashboard - Link

2 tests run, 0 skipped, 0 failed.

@cordova-qa
Copy link

Cordova CI Build has completed successfully.

Commit - Link
Dashboard - Link

2 tests run, 0 skipped, 0 failed.

@ccorcos
Copy link
Contributor Author

ccorcos commented Jun 19, 2017

@cjpearson really cool. I'll do that.

@onderceylan
Copy link

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
Copy link

hirbod commented Mar 31, 2018

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
Copy link

steodor commented Aug 1, 2018

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

Labels

None yet

10 participants