Skip to content

fix: close keyboard even if it's partially visible#1436

Merged
kirillzyusko merged 2 commits intomainfrom
fix/close-keyboard-when-it-is-partially-visible
Apr 16, 2026
Merged

fix: close keyboard even if it's partially visible#1436
kirillzyusko merged 2 commits intomainfrom
fix/close-keyboard-when-it-is-partially-visible

Conversation

@kirillzyusko
Copy link
Copy Markdown
Owner

@kirillzyusko kirillzyusko commented Apr 16, 2026

📜 Description

Fixed an issue when calling KeyboardController.dismiss during the keyboard animation (when it appears) doesn't close a keyboard.

💡 Motivation and Context

If we use keyboardDidShow as an indication that keyboard is fully shown, then when keyboard is in progress of the animation calling KeyboardController.dismiss will not close keyboard, because isClosed will be true, so we'll go into this code:

return new Promise((resolve) => {
  if (isClosed) {
    resolve();

    return;
  }

The fix is quite trivial - we need to use keyboardWillShow instead of keyboardDIdShow. In this case as soon as keyboard starts its animation the isClosed will be false:

KeyboardEvents.addListener("keyboardWillShow", (e) => {
  isClosed = false;
  lastState = e;
});

The reasonable question is that such small fix produces a different behavior for KeyboardController.state() and KeyboardController.isVisible(). Before they would update their values only when animation completes. But now they will update values before keyboard appearance.

Technically it still makes sense and the bug above confirms that. We should treat keyboard as shown even if 1% of keyboard is visible on a screen.

I think further we may add additional prop to state like isAnimating/isTransitioning (or maybe even enum to show the difference OPENING | OPENED | CLOSING | CLOSED) to indicate that animation is in the process. But this is a future improvement. Hopefully it's not a breaking change 🤞

Close #1400

📢 Changelog

JS

  • change keyboardDidShow to keyboardWillShow in module.ts file;

🤔 How Has This Been Tested?

Tested manually on iPhone 17 Pro (iOS 26.2).

📸 Screenshots (if appropriate):

Before After
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-04-16.at.10.56.31.mov
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-04-16.at.10.55.33.mov

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko self-assigned this Apr 16, 2026
@kirillzyusko kirillzyusko added the 🐛 bug Something isn't working label Apr 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

📊 Package size report

Current size Target Size Difference
312781 bytes 313303 bytes -522 bytes 📉

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

LGTM

…is visible and what is not "visible" (if keyboard is shown even partially it means it is "visible", otherwise it's not visible).
@kirillzyusko kirillzyusko merged commit b3dc83e into main Apr 16, 2026
11 checks passed
@kirillzyusko kirillzyusko deleted the fix/close-keyboard-when-it-is-partially-visible branch April 16, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyboardController.dismiss doesn't work if the keyboard is still in motion

1 participant