Skip to content

fix: show main composer when there is no focused draft #23618

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

Merged
merged 12 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
8 changes: 4 additions & 4 deletions src/components/EmojiPicker/EmojiPickerButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const propTypes = {
/** Flag to disable the emoji picker button */
isDisabled: PropTypes.bool,

/** Id to use for the emoji picker button */
nativeID: PropTypes.string,
/** Mouse event handler */
onMouseDown: PropTypes.func,

/**
* ReportAction for EmojiPicker.
Expand All @@ -29,8 +29,8 @@ const propTypes = {

const defaultProps = {
isDisabled: false,
nativeID: '',
reportAction: {},
onMouseDown: undefined,
};

function EmojiPickerButton(props) {
Expand All @@ -43,8 +43,8 @@ function EmojiPickerButton(props) {
style={({hovered, pressed}) => [styles.chatItemEmojiButton, StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed))]}
disabled={props.isDisabled}
onPress={() => EmojiPickerAction.showEmojiPicker(props.onModalHide, props.onEmojiSelected, emojiPopoverAnchor, undefined, () => {}, props.reportAction)}
nativeID={props.nativeID}
accessibilityLabel={props.translate('reportActionCompose.emoji')}
onMouseDown={props.onMouseDown}
>
{({hovered, pressed}) => (
<Icon
Expand Down

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions src/libs/setShouldShowComposeInputKeyboardAware/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as Composer from '../actions/Composer';

export default (shouldShow) => {
Composer.setShouldShowComposeInput(shouldShow);
};
26 changes: 26 additions & 0 deletions src/libs/setShouldShowComposeInputKeyboardAware/index.native.js
Original file line number Diff line number Diff line change
@@ -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();
});
};
30 changes: 13 additions & 17 deletions src/pages/home/report/ReportActionItemMessageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -74,9 +74,6 @@ const defaultProps = {
};

// native ids
const saveButtonID = 'saveButton';
const cancelButtonID = 'cancelButton';
const emojiButtonID = 'emojiButton';
const messageEditInput = 'messageEditInput';

function ReportActionItemMessageEdit(props) {
Expand Down Expand Up @@ -202,8 +199,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) {
Expand Down Expand Up @@ -279,14 +278,15 @@ function ReportActionItemMessageEdit(props) {
<PressableWithFeedback
onPress={deleteDraft}
style={styles.chatItemSubmitButton}
nativeID={cancelButtonID}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
accessibilityLabel={translate('common.close')}
// disable dimming
hoverDimmingValue={1}
pressDimmingValue={1}
hoverStyle={StyleUtils.getButtonBackgroundColorStyle(CONST.BUTTON_STATES.ACTIVE)}
pressStyle={StyleUtils.getButtonBackgroundColorStyle(CONST.BUTTON_STATES.PRESSED)}
// Keep focus on the composer when cancel button is clicked.
onMouseDown={(e) => e.preventDefault()}
>
{({hovered, pressed}) => (
<Icon
Expand Down Expand Up @@ -323,21 +323,15 @@ function ReportActionItemMessageEdit(props) {
onFocus={() => {
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) {
return;
}
openReportActionComposeViewWhenClosingMessageEdit();
setShouldShowComposeInputKeyboardAware(true);
}}
selection={selection}
onSelectionChange={(e) => setSelection(e.nativeEvent.selection)}
Expand All @@ -348,8 +342,9 @@ function ReportActionItemMessageEdit(props) {
isDisabled={props.shouldDisableEmojiPicker}
onModalHide={() => InteractionManager.runAfterInteractions(() => textInputRef.current.focus())}
onEmojiSelected={addEmojiToTextBox}
nativeID={emojiButtonID}
reportAction={props.action}
// Keep focus on the composer when emoji picker button is clicked.
onMouseDown={(e) => e.preventDefault()}
/>
</View>

Expand All @@ -358,12 +353,13 @@ function ReportActionItemMessageEdit(props) {
<PressableWithFeedback
style={[styles.chatItemSubmitButton, hasExceededMaxCommentLength ? {} : styles.buttonSuccess]}
onPress={publishDraft}
nativeID={saveButtonID}
disabled={hasExceededMaxCommentLength}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
accessibilityLabel={translate('common.saveChanges')}
hoverDimmingValue={1}
pressDimmingValue={0.2}
// Keep focus on the composer when save button is clicked.
onMouseDown={(e) => e.preventDefault()}
>
<Icon
src={Expensicons.Checkmark}
Expand Down