Skip to content

Commit 98d0423

Browse files
fix(mobile): terminal accessory also clears on Android's didHide-only IME hide
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 996ef6e commit 98d0423

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

‎apps/mobile/src/features/terminal/terminalKeyboardShowing.test.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,19 @@ function emit(name: string) {
2121
}
2222

2323
// Android's syncKeyboardPosition repairs a nonanimated IME inset change with
24-
// keyboardDidHide then keyboardDidShow, and no keyboardWillShow.
25-
it("brings the accessory back when Android restores the keyboard with keyboardDidShow alone", () => {
24+
// keyboardDidHide then keyboardDidShow, and no will-events.
25+
it("follows Android's nonanimated hide and show, which send only the did-events", () => {
2626
const onChange = vi.fn();
2727
const unsubscribe = subscribeKeyboardShowing(onChange);
2828
emit("keyboardWillShow");
29-
emit("keyboardWillHide");
30-
emit("keyboardDidHide");
31-
onChange.mockClear();
3229

30+
emit("keyboardDidHide");
31+
const hidden = { showing: getKeyboardShowing(), notified: onChange.mock.calls.length };
3332
emit("keyboardDidShow");
3433

35-
expect({ showing: getKeyboardShowing(), notified: onChange.mock.calls.length }).toEqual({
36-
showing: true,
37-
notified: 1,
38-
});
34+
expect({
35+
hidden,
36+
shown: { showing: getKeyboardShowing(), notified: onChange.mock.calls.length },
37+
}).toEqual({ hidden: { showing: false, notified: 2 }, shown: { showing: true, notified: 3 } });
3938
unsubscribe();
4039
});

‎apps/mobile/src/features/terminal/terminalKeyboardShowing.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { KeyboardController, KeyboardEvents } from "react-native-keyboard-contro
22

33
// `useKeyboardState` only flips to hidden on didHide; the accessory must
44
// leave as soon as the keyboard starts hiding, so it follows the will-events.
5-
// Android restores a nonanimated IME inset with keyboardDidShow alone.
5+
// Android shows and hides a nonanimated IME inset with the did-events alone.
66
let keyboardShowing = KeyboardController.isVisible();
77
export function subscribeKeyboardShowing(onChange: () => void) {
88
keyboardShowing = KeyboardController.isVisible();
@@ -12,14 +12,17 @@ export function subscribeKeyboardShowing(onChange: () => void) {
1212
};
1313
const willShow = KeyboardEvents.addListener("keyboardWillShow", show);
1414
const didShow = KeyboardEvents.addListener("keyboardDidShow", show);
15-
const willHide = KeyboardEvents.addListener("keyboardWillHide", () => {
15+
const hide = () => {
1616
keyboardShowing = false;
1717
onChange();
18-
});
18+
};
19+
const willHide = KeyboardEvents.addListener("keyboardWillHide", hide);
20+
const didHide = KeyboardEvents.addListener("keyboardDidHide", hide);
1921
return () => {
2022
willShow.remove();
2123
didShow.remove();
2224
willHide.remove();
25+
didHide.remove();
2326
};
2427
}
2528
export const getKeyboardShowing = () => keyboardShowing;

0 commit comments

Comments
 (0)