Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from

Conversation

Lindsay-Needs-Sleep
Copy link
Contributor

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.

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

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.

…#176) (ionic-team#399)

- We only need the KeyboardWillHide event to fix this problem, and we only need it for ios 11+
- Enable the fix for ios 11+, not only ios 12+. It was probably only 12+ because no devices have a max OS of 11, so no dev probably confirmed the problem's existence (or non-existence) on 11, myself included.  (But the functionality that started this issue chain began in ios 11.)
- Do some math to make sure the offset when the keyboard goes down doesn't result in empty white space being displayed.
- This solution can potentially be removed when apple finally releases the fix for the issue discussed here: apache/cordova-ios#417 (comment)
For full details see PR ionic-team#532
@Lindsay-Needs-Sleep Lindsay-Needs-Sleep force-pushed the fix_2x_keyboard-dismissal-view-shift-399-176 branch from 08c9c3f to d82b0f3 Compare March 23, 2020 12:01
@Lindsay-Needs-Sleep Lindsay-Needs-Sleep changed the title Fix 2x keyboard dismissal view shift Fix 2x keyboard dismissal problems Mar 23, 2020
@Lindsay-Needs-Sleep Lindsay-Needs-Sleep changed the title Fix 2x keyboard dismissal problems Fix(iOS): (2.x) Issues related to keyboard dismissal Mar 23, 2020
@Lindsay-Needs-Sleep Lindsay-Needs-Sleep changed the title Fix(iOS): (2.x) Issues related to keyboard dismissal Fix(iOS): Issues related to keyboard dismissal (2.x) Mar 23, 2020
@Lindsay-Needs-Sleep
Copy link
Contributor Author

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants