Skip to content

Commit

Permalink
fix expand button disappear after clicking send
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanDylann committed Oct 3, 2023
1 parent ee81a28 commit 49ad7e7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function ComposerWithSuggestions({
isFullComposerAvailable,
setIsFullComposerAvailable,
setIsCommentEmpty,
submitForm,
handleSendMessage,
shouldShowComposeInput,
measureParentContainer,
// Refs
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
27 changes: 21 additions & 6 deletions src/pages/home/report/ReportActionCompose/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 (
<View
ref={containerRef}
Expand Down Expand Up @@ -381,7 +399,7 @@ function ReportActionCompose({
isFullComposerAvailable={isFullComposerAvailable}
setIsFullComposerAvailable={setIsFullComposerAvailable}
setIsCommentEmpty={setIsCommentEmpty}
submitForm={submitForm}
handleSendMessage={handleSendMessage}
shouldShowComposeInput={shouldShowComposeInput}
onFocus={onFocus}
onBlur={onBlur}
Expand Down Expand Up @@ -409,10 +427,7 @@ function ReportActionCompose({
)}
<SendButton
isDisabled={isSendDisabled}
setIsCommentEmpty={setIsCommentEmpty}
resetFullComposerSize={resetFullComposerSize}
submitForm={submitForm}
animatedRef={animatedRef}
handleSendMessage={handleSendMessage}
/>
</View>
<View
Expand Down
26 changes: 4 additions & 22 deletions src/pages/home/report/ReportActionCompose/SendButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,17 @@ const propTypes = {
/** Whether the button is disabled */
isDisabled: PropTypes.bool.isRequired,

/** Reference to the animated view */
animatedRef: PropTypes.func.isRequired,

/** Sets the isCommentEmpty flag to true */
setIsCommentEmpty: PropTypes.func.isRequired,

/** resets the composer to normal size */
resetFullComposerSize: PropTypes.func.isRequired,

/** Submits the form */
submitForm: PropTypes.func.isRequired,
/** Handle clicking on send button */
handleSendMessage: PropTypes.func.isRequired,
};

function SendButton({isDisabled: isDisabledProp, animatedRef, setIsCommentEmpty, resetFullComposerSize, submitForm}) {
function SendButton({isDisabled: isDisabledProp, handleSendMessage}) {
const {translate} = useLocalize();

const Tap = Gesture.Tap()
.enabled()
.onEnd(() => {
'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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 49ad7e7

Please sign in to comment.