martinrybak / keyboard_avoider

A lightweight alternative to the Scaffold widget for avoiding the on-screen software keyboard. Automatically scrolls obscured TextField child widgets into view on focus.
https://medium.com/flutter-nyc/avoiding-the-on-screen-keyboard-in-flutter-ae0e46ecb96c
MIT License
118 stars 41 forks source link

fix keyboard blinking #5

Open 2ZeroSix opened 4 years ago

2ZeroSix commented 4 years ago

Fix for keyboard blinking issue. Added short debounce in didChangeMetrics calls when life cycle state is changed to.resumed.

before RPReplay_Final1588224308

after RPReplay_Final1588224782

might help to workaround this issue with default scaffolds resizeToAvoidBottomInset behavior: https://github.com/flutter/flutter/issues/53565

martinrybak commented 4 years ago

Thanks for discovering this! Indeed, this also affect the Scaffold widget. I pushed a potentially simpler fix to the foreground-blink branch. Can you see if that does the trick?

2ZeroSix commented 4 years ago

@martinrybak unfortunately this simpler fix introduce a bug:

  1. open app
  2. open keyboard
  3. switch to other app
  4. open keyboard
  5. close keyboard
  6. return to flutter app

result: widgets act like the keyboard is still open

image

martinrybak commented 4 years ago

Can you pull and try it again? Seems to work with the following use cases on iPhone 11 simulator running iOS 13.3:

For “other app”, I am using the News app (textfield on the Following tab).

Test case 1

  1. Open soft keyboard in other app
  2. Open soft keyboard in sample app
  3. Dismiss soft keyboard in other app
  4. Return to sample app, keyboard should close

Test case 2

  1. Open soft keyboard in sample app
  2. Open soft keyboard in other app
  3. Return to sample app, keyboard should still be open

Test case 3

  1. Open soft keyboard in sample app
  2. Open soft keyboard in other app
  3. Close soft keyboard in other app
  4. Return to sample app, keyboard should still be open
2ZeroSix commented 4 years ago

@martinrybak same issue :( iOS 13.4 In this test case where "other app" is Settings (search field at the top the same as in the gifs above)

Test case 1

  1. Open soft keyboard in other app
    1. Open soft keyboard in sample app
    2. Dismiss soft keyboard in other app
    3. Return to sample app, keyboard should close
martinrybak commented 4 years ago

I added a debounce as you suggested. Can you take another look?

martinrybak commented 4 years ago

@2ZeroSix does the latest on foreground-blink solve the issue? Thanks.

2ZeroSix commented 4 years ago

Yep, it does solve it for me 🎉, but I found another (pretty rare) scenario: Open example app and instantly change state of the keyboard, resize is just lost and layout stay the same. (in this pr it works as expected)

Do you mind if I try to modify your solution (as it seems much cleaner than mine) and create another PR?

martinrybak commented 4 years ago

Yes, by all means!