Fix: Keyboard opens on android when clicked on switch to keyboard btn in emoji picker (#9464)

This commit is contained in:
Rajat Dabade 2026-01-26 18:20:55 +05:30 committed by GitHub
parent 71d67f27d0
commit 98bf396714
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 8 deletions

View file

@ -9,6 +9,7 @@ import TouchableWithFeedback from '@components/touchable_with_feedback';
import {useKeyboardAnimationContext} from '@context/keyboard_animation'; import {useKeyboardAnimationContext} from '@context/keyboard_animation';
import {useTheme} from '@context/theme'; import {useTheme} from '@context/theme';
import {selectEmojiCategoryBarSection, useEmojiCategoryBar} from '@hooks/emoji_category_bar'; import {selectEmojiCategoryBarSection, useEmojiCategoryBar} from '@hooks/emoji_category_bar';
import {useFocusAfterEmojiDismiss} from '@hooks/useFocusAfterEmojiDismiss';
import {usePreventDoubleTap} from '@hooks/utils'; import {usePreventDoubleTap} from '@hooks/utils';
import {deleteLastGrapheme} from '@utils/grapheme'; import {deleteLastGrapheme} from '@utils/grapheme';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
@ -61,11 +62,14 @@ const EmojiCategoryBar = ({onSelect}: Props) => {
const keyboardContext = useKeyboardAnimationContext(); const keyboardContext = useKeyboardAnimationContext();
const { const {
focusInput, focusInput,
inputRef,
updateValue, updateValue,
updateCursorPosition, updateCursorPosition,
cursorPositionRef, cursorPositionRef,
} = keyboardContext; } = keyboardContext;
const {focus: focusWithEmojiDismiss} = useFocusAfterEmojiDismiss(inputRef, focusInput);
// Only show keyboard/delete buttons if we're in input accessory view mode // Only show keyboard/delete buttons if we're in input accessory view mode
// Check if updateValue is available (not null) to determine if we're in input accessory context // Check if updateValue is available (not null) to determine if we're in input accessory context
const showActionButtons = updateValue !== null; const showActionButtons = updateValue !== null;
@ -80,8 +84,8 @@ const EmojiCategoryBar = ({onSelect}: Props) => {
}, [onSelect]); }, [onSelect]);
const handleKeyboardPress = usePreventDoubleTap(useCallback(() => { const handleKeyboardPress = usePreventDoubleTap(useCallback(() => {
focusInput(); focusWithEmojiDismiss();
}, [focusInput])); }, [focusWithEmojiDismiss]));
const deleteCharFromCurrentCursorPosition = useCallback(() => { const deleteCharFromCurrentCursorPosition = useCallback(() => {
if (!updateValue || !updateCursorPosition || !cursorPositionRef) { if (!updateValue || !updateCursorPosition || !cursorPositionRef) {

View file

@ -45,13 +45,16 @@ export const useFocusAfterEmojiDismiss = (
inputRef.current?.blur(); inputRef.current?.blur();
const handleDelayedFocus = () => { // Use requestAnimationFrame to ensure state updates have been applied
focusInput(); requestAnimationFrame(() => {
setIsManuallyFocusingAfterEmojiDismiss(false); const handleDelayedFocus = () => {
focusTimeoutRef.current = null; focusInput();
}; setIsManuallyFocusingAfterEmojiDismiss(false);
focusTimeoutRef.current = null;
};
focusTimeoutRef.current = setTimeout(handleDelayedFocus, 200); focusTimeoutRef.current = setTimeout(handleDelayedFocus, 200);
});
return () => { return () => {
if (focusTimeoutRef.current) { if (focusTimeoutRef.current) {
@ -80,6 +83,20 @@ export const useFocusAfterEmojiDismiss = (
setIsEmojiSearchFocused(false); setIsEmojiSearchFocused(false);
setShowInputAccessoryView(false); setShowInputAccessoryView(false);
if (focusTimeoutRef.current) {
clearTimeout(focusTimeoutRef.current);
}
inputRef.current?.blur();
// Schedule focus after emoji picker closes
focusTimeoutRef.current = setTimeout(() => {
focusInput();
setIsManuallyFocusingAfterEmojiDismiss(false);
isDismissingEmojiPicker.current = false;
focusTimeoutRef.current = null;
}, 200);
} else { } else {
focusInput(); focusInput();
} }
@ -91,6 +108,7 @@ export const useFocusAfterEmojiDismiss = (
keyboardTranslateY, keyboardTranslateY,
isTransitioningFromCustomView, isTransitioningFromCustomView,
setIsEmojiSearchFocused, setIsEmojiSearchFocused,
inputRef,
focusInput, focusInput,
]); ]);