Mastering keyboard management ๐ฅท๐ผ
Today I'm glad to announce a new 1.15.0
version of react-native-keyboard-controller
๐
This release mainly focuses on managing keyboard state, improving keyboard dismissal interactions and API enhancements, so let's go and see which new features this release brings ๐
Changes to dismiss
methodโ
dismiss
method now returns a promiseโ
Previously, the dismiss
method was synchronous, which meant that you couldn't determine the moment when keyboard is fully hidden. Typically many developers were using one time listener that was resolving a promise or executing the code that had to be executed after keyboard dismissal. The code could look like this:
import {
KeyboardController,
KeyboardEvents,
} from "react-native-keyboard-controller";
const subscription = KeyboardEvents.addListener("keyboardDidHide", () => {
setVisible(true);
subscription.remove();
});
KeyboardController.dismiss();
Now, dismiss
returns a promise, so you can use it in async
way:
import { KeyboardController } from "react-native-keyboard-controller";
await KeyboardController.dismiss();
setVisible(true);
Much cleaner and more readable code! ๐ช
dismiss
now blurs input by defaultโ
The previous behavior of dismiss
was keeping the focus on the input on Android and blurring the input on iOS. This behavior was not very intuitive and such inconsistency could causing a lot of issues. Now, the default behavior is to blur the input on both platforms ๐
Though a rhetorical question might be raised - "I liked the old behavior, when input still hold the focus ๐คทโโ๏ธ. How to restore a previous behavior?" We hear you! ๐