Skip to content

Commit 6fa940b

Browse files
committed
fix(mobile): Android composer card closes with the keyboard
1 parent 13ffae7 commit 6fa940b

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/n
3131
import type { ReactNode } from "react";
3232
import { useEffect, useLayoutEffect, useRef, useState, type RefObject } from "react";
3333
import { Keyboard, Platform, View, type ViewStyle } from "react-native";
34-
import { useKeyboardState } from "react-native-keyboard-controller";
34+
import { KeyboardController, KeyboardEvents } from "react-native-keyboard-controller";
3535
import { composerImageGallery } from "../../lib/composerImageGallery";
3636
import { filePreviewGallery } from "../../lib/filePreviewGallery";
3737
import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
@@ -470,6 +470,19 @@ export function ComposerSurface(props: {
470470
);
471471
}
472472

473+
function useKeyboardShowing() {
474+
const [showing, setShowing] = useState(KeyboardController.isVisible);
475+
useEffect(() => {
476+
const show = KeyboardEvents.addListener("keyboardWillShow", () => setShowing(true));
477+
const hide = KeyboardEvents.addListener("keyboardWillHide", () => setShowing(false));
478+
return () => {
479+
show.remove();
480+
hide.remove();
481+
};
482+
}, []);
483+
return showing;
484+
}
485+
473486
/** Space below the composer pill, inside the bottom inset it is given. */
474487
export const THREAD_COMPOSER_BOTTOM_GUTTER = 6;
475488

@@ -483,7 +496,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
483496
const fallbackInputRef = useRef<ComposerEditorHandle>(null);
484497
const inputRef = props.editorRef ?? fallbackInputRef;
485498
const [isFocused, setIsFocused] = useState(false);
486-
const keyboardVisible = useKeyboardState((state) => state.isVisible);
499+
const keyboardVisible = useKeyboardShowing();
487500
const pendingPastedTextAttachmentCountRef = useRef(0);
488501
const pendingNativeImagePasteCountRef = useRef(0);
489502
const [pendingPastedTextAttachmentCount, setPendingPastedTextAttachmentCount] = useState(0);

0 commit comments

Comments
 (0)