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: show main composer when there is no focused draft #23618

Merged
merged 12 commits into from
Jul 28, 2023

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,8 +74,6 @@ const defaultProps = {
};

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

Expand Down Expand Up @@ -202,8 +200,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 +279,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 +324,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) {
if (_.contains([messageEditInput, emojiButtonID], relatedTargetId)) {
return;
}
openReportActionComposeViewWhenClosingMessageEdit();
setShouldShowComposeInputKeyboardAware(true);
}}
selection={selection}
onSelectionChange={(e) => setSelection(e.nativeEvent.selection)}
Expand All @@ -348,8 +343,8 @@ function ReportActionItemMessageEdit(props) {
isDisabled={props.shouldDisableEmojiPicker}
onModalHide={() => InteractionManager.runAfterInteractions(() => textInputRef.current.focus())}
onEmojiSelected={addEmojiToTextBox}
nativeID={emojiButtonID}
reportAction={props.action}
nativeID={emojiButtonID}
/>
</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