Skip to content

Commit

Permalink
Merge pull request #30483 from s-alves10/fix/issue-30119
Browse files Browse the repository at this point in the history
fix: don't focus composer if emoji picker is opened
  • Loading branch information
flodnv authored Oct 31, 2023
2 parents 337c5c1 + db3d93b commit 902d7cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {InteractionManager, TextInput} from 'react-native';
import * as EmojiPickerAction from './actions/EmojiPickerAction';
import ComposerFocusManager from './ComposerFocusManager';

type FocusWithDelay = (shouldDelay?: boolean) => void;
type FocusComposerWithDelay = (shouldDelay?: boolean) => void;
/**
* Create a function that focuses a text input.
* Create a function that focuses the composer.
*/
function focusWithDelay(textInput: TextInput | null): FocusWithDelay {
function focusComposerWithDelay(textInput: TextInput | null): FocusComposerWithDelay {
/**
* Focus the text input
* @param [shouldDelay] Impose delay before focusing the text input
Expand All @@ -14,7 +15,7 @@ function focusWithDelay(textInput: TextInput | null): FocusWithDelay {
// There could be other animations running while we trigger manual focus.
// This prevents focus from making those animations janky.
InteractionManager.runAfterInteractions(() => {
if (!textInput) {
if (!textInput || EmojiPickerAction.isEmojiPickerVisible()) {
return;
}

Expand All @@ -32,4 +33,4 @@ function focusWithDelay(textInput: TextInput | null): FocusWithDelay {
};
}

export default focusWithDelay;
export default focusComposerWithDelay;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as ComposerUtils from '@libs/ComposerUtils';
import getDraftComment from '@libs/ComposerUtils/getDraftComment';
import convertToLTRForComposer from '@libs/convertToLTRForComposer';
import * as EmojiUtils from '@libs/EmojiUtils';
import focusWithDelay from '@libs/focusWithDelay';
import focusComposerWithDelay from '@libs/focusComposerWithDelay';
import * as KeyDownListener from '@libs/KeyboardShortcut/KeyDownPressListener';
import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
Expand Down Expand Up @@ -394,7 +394,7 @@ function ComposerWithSuggestions({
* @memberof ReportActionCompose
*/
const focus = useCallback((shouldDelay = false) => {
focusWithDelay(textInputRef.current)(shouldDelay);
focusComposerWithDelay(textInputRef.current)(shouldDelay);
}, []);

const setUpComposeFocusManager = useCallback(() => {
Expand Down
9 changes: 3 additions & 6 deletions src/pages/home/report/ReportActionItemMessageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions';
import * as Browser from '@libs/Browser';
import * as ComposerUtils from '@libs/ComposerUtils';
import * as EmojiUtils from '@libs/EmojiUtils';
import focusWithDelay from '@libs/focusWithDelay';
import focusComposerWithDelay from '@libs/focusComposerWithDelay';
import onyxSubscribe from '@libs/onyxSubscribe';
import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
Expand Down Expand Up @@ -358,7 +358,7 @@ function ReportActionItemMessageEdit(props) {
/**
* Focus the composer text input
*/
const focus = focusWithDelay(textInputRef.current);
const focus = focusComposerWithDelay(textInputRef.current);

return (
<>
Expand Down Expand Up @@ -432,10 +432,7 @@ function ReportActionItemMessageEdit(props) {
<View style={styles.editChatItemEmojiWrapper}>
<EmojiPickerButton
isDisabled={props.shouldDisableEmojiPicker}
onModalHide={() => {
setIsFocused(true);
focus(true);
}}
onModalHide={() => focus(true)}
onEmojiSelected={addEmojiToTextBox}
nativeID={emojiButtonID}
emojiPickerID={props.action.reportActionID}
Expand Down

0 comments on commit 902d7cc

Please sign in to comment.