From 49ad7e76ae89764eb83ebe6c07f3e60868ef2e0e Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Tue, 3 Oct 2023 10:38:07 +0700 Subject: [PATCH] fix expand button disappear after clicking send --- .../ComposerWithSuggestions.js | 6 ++--- .../ReportActionCompose.js | 27 ++++++++++++++----- .../report/ReportActionCompose/SendButton.js | 26 +++--------------- .../composerWithSuggestionsProps.js | 2 +- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js index d04983dc2f75..69de6da1fcd6 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js @@ -91,7 +91,7 @@ function ComposerWithSuggestions({ isFullComposerAvailable, setIsFullComposerAvailable, setIsCommentEmpty, - submitForm, + handleSendMessage, shouldShowComposeInput, measureParentContainer, // Refs @@ -312,7 +312,7 @@ function ComposerWithSuggestions({ // Submit the form when Enter is pressed if (e.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey && !e.shiftKey) { e.preventDefault(); - submitForm(); + handleSendMessage(); } // Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty and Chronos is not in the participants @@ -331,7 +331,7 @@ function ComposerWithSuggestions({ } } }, - [isKeyboardShown, isSmallScreenWidth, parentReportActions, report, reportActions, reportID, submitForm, suggestionsRef, valueRef], + [isKeyboardShown, isSmallScreenWidth, parentReportActions, report, reportActions, reportID, handleSendMessage, suggestionsRef, valueRef], ); const onSelectionChange = useCallback( diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js index dedccc65a390..552cd2cc21ad 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js @@ -4,7 +4,7 @@ import {View} from 'react-native'; import _ from 'underscore'; import lodashGet from 'lodash/get'; import {withOnyx} from 'react-native-onyx'; -import {useAnimatedRef} from 'react-native-reanimated'; +import {runOnJS, useAnimatedRef} from 'react-native-reanimated'; import {PortalHost} from '@gorhom/portal'; import styles from '../../../../styles/styles'; import ONYXKEYS from '../../../../ONYXKEYS'; @@ -37,6 +37,7 @@ import getModalState from '../../../../libs/getModalState'; import useWindowDimensions from '../../../../hooks/useWindowDimensions'; import * as EmojiPickerActions from '../../../../libs/actions/EmojiPickerAction'; import getDraftComment from '../../../../libs/ComposerUtils/getDraftComment'; +import updatePropsPaperWorklet from '../../../../libs/updatePropsPaperWorklet'; const propTypes = { /** A method to call when the form is submitted */ @@ -314,6 +315,23 @@ function ReportActionCompose({ const isSendDisabled = isCommentEmpty || isBlockedFromConcierge || disabled || hasExceededMaxCommentLength; + const handleSendMessage = useCallback(() => { + 'worklet'; + + if (isSendDisabled) { + return; + } + + const viewTag = animatedRef(); + const viewName = 'RCTMultilineTextInputView'; + const updates = {text: ''}; + // We are setting the isCommentEmpty flag to true so the status of it will be in sync of the native text input state + runOnJS(setIsCommentEmpty)(true); + runOnJS(resetFullComposerSize)(); + updatePropsPaperWorklet(viewTag, viewName, updates); // clears native text input on the UI thread + runOnJS(submitForm)(); + }, [isSendDisabled, resetFullComposerSize, submitForm, animatedRef]); + return ( { - 'worklet'; - - const viewTag = animatedRef(); - const viewName = 'RCTMultilineTextInputView'; - const updates = {text: ''}; - // We are setting the isCommentEmpty flag to true so the status of it will be in sync of the native text input state - runOnJS(setIsCommentEmpty)(true); - runOnJS(resetFullComposerSize)(); - updatePropsPaperWorklet(viewTag, viewName, updates); // clears native text input on the UI thread - runOnJS(submitForm)(); + handleSendMessage(); }); return ( diff --git a/src/pages/home/report/ReportActionCompose/composerWithSuggestionsProps.js b/src/pages/home/report/ReportActionCompose/composerWithSuggestionsProps.js index 0c8f36114c44..017b5aecb4ae 100644 --- a/src/pages/home/report/ReportActionCompose/composerWithSuggestionsProps.js +++ b/src/pages/home/report/ReportActionCompose/composerWithSuggestionsProps.js @@ -72,7 +72,7 @@ const propTypes = { setIsCommentEmpty: PropTypes.func.isRequired, /** A method to call when the form is submitted */ - submitForm: PropTypes.func.isRequired, + handleSendMessage: PropTypes.func.isRequired, /** Whether the compose input is shown or not */ shouldShowComposeInput: PropTypes.bool.isRequired,