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: Chat - App displays mention suggestion for sometime when we remove spaces before #29957

Merged
merged 7 commits into from
Oct 23, 2023
Merged
Changes from 5 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
11 changes: 10 additions & 1 deletion src/pages/home/report/ReportActionCompose/SuggestionMention.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as UserUtils from '../../../../libs/UserUtils';
import * as Expensicons from '../../../../components/Icon/Expensicons';
import * as SuggestionsUtils from '../../../../libs/SuggestionUtils';
import useLocalize from '../../../../hooks/useLocalize';
import usePrevious from '../../../../hooks/usePrevious';
import ONYXKEYS from '../../../../ONYXKEYS';
import personalDetailsPropType from '../../../personalDetailsPropType';
import * as SuggestionProps from './suggestionProps';
Expand Down Expand Up @@ -56,6 +57,7 @@ function SuggestionMention({
measureParentContainer,
}) {
const {translate} = useLocalize();
const previousValue = usePrevious(value);
const [suggestionValues, setSuggestionValues] = useState(defaultSuggestionsValues);

const isMentionSuggestionsMenuVisible = !_.isEmpty(suggestionValues.suggestedMentions) && suggestionValues.shouldShowSuggestionMenu;
Expand Down Expand Up @@ -233,8 +235,15 @@ function SuggestionMention({
);

useEffect(() => {
if (value.length < previousValue.length) {
// A workaround to not show the suggestions list when the user deletes a character before the mention.
// It is caused by a buggy behavior of the TextInput on iOS. Should be fixed after migration to the Fabric Arc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arc -> Arch (or just "Fabric")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arc:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ark:

image

// See: https://github.com/facebook/react-native/pull/36930#issuecomment-1593028467
return;
}

calculateMentionSuggestion(selection.end);
}, [selection, calculateMentionSuggestion]);
}, [selection, value, previousValue, calculateMentionSuggestion]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both value and previousValue are necessary, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would omit both values from dependencies, but in that case, we get a lint error – it requires both to be present

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sure. The truth is that we opt-out quite often from that lint... In this case I would go whichever path is less likely to create another regression...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you @cubuspl42, we should follow the path that is less likely to create another regression.


const updateShouldShowSuggestionMenuToFalse = useCallback(() => {
setSuggestionValues((prevState) => {
Expand Down
Loading