capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

Keyboard resize is slow in iOS

Open aeharding opened this issue 1 year ago • 12 comments

Bug Report

Plugin(s)

Keyboard

Capacitor Version

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 5.5.1
  @capacitor/core: 5.5.1
  @capacitor/android: 5.5.1
  @capacitor/ios: 5.5.1

Installed Dependencies:

  @capacitor/cli: 5.2.3
  @capacitor/android: 5.2.3
  @capacitor/core: 5.2.3
  @capacitor/ios: 5.2.3

Platform(s)

iOS

Current Behavior

On iOS, the app is incorrectly resized after the keyboard animation finishes, not before.

On Android, web view is correctly resized before keyboard animation starts.

Expected Behavior

Web view is resized before keyboard animation starts.

Code Reproduction

https://github.com/aeharding/test-keyboard-slow

Other Technical Details

iOS incorrect behavior

https://github.com/ionic-team/capacitor-plugins/assets/2166114/888abf46-c036-4959-9738-49140f91848a

Android correct behavior

https://github.com/ionic-team/capacitor-plugins/assets/2166114/feaadf20-688f-40e8-8a1d-a1df67c329bd

Additional Context

Original issue that got closed as stale: https://github.com/ionic-team/capacitor/issues/1540

aeharding avatar Nov 16 '23 01:11 aeharding

@aeharding Yes i use capacitor 4 and not 5 because since capacitor 5 the keyboard closing on ios is really slow. And on closing a white background is flickering on my dark themed app.

stephan-fischer avatar Jan 16 '24 20:01 stephan-fischer

I'm having the same issue. I took a quick look at the code and I'm wondering if this line is the culprit: https://github.com/ionic-team/capacitor-plugins/blob/d5483ce9f666f1a38c25a11e63899fd35701ca45/keyboard/ios/Plugin/Keyboard.m#L145

It adds a delay to keyboard resizing code. The delay has of length of UIKeyboardAnimationDurationUserInfoKey + 0.2 seconds The delay is smaller when hiding the keyboard which is probably why hiding is a bit smoother.

With the current code we can't apply this fix correctly: https://github.com/ionic-team/capacitor/issues/1540#issuecomment-735221275

With the delay in place the transition animation will start late and therefore the content will resize late again.

Achder avatar Mar 06 '24 09:03 Achder

@dallastjames could you maybe look into this PR https://github.com/ionic-team/capacitor-plugins/pull/1634 This issue widens the native <> capacitor divide. It makes the app feel less native which is a big problem

Achder avatar Mar 07 '24 08:03 Achder

@aeharding Did you by any chance find a workaround for this?

Achder avatar Mar 22 '24 13:03 Achder

I fiddled around with the code and removed the delay I mentioned above. Without the delay the experience is much better. I'd love to provide a PR to fix this but I don't have enough inside into why the delay is hardcoded in the first place. @dallastjames could comment on the issue?

Achder avatar Apr 16 '24 11:04 Achder

anyone got a fix for this, removing the delay dont fix the problem for me. if anyone got he solution in my bio is my discord, maybe we could help each other out!

Reiserro avatar Apr 17 '24 21:04 Reiserro

@Reiserro If you're still on v5 try my forked version: https://www.npmjs.com/package/@meerpohl/keyboard

I will soon provide a v6 fork.

Achder avatar Apr 18 '24 08:04 Achder

@Achder thanks my G its working! Thumbs up hamster

Reiserro avatar Apr 18 '24 21:04 Reiserro

Issue still present in Capacitor 6, makes for a poor user experience on iOS devices.

mpmua avatar May 23 '24 09:05 mpmua

Looking for a solution to this as well, in the meantime I found a workaround.

Capacitor is compatible with Cordova plugins. I installed https://github.com/cjpearson/cordova-plugin-keyboard and uninstalled @capacitor/keyboard, then put this JS line in my app startup:

window.Keyboard.shrinkView(true);

Now I don't have an issue with delayed resizing

sam-hu avatar Jun 08 '24 04:06 sam-hu

Is there any plan to address this issue?

Vasile-Peste avatar Aug 19 '24 13:08 Vasile-Peste