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

(cherry picked from commit cb0613c)

(CP triggered by puneetlath)
  • Loading branch information
mountiny authored and OSBotify committed Dec 2, 2024
1 parent dbeefcb commit 0fa41b4
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 0fa41b4

Please sign in to comment.