cordova-plugin-ionic-webview icon indicating copy to clipboard operation
cordova-plugin-ionic-webview copied to clipboard

Fix(iOS): Issues related to keyboard dismissal (2.x)

Open Lindsay-Needs-Sleep opened this issue 5 years ago • 1 comments

Sister PR for 4.x: PR #533


The history of the keyboard dismissal problems are kind of messy so here we go:

1)

The main bug that started this all is reported here:

To summarize: Apple did something and broke a part of WKWebView for iOS 12 and 13. The problem occurs when the keyboard is dismissed. After dismissal the bottom part of the page has a white unused portion / the content behind the keyboard becomes unusable.

The issue is truly an apple problem. So this PR, and the previously accepted PR #201, should not be required if apple ever actually releases the fix. (The fix has been completed already apparently).
You can see the apple bug report links here.

2)

PR #179 and PR #201 attempt to fix this problem.

  • PR #179 is denied.
  • PR #201 is accepted.

3)

Unfortunately, PR #201 introduces another a secondary bug, #399.
Now, when the keyboard is dismissed the screen scrolls all the way back to the top. (Also reported in cordova-plugin-ionic-keyboard #84.)

4)

To fix the scroll to top issue we have PR #342. Unfortunately, this introduces another (less problematic bug): the view now "jumps" a little when moving between text fields.


Proposed Solution

Modify the changes from PR #201 using inspiriration from PR #342.

In KeyboardWillHide event:

  • Detect when the presence of the keyboard has allowed the user to scroll further than they would have been able to without the keyboard. (aka. If there will be whitespace at the bottom when the keyboard goes down)
  • If in the situation above, do some math to calculate the maximum allowed offset, and set the view to that. This causes the view to move into place properly. (So no empty whitespace or unusable portion of the view.)

Environment

I have been testing with:

  • Xcode 10.2

My project is:

  • cordova
  • cordova-plugin-ionic-webview 2.x
  • no keyboard plugins
  • Lots of other plugins that shouldn't matter

I have been testing on these devices:

  • iPad mini 2, iOS 12.4.5 (real)
  • iPhone 6s, iOS 13.3.1 (real)
  • iPhone X, iOS 12.2 (emulator)

I have also tested this change with, and without, the changes in PR #530

I have also tested the 4.x sister PR #533 (which has identical changes basically) with these projects:

modified ionic tutorial

  • cordova-plugin-ionic-webview 4.x
  • cordova-plugin-ionic-keyboard / NO cordova-plugin-ionic-keyboard

modified cordova helloWorld

  • NO cordova-plugin-ionic-keyboard

Summary

Fixes:

Compatible with PR #530.

Alternate Solution

  • Remove all changes from PR #201 (the keyboard event listeners)
  • And recommend that users use cordova-plugin-wkkeyboardfix until Apple releases the fix in an iOS update

Pros:

  • Less code muddling on our side (cleaner history)

Cons:

  • Apparently the plugin may result in a rejection

(tested this plugin on the ionic and cordova project for 4.x, and cordova for 2.x)

Since this plugin has already fixed this issue, I suppose it is probably better to just fix the fix at this point rather than this.

Lindsay-Needs-Sleep avatar Mar 23 '20 12:03 Lindsay-Needs-Sleep

@jcesarmobile thanks for approving PR #533!

This PR is basically the exact same changes, but for 2.x. Would you be able to look at this PR as well?

Lindsay-Needs-Sleep avatar Apr 10 '20 21:04 Lindsay-Needs-Sleep