Skip to content

Commit

Permalink
Merge pull request #19541 from therealsujitk/fix-18992
Browse files Browse the repository at this point in the history
Hide mention suggestions while opening file picker
  • Loading branch information
pecanoro authored Jun 1, 2023
2 parents 5ff32c3 + 495d715 commit edf9b18
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ class ReportActionCompose extends React.Component {
this.updateNumberOfLines = this.updateNumberOfLines.bind(this);
this.showPopoverMenu = this.showPopoverMenu.bind(this);
this.comment = props.comment;
this.setShouldBlockEmojiCalcToFalse = this.setShouldBlockEmojiCalcToFalse.bind(this);

// React Native will retain focus on an input for native devices but web/mWeb behave differently so we have some focus management
// code that will refocus the compose input after a user closes a modal or some other actions, see usage of ReportActionComposeFocusManager
Expand All @@ -195,6 +194,10 @@ class ReportActionCompose extends React.Component {

this.shouldAutoFocus = !props.modal.isVisible && (this.shouldFocusInputOnScreenFocus || this.isEmptyChat()) && props.shouldShowComposeInput;

// These variables are used to decide whether to block the suggestions list from showing to prevent flickering
this.shouldBlockEmojiCalc = false;
this.shouldBlockMentionCalc = false;

// For mobile Safari, updating the selection prop on an unfocused input will cause it to automatically gain focus
// and subsequent programmatic focus shifts (e.g., modal focus trap) to show the blue frame (:focus-visible style),
// so we need to ensure that it is only updated after focus.
Expand Down Expand Up @@ -285,6 +288,8 @@ class ReportActionCompose extends React.Component {
this.setState({selection: e.nativeEvent.selection});
if (!this.state.value || e.nativeEvent.selection.end < 1) {
this.resetSuggestions();
this.shouldBlockEmojiCalc = false;
this.shouldBlockMentionCalc = false;
return;
}
this.calculateEmojiSuggestion();
Expand Down Expand Up @@ -423,13 +428,6 @@ class ReportActionCompose extends React.Component {
}
}

// eslint-disable-next-line rulesdir/prefer-early-return
setShouldBlockEmojiCalcToFalse() {
if (this.state && this.state.shouldBlockEmojiCalc) {
this.setState({shouldBlockEmojiCalc: false});
}
}

/**
* Determines if we can show the task option
* @param {Array} reportParticipants
Expand Down Expand Up @@ -513,10 +511,11 @@ class ReportActionCompose extends React.Component {
* Calculates and cares about the content of an Emoji Suggester
*/
calculateEmojiSuggestion() {
if (this.state.shouldBlockEmojiCalc) {
this.setState({shouldBlockEmojiCalc: false});
if (this.shouldBlockEmojiCalc) {
this.shouldBlockEmojiCalc = false;
return;
}

const leftString = this.state.value.substring(0, this.state.selection.end);
const colonIndex = leftString.lastIndexOf(':');
const isCurrentlyShowingEmojiSuggestion = this.isEmojiCode(this.state.value, this.state.selection.end);
Expand All @@ -543,6 +542,11 @@ class ReportActionCompose extends React.Component {
}

calculateMentionSuggestion() {
if (this.shouldBlockMentionCalc) {
this.shouldBlockMentionCalc = false;
return;
}

const valueAfterTheCursor = this.state.value.substring(this.state.selection.end);
const indexOfFirstWhitespaceCharOrEmojiAfterTheCursor = valueAfterTheCursor.search(CONST.REGEX.SPECIAL_CHAR_OR_EMOJI);

Expand Down Expand Up @@ -944,7 +948,8 @@ class ReportActionCompose extends React.Component {
onConfirm={this.addAttachment}
onModalShow={() => this.setState({isAttachmentPreviewActive: true})}
onModalHide={() => {
this.setShouldBlockEmojiCalcToFalse();
this.shouldBlockEmojiCalc = false;
this.shouldBlockMentionCalc = false;
this.setState({isAttachmentPreviewActive: false});
}}
>
Expand Down Expand Up @@ -1025,10 +1030,11 @@ class ReportActionCompose extends React.Component {
icon: Expensicons.Paperclip,
text: this.props.translate('reportActionCompose.addAttachment'),
onSelected: () => {
// Set a flag to block emoji calculation until we're finished using the file picker,
// Set a flag to block suggestion calculation until we're finished using the file picker,
// which will stop any flickering as the file picker opens on non-native devices.
if (this.willBlurTextInputOnTapOutside) {
this.setState({shouldBlockEmojiCalc: true});
this.shouldBlockEmojiCalc = true;
this.shouldBlockMentionCalc = true;
}

openPicker({
Expand Down Expand Up @@ -1082,7 +1088,10 @@ class ReportActionCompose extends React.Component {
this.setIsFocused(false);
this.resetSuggestions();
}}
onClick={this.setShouldBlockEmojiCalcToFalse}
onClick={() => {
this.shouldBlockEmojiCalc = false;
this.shouldBlockMentionCalc = false;
}}
onPasteFile={displayFileInModal}
shouldClear={this.state.textInputShouldClear}
onClear={() => this.setTextInputShouldClear(false)}
Expand Down

0 comments on commit edf9b18

Please sign in to comment.