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/27779: Expand button disappear after clicking send #28681

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
2 changes: 1 addition & 1 deletion src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ function ReportScreen({
policies={policies}
/>
) : (
<ReportFooter shouldDisableCompose />
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
<ReportFooter isReportReadyForDisplay={false} />
)}
</View>
</DragAndDropProvider>
Expand Down
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
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 @@ -72,6 +73,8 @@ const propTypes = {
/** The type of action that's pending */
pendingAction: PropTypes.oneOf(['add', 'update', 'delete']),

/** /** Whetjer the report is ready for display */
isReportReadyForDisplay: PropTypes.bool,
...withCurrentUserPersonalDetailsPropTypes,
};

Expand All @@ -83,6 +86,7 @@ const defaultProps = {
isComposerFullSize: false,
pendingAction: null,
shouldShowComposeInput: true,
isReportReadyForDisplay: true,
...withCurrentUserPersonalDetailsDefaultProps,
};

Expand All @@ -105,6 +109,7 @@ function ReportActionCompose({
reportID,
reportActions,
shouldShowComposeInput,
isReportReadyForDisplay,
}) {
const {translate} = useLocalize();
const {isMediumScreenWidth, isSmallScreenWidth} = useWindowDimensions();
Expand Down Expand Up @@ -314,6 +319,23 @@ function ReportActionCompose({

const isSendDisabled = isCommentEmpty || isBlockedFromConcierge || disabled || hasExceededMaxCommentLength;

const handleSendMessage = useCallback(() => {
'worklet';

if (isSendDisabled || !isReportReadyForDisplay) {
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, isReportReadyForDisplay]);

return (
<View
ref={containerRef}
Expand Down Expand Up @@ -381,7 +403,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 +431,7 @@ function ReportActionCompose({
)}
<SendButton
isDisabled={isSendDisabled}
setIsCommentEmpty={setIsCommentEmpty}
resetFullComposerSize={resetFullComposerSize}
submitForm={submitForm}
animatedRef={animatedRef}
handleSendMessage={handleSendMessage}
/>
</View>
<View
Expand Down
28 changes: 4 additions & 24 deletions src/pages/home/report/ReportActionCompose/SendButton.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import {View} from 'react-native';
import {runOnJS} from 'react-native-reanimated';
import {Gesture, GestureDetector} from 'react-native-gesture-handler';
import PropTypes from 'prop-types';
import styles from '../../../../styles/styles';
Expand All @@ -10,42 +9,23 @@ import * as Expensicons from '../../../../components/Icon/Expensicons';
import CONST from '../../../../CONST';
import Tooltip from '../../../../components/Tooltip';
import PressableWithFeedback from '../../../../components/Pressable/PressableWithFeedback';
import updatePropsPaperWorklet from '../../../../libs/updatePropsPaperWorklet';
import useLocalize from '../../../../hooks/useLocalize';

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
5 changes: 5 additions & 0 deletions src/pages/home/report/ReportFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const propTypes = {
/** Whether user interactions should be disabled */
shouldDisableCompose: PropTypes.bool,

/** Whetjer the report is ready for display */
isReportReadyForDisplay: PropTypes.bool,

...windowDimensionsPropTypes,
};

Expand All @@ -48,6 +51,7 @@ const defaultProps = {
pendingAction: null,
shouldShowComposeInput: true,
shouldDisableCompose: false,
isReportReadyForDisplay: true,
};

function ReportFooter(props) {
Expand Down Expand Up @@ -86,6 +90,7 @@ function ReportFooter(props) {
pendingAction={props.pendingAction}
isComposerFullSize={props.isComposerFullSize}
disabled={props.shouldDisableCompose}
isReportReadyForDisplay={props.isReportReadyForDisplay}
/>
</SwipeableView>
</View>
Expand Down