Skip to content

Commit

Permalink
Merge pull request #53384 from margelo/fix/fallback-to-current-focus-…
Browse files Browse the repository at this point in the history
…activity-on-android-keyboard-controller
  • Loading branch information
mountiny authored Dec 2, 2024
2 parents 585c8ad + b7ca605 commit cb0613c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/utils/keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import {KeyboardController, KeyboardEvents} from 'react-native-keyboard-controller';
import {Keyboard} from 'react-native';

let isVisible = false;

KeyboardEvents.addListener('keyboardDidHide', () => {
Keyboard.addListener('keyboardDidHide', () => {
isVisible = false;
});

KeyboardEvents.addListener('keyboardDidShow', () => {
Keyboard.addListener('keyboardDidShow', () => {
isVisible = true;
});

// starting from [email protected]+ we can use `KeyboardController.dismiss()` directly
const dismiss = (): Promise<void> => {
return new Promise((resolve) => {
if (!isVisible) {
Expand All @@ -19,12 +18,12 @@ const dismiss = (): Promise<void> => {
return;
}

const subscription = KeyboardEvents.addListener('keyboardDidHide', () => {
const subscription = Keyboard.addListener('keyboardDidHide', () => {
resolve(undefined);
subscription.remove();
});

KeyboardController.dismiss();
Keyboard.dismiss();
});
};

Expand Down

0 comments on commit cb0613c

Please sign in to comment.