From e1bebc9bc3b3793cace51ba70e7ea5bab85a4e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Tue, 1 Aug 2023 14:47:16 -0600 Subject: [PATCH] Revert "fix: show main composer when there is no focused draft" --- .../index.js | 5 ++++ .../index.native.js | 9 ++++++ .../index.js | 5 ---- .../index.native.js | 26 ---------------- .../report/ReportActionItemMessageEdit.js | 30 +++++++++++-------- 5 files changed, 31 insertions(+), 44 deletions(-) create mode 100644 src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.js create mode 100644 src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.native.js delete mode 100644 src/libs/setShouldShowComposeInputKeyboardAware/index.js delete mode 100644 src/libs/setShouldShowComposeInputKeyboardAware/index.native.js diff --git a/src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.js b/src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.js new file mode 100644 index 000000000000..4f3e8c5de2c8 --- /dev/null +++ b/src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.js @@ -0,0 +1,5 @@ +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 new file mode 100644 index 000000000000..488769741715 --- /dev/null +++ b/src/libs/openReportActionComposeViewWhenClosingMessageEdit/index.native.js @@ -0,0 +1,9 @@ +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 deleted file mode 100644 index a8ad5f54a65f..000000000000 --- a/src/libs/setShouldShowComposeInputKeyboardAware/index.js +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 147d21d51168..000000000000 --- a/src/libs/setShouldShowComposeInputKeyboardAware/index.native.js +++ /dev/null @@ -1,26 +0,0 @@ -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 a8a2629fe695..54c5fec4533e 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 setShouldShowComposeInputKeyboardAware from '../../../libs/setShouldShowComposeInputKeyboardAware'; +import openReportActionComposeViewWhenClosingMessageEdit from '../../../libs/openReportActionComposeViewWhenClosingMessageEdit'; import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager'; import EmojiPickerButton from '../../../components/EmojiPicker/EmojiPickerButton'; import Icon from '../../../components/Icon'; @@ -74,6 +74,8 @@ const defaultProps = { }; // native ids +const saveButtonID = 'saveButton'; +const cancelButtonID = 'cancelButton'; const emojiButtonID = 'emojiButton'; const messageEditInput = 'messageEditInput'; @@ -200,10 +202,8 @@ function ReportActionItemMessageEdit(props) { const deleteDraft = useCallback(() => { debouncedSaveDraft.cancel(); Report.saveReportActionDraft(props.reportID, props.action.reportActionID, ''); - if (isFocusedRef.current) { - ComposerActions.setShouldShowComposeInput(true); - ReportActionComposeFocusManager.focus(); - } + 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,6 +279,7 @@ function ReportActionItemMessageEdit(props) { e.preventDefault()} > {({hovered, pressed}) => ( { setIsFocused(true); reportScrollManager.scrollToIndex({animated: true, index: props.index}, true); - setShouldShowComposeInputKeyboardAware(false); + ComposerActions.setShouldShowComposeInput(false); }} onBlur={(event) => { setIsFocused(false); const relatedTargetId = lodashGet(event, 'nativeEvent.relatedTarget.id'); - if (_.contains([messageEditInput, emojiButtonID], relatedTargetId)) { + + // 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) { return; } - setShouldShowComposeInputKeyboardAware(true); + openReportActionComposeViewWhenClosingMessageEdit(); }} selection={selection} onSelectionChange={(e) => setSelection(e.nativeEvent.selection)} @@ -343,8 +348,8 @@ function ReportActionItemMessageEdit(props) { isDisabled={props.shouldDisableEmojiPicker} onModalHide={() => InteractionManager.runAfterInteractions(() => textInputRef.current.focus())} onEmojiSelected={addEmojiToTextBox} - reportAction={props.action} nativeID={emojiButtonID} + reportAction={props.action} /> @@ -353,13 +358,12 @@ function ReportActionItemMessageEdit(props) { e.preventDefault()} >