@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 26 lines 979 Bytes
Raw
1 import { useSyncExternalStore } from "react";
2 import { KeyboardController, KeyboardEvents } from "react-native-keyboard-controller";
3
4 // `useKeyboardState` only flips on willShow and didHide. This follows the will-events, so a
5 // layout that makes room for the keyboard gives it back as soon as the keyboard starts hiding.
6 let keyboardShowing = KeyboardController.isVisible();
7 function subscribeKeyboardShowing(onChange: () => void) {
8 keyboardShowing = KeyboardController.isVisible();
9 const willShow = KeyboardEvents.addListener("keyboardWillShow", () => {
10 keyboardShowing = true;
11 onChange();
12 });
13 const willHide = KeyboardEvents.addListener("keyboardWillHide", () => {
14 keyboardShowing = false;
15 onChange();
16 });
17 return () => {
18 willShow.remove();
19 willHide.remove();
20 };
21 }
22 const getKeyboardShowing = () => keyboardShowing;
23
24 export function useSoftKeyboardShowing() {
25 return useSyncExternalStore(subscribeKeyboardShowing, getKeyboardShowing);
26 }