Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't focus composer if emoji picker is opened #30483

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the name change required? we still have the option to pass the textInput ref, it is possible the input component not be the composer we are trying to focus always.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@getusha

Please check #30119 (comment)

/**
* 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
Loading