diff --git a/src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.js b/src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.js deleted file mode 100644 index 4f3e8c5de2c8..000000000000 --- a/src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as Composer from '../actions/Composer'; - -export default () => { - Composer.setShouldShowComposeInput(true); -}; diff --git a/src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.native.js b/src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.native.js deleted file mode 100644 index 488769741715..000000000000 --- a/src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.native.js +++ /dev/null @@ -1,9 +0,0 @@ -import {Keyboard} from 'react-native'; -import * as Composer from '../actions/Composer'; - -export default () => { - const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => { - Composer.setShouldShowComposeInput(true); - keyboardDidHideListener.remove(); - }); -}; diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/index.js b/src/libs/setShouldShowComposeInputKeyboardAware/index.js new file mode 100644 index 000000000000..a8ad5f54a65f --- /dev/null +++ b/src/libs/setShouldShowComposeInputKeyboardAware/index.js @@ -0,0 +1,5 @@ +import * as Composer from '../actions/Composer'; + +export default (shouldShow) => { + Composer.setShouldShowComposeInput(shouldShow); +}; diff --git a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.js b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.js new file mode 100644 index 000000000000..147d21d51168 --- /dev/null +++ b/src/libs/setShouldShowComposeInputKeyboardAware/index.native.js @@ -0,0 +1,26 @@ +import {Keyboard} from 'react-native'; +import * as Composer from '../actions/Composer'; + +let keyboardDidHideListener = null; +export default (shouldShow) => { + if (keyboardDidHideListener) { + keyboardDidHideListener.remove(); + keyboardDidHideListener = null; + } + + if (!shouldShow) { + Composer.setShouldShowComposeInput(false); + return; + } + + // If keyboard is already hidden, we should show composer immediately because keyboardDidHide event won't be called + if (!Keyboard.isVisible()) { + Composer.setShouldShowComposeInput(true); + return; + } + + keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => { + Composer.setShouldShowComposeInput(true); + keyboardDidHideListener.remove(); + }); +}; diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index 54c5fec4533e..a8a2629fe695 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -12,7 +12,7 @@ import * as StyleUtils from '../../../styles/StyleUtils'; import containerComposeStyles from '../../../styles/containerComposeStyles'; import Composer from '../../../components/Composer'; import * as Report from '../../../libs/actions/Report'; -import openReportActionComposeViewWhenClosingMessageEdit from '../../../libs/openReportActionComposeViewWhenClosingMessageEdit'; +import setShouldShowComposeInputKeyboardAware from '../../../libs/setShouldShowComposeInputKeyboardAware'; import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager'; import EmojiPickerButton from '../../../components/EmojiPicker/EmojiPickerButton'; import Icon from '../../../components/Icon'; @@ -74,8 +74,6 @@ const defaultProps = { }; // native ids -const saveButtonID = 'saveButton'; -const cancelButtonID = 'cancelButton'; const emojiButtonID = 'emojiButton'; const messageEditInput = 'messageEditInput'; @@ -202,8 +200,10 @@ function ReportActionItemMessageEdit(props) { const deleteDraft = useCallback(() => { debouncedSaveDraft.cancel(); Report.saveReportActionDraft(props.reportID, props.action.reportActionID, ''); - ComposerActions.setShouldShowComposeInput(true); - ReportActionComposeFocusManager.focus(); + if (isFocusedRef.current) { + ComposerActions.setShouldShowComposeInput(true); + ReportActionComposeFocusManager.focus(); + } // Scroll to the last comment after editing to make sure the whole comment is clearly visible in the report. if (props.index === 0) { @@ -279,7 +279,6 @@ function ReportActionItemMessageEdit(props) { e.preventDefault()} > {({hovered, pressed}) => ( { setIsFocused(true); reportScrollManager.scrollToIndex({animated: true, index: props.index}, true); - ComposerActions.setShouldShowComposeInput(false); + setShouldShowComposeInputKeyboardAware(false); }} onBlur={(event) => { setIsFocused(false); const relatedTargetId = lodashGet(event, 'nativeEvent.relatedTarget.id'); - - // Return to prevent re-render when save/cancel button is pressed which cancels the onPress event by re-rendering - if (_.contains([saveButtonID, cancelButtonID, emojiButtonID], relatedTargetId)) { - return; - } - - if (messageEditInput === relatedTargetId) { + if (_.contains([messageEditInput, emojiButtonID], relatedTargetId)) { return; } - openReportActionComposeViewWhenClosingMessageEdit(); + setShouldShowComposeInputKeyboardAware(true); }} selection={selection} onSelectionChange={(e) => setSelection(e.nativeEvent.selection)} @@ -348,8 +343,8 @@ function ReportActionItemMessageEdit(props) { isDisabled={props.shouldDisableEmojiPicker} onModalHide={() => InteractionManager.runAfterInteractions(() => textInputRef.current.focus())} onEmojiSelected={addEmojiToTextBox} - nativeID={emojiButtonID} reportAction={props.action} + nativeID={emojiButtonID} /> @@ -358,12 +353,13 @@ function ReportActionItemMessageEdit(props) { e.preventDefault()} >