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

Static emoji autosuggestion #14686

Conversation

perunt
Copy link
Contributor

@perunt perunt commented Jan 31, 2023

Details

Sets up an emojicode autosuggestion UI.

Fixed Issues

$ #12188

Tests

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Condition: You are in the chat screen and the text input is focused with the keyboard expanded

Mobile:

  1. Enter :s in an empty text input.

  2. Observe that there is no suggestion.

  3. Add 'm' to the text input so it contains :sm.

  4. Verify that the Emoji suggester appears above the text input.

  5. Tap on any of the suggested emojis.

  6. Verify that :sm is replaced with the selected emoji.

  7. Enter some text in the text input.

  8. Add a space or create a new line.

  9. Expand the input

  10. Enter a colon followed by two letters that correspond to the name of the desired emoji (e.g. smile -> :sm, flag -> :fl).

  11. Verify that the Emoji suggester appears above the text input.

  12. Tap on one of the suggested emojis.

  13. Verify that the text (e.g. :sm, :fl, etc.) is replaced with the selected emoji.

WEB/Desktop:

  1. Enter :s in an empty text input.
  2. Observe that there is no suggestion.
  3. Add 'm' to the text input so it contains :sm.
  4. Verify that the Emoji suggester appears above the text input.
  5. Use the arrow keys to switch between suggested emojis.
  6. Select a suggested emoji by either tapping on it or pressing Enter if you are using the arrow keys.
  7. Verify that :sm is replaced with the selected emoji.

Note: The suggestion will only appear if you enter a colon followed by two letters without any spaces in between. Before the colon, there should be either a space, a line break, or the input should be the first word in the text field. (So, the following values would not trigger the suggestion::s, : sm, :s m, sm:sm)
Emoji suggestions could contain up to 5 items. Is a screen small we show a height of 2.5 items and you can scroll this box.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Jan-31-2023.22-22-38.mp4
Mobile Web - Chrome
Feb-12-2023.19-06-12.mp4
Mobile Web - Safari
Feb-12-2023.19-06-34.mp4
Desktop
Jan-31-2023.22-28-10.mp4
iOS
Jan-31-2023.22-02-45.mp4
Android
Jan-31-2023.22-13-56.mp4

@github-actions
Copy link
Contributor

github-actions bot commented Jan 31, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@perunt perunt marked this pull request as ready for review February 3, 2023 13:52
@perunt perunt requested a review from a team as a code owner February 3, 2023 13:52
@melvin-bot melvin-bot bot requested review from Beamanator and removed request for a team February 3, 2023 13:52
@melvin-bot
Copy link

melvin-bot bot commented Feb 3, 2023

@Beamanator Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@stitesExpensify
Copy link
Contributor

I'll review this first thing on Monday

src/components/EmojiSuggestions/index.js Outdated Show resolved Hide resolved
src/components/EmojiSuggestions/index.js Outdated Show resolved Hide resolved
src/components/EmojiSuggestions/index.js Outdated Show resolved Hide resolved
src/components/EmojiSuggestions/index.js Outdated Show resolved Hide resolved
src/components/EmojiSuggestions/index.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
@roryabraham

This comment was marked as resolved.

@perunt
Copy link
Contributor Author

perunt commented Feb 6, 2023

I have read the CLA Document and I hereby sign the CLA

@perunt perunt requested review from roryabraham and removed request for stitesExpensify and Beamanator February 6, 2023 14:27
@roryabraham
Copy link
Contributor

@perunt This PR will still be unmergable because it contains these older unsigned commits:

image

@perunt perunt force-pushed the feature/@perunt/emoji-autosuggestion-static branch from da3e291 to fc4b0c9 Compare February 7, 2023 11:45
@roryabraham
Copy link
Contributor

roryabraham commented Feb 8, 2023

@perunt this commit will be a problem (gpg signature needs to be verified by GitHub):

image

src/components/EmojiSuggestions/index.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
@perunt perunt force-pushed the feature/@perunt/emoji-autosuggestion-static branch 6 times, most recently from ae3f1b7 to 69ec073 Compare February 9, 2023 17:27
Copy link
Contributor

@roryabraham roryabraham left a comment

Choose a reason for hiding this comment

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

Overall this is looking much better to me

const newComment = this.comment.slice(0, this.state.selection.start)
+ emoji + this.comment.slice(this.state.selection.end, this.comment.length);
+ emojiWithSpace
Copy link
Contributor

Choose a reason for hiding this comment

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

It does not look like this change was made. Maybe you need to disable prettier?

src/pages/home/report/ReportActionCompose.js Outdated Show resolved Hide resolved
@roryabraham
Copy link
Contributor

@mananjadhav tagging you for review since you're the C+ on the linked issue: #12188

@mananjadhav
Copy link
Collaborator

I am tagging this PR to highlight an issue fixed here. All conditions in ternary expressions or left-hand operands on conditional renders, should be boolean. This PR is one of the PRs that uses conditional render with string operands, hence I am tagging it here for the contributors to check.

We've also updated the item in the checklist with this PR to avoid this issue in the future.

@sobitneupane
Copy link
Contributor

Hello everyone, this PR introduced a bug #16730 where for newly created chat (being offline), auto-suggestion modal is transparent. This issue was fixed by this PR. It is an edge case and can be easily missed.

@Santhosh-Sellavel
Copy link
Collaborator

Hi Everyone we missed handling a case here which lead to this issue #16626. IMO we could have caught this if considered testing other possible scenarios.

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented May 3, 2023

Hi everyone, This PR accidentally revert changes made here #13875 which lead to cause this issue #15951 For more context here

hovered,
index,
)}
onMouseDown={e => e.preventDefault()}
Copy link
Member

Choose a reason for hiding this comment

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

Hi! I'm coming from #16485

onMouseDown={e => e.preventDefault()} prevents the focus from moving and the keyboard from closing. But unfortunately, when we long press the emoji element, the mousedown event is not fired on mWeb Android.

Causing the bug - #16485

The mWeb Android behavior is well demonstrated here.

@sobitneupane
Copy link
Contributor

Hello everyone, Looks like we missed to handle this issue while implementing the feature.

Issue: #16977
Title: The Emoji suggestion is flickered when adding attachment
Steps To reproduce:

  • Open any chat
  • Enter :smi and observe the emoji suggestion appears
  • Click + button on the left of composer
  • Click on Add Attachment and observe that the emoji suggestion re-appear for a moment

@Santhosh-Sellavel
Copy link
Collaborator

Hello everyone this PR caused a console error. More details here

@mollfpr
Copy link
Contributor

mollfpr commented May 22, 2023

HIYA! Coming from #18793

This PR causes a crash upon searching the mention back to back; complete step here.

The root cause of the crash is that the LayoutAnimation is being called (here) after the state update is triggered (here). At the end of this function, we're doing another state update. These together cause the crash.

const commentBeforeColon = this.state.value.slice(0, this.state.colonIndex);
const emojiObject = this.state.suggestedEmojis[highlightedEmojiIndex];
const emojiCode = emojiObject.types && emojiObject.types[this.props.preferredSkinTone] ? emojiObject.types[this.props.preferredSkinTone] : emojiObject.code;
const commentAfterColonWithEmojiNameRemoved = this.state.value.slice(this.state.selection.end).replace(CONST.REGEX.EMOJI_REPLACER, CONST.SPACE);
Copy link
Contributor

@s77rt s77rt Jun 1, 2023

Choose a reason for hiding this comment

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

@perunt Is there a specific reason why we are replacing text after colon with a space? (Coming from #19289)

@@ -1003,6 +1021,8 @@ const CONST = {
CHAT_ATTACHMENT_TOKEN_KEY: 'X-Chat-Attachment-Token',

USA_COUNTRY_NAME,
SPACE_LENGTH: 1,
SPACE: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

This caused a regression #19289. In our world SPACE is still and not 1 😅.

Copy link
Contributor

Choose a reason for hiding this comment

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

whoooops 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄

@mollfpr
Copy link
Contributor

mollfpr commented Jun 9, 2023

Coming from #18112

In the above issue, on Android scrolling on the emoji suggestion will scroll the report action list.

Instead of setting height directly on FlatList, apply height to the parent View component. Also set flex:1 to FlatList. This fixes the scroll issue with nested Flatlist and prevents the chat list from scrolling instead.

nextState.shouldShowSuggestionMenu = !_.isEmpty(newSuggestedEmojis);
}

LayoutAnimation.configureNext(LayoutAnimation.create(50, LayoutAnimation.Types.easeInEaseOut, LayoutAnimation.Properties.opacity));
Copy link
Member

Choose a reason for hiding this comment

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

Why did we add this LayoutAnimation @perunt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was added to show a suggestion box. I just checked the code and noticed we introduced an animatedValue to control it. So, I think we can just remove LayoutAnimation

Comment on lines +190 to +193
emojiSuggestionsText: {
fontFamily: fontFamily.EMOJI_TEXT_FONT,
fontSize: variables.fontSizeMedium,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

This caused an issue when emoji text became too long. We should have allowed word breaking here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for let us know.

@@ -582,6 +704,7 @@ class ReportActionCompose extends React.Component {
<TouchableOpacity
onPress={(e) => {
e.preventDefault();
this.setShouldShowSuggestionMenuToFalse();
Copy link
Member

@parasharrajat parasharrajat Dec 11, 2023

Choose a reason for hiding this comment

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

Why did we close the suggestions on Expand/Collapse cc: @mananjadhav @perunt?

Copy link
Member

Choose a reason for hiding this comment

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

Would love to hear your opinion @mananjadhav @perunt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's tough to remember all the details, but the first thing that comes to mind is that we adopted this feature from other messengers. We can definitely keep it displayed

const prefixLocation = name.search(prefix);

if (prefixLocation === 0 && prefix.length === name.length) {
texts.push({text: prefix, isColored: true});
Copy link
Contributor

Choose a reason for hiding this comment

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

text should be name instead of prefix.
Later, this caused minor regression - #32749

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.