Skip to content

Commit 524faa2

Browse files
Onkarj012claude
andcommitted
fix(mobile): Android back recovers when a keyboard hide event is missed
Dismissing an already-hidden IME emits no keyboardDidHide, so a missed hide left isVisible() stuck true and Back swallowed forever. A second Back before any show/hide event now goes through to the caller. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 15b6fe5 commit 524faa2

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
import { KeyboardController } from "react-native-keyboard-controller";
1+
import { KeyboardController, KeyboardEvents } from "react-native-keyboard-controller";
2+
3+
let dismissPending = false;
4+
KeyboardEvents.addListener("keyboardDidShow", () => {
5+
dismissPending = false;
6+
});
7+
KeyboardEvents.addListener("keyboardDidHide", () => {
8+
dismissPending = false;
9+
});
210

311
// Dismisses the soft keyboard when one is really open; returns whether it did.
412
export function dismissOpenKeyboard(): boolean {
513
// RN's Keyboard and TextInputState miss the chat composer, a custom native EditText. The
614
// keyboard controller tracks the IME natively and resyncs on resume, so it sees the composer.
715
if (!KeyboardController.isVisible()) return false;
16+
// Dismissing an already-hidden IME emits no keyboardDidHide, so a missed hide would leave
17+
// isVisible() stuck true. A second Back before any hide lands lets the caller act instead.
18+
if (dismissPending) return false;
19+
dismissPending = true;
820
void KeyboardController.dismiss();
921
return true;
1022
}

0 commit comments

Comments
 (0)