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

Make emojis larger when multiple are sent at the same time #8896

Merged
merged 13 commits into from
May 16, 2022

Conversation

eVoloshchak
Copy link
Contributor

@eVoloshchak eVoloshchak commented May 6, 2022

Details

Previously emojis in messages were larger than text only if you send message consisting of only one emoji. This PR ensures that if message consists only of emojis, they are displayed larger that text, regardless of the length.

Fixed Issues

#8867

Tests

  1. Send a message that contains only emojis
  2. Verify that emojis in this message are larger that the text (27pt)
  3. Send a message that contains both text and emojis
  4. Verify that emojis and text are small and have the same font size

PR Review Checklist

Contributor (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 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 included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team 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
  • 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 */
    • Any functional components have the displayName property
    • 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
  • 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.

PR Reviewer Checklist

  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 verified proper code patterns were followed (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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • 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
  • 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 */
    • Any functional components have the displayName property
    • 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 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.

QA Steps

  1. Send a message that contains only emojis
  2. Verify that emojis in this message are larger that the text (27pt)
  3. Send a message that contains both text and emojis
  4. Verify that emojis and text are small and have the same font size

Screenshots

Web

Screenshot from 2022-05-06 15-42-29

Mobile Web

Screenshot_20220506-154436

Desktop

I'm unable to launch the desktop app due to this bug. It is not present if you downgrade to certain node and npm versions, but since I use MacinCloud, I'm unable to do so. So if someone with a mac could test it and upload a video, I would highly appreciate it.

iOS

Simulator Screen Shot - iPod touch (7th generation) - 2022-05-06 at 18 57 20

Android

Screenshot_20220506-154621

src/libs/EmojiUtils.js Outdated Show resolved Hide resolved
@eVoloshchak
Copy link
Contributor Author

Updated

src/libs/EmojiUtils.js Outdated Show resolved Hide resolved
src/styles/styles.js Outdated Show resolved Hide resolved
@Santhosh-Sellavel
Copy link
Collaborator

Even if there are spaces in between Emojis should they be small?

@eVoloshchak @Julesssss

Screenshot 2022-05-10 at 9 57 09 PM

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented May 10, 2022

PR Reviewer Checklist

  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 verified proper code patterns were followed (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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • 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
  • 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 */
    • Any functional components have the displayName property
    • 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 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.

@Santhosh-Sellavel
Copy link
Collaborator

@eVoloshchak

I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)

Add failure steps i.e which is adding text along with emoji will make them smaller

@Julesssss
Copy link
Contributor

Even if there are spaces in between Emojis should they be small?

Hmm, nice edgecase! I missed that.

Part of me thinks that yes a space character could be an exception -- but it's a bit of a rabbit hole as I'm sure we could think of other exceptions too. Ultimately I don't think it matters too much either way

Julesssss
Julesssss previously approved these changes May 10, 2022
Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

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

Tested well for me on all platforms.

@Julesssss
Copy link
Contributor

CC @tgolen who may want to review, as you have essentially already reviewed

@Santhosh-Sellavel
Copy link
Collaborator

Even if there are spaces in between Emojis should they be small?

Hmm, nice edgecase! I missed that.

Part of me thinks that yes a space character could be an exception -- but it's a bit of a rabbit hole as I'm sure we could think of other exceptions too. Ultimately I don't think it matters too much either way

This could be plausible regressions just checking with you.

I could see only whitespaces and a newLine,

Screenshot 2022-05-10 at 10 08 17 PM

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

I left a few edge cases here #8896 (comment).

Otherwise Looks good & test's well for me!
cc: @Julesssss

Comment on lines 1046 to 1047
fontSize: variables.fontSizeSingleEmoji,
lineHeight: variables.fontSizeSingleEmojiHeight,
Copy link
Collaborator

Choose a reason for hiding this comment

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

NAB! these variables could be renamed too.

@Julesssss
Copy link
Contributor

Screenshot 2022-05-10 at 10 08 17 PM

On second thoughts, perhaps we should handle newline and space... Ignore my previous reasoning.

Finally, I see no nociable performance hit on a real/emulated Android device.

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

@eVoloshchak Can you handle these cases thanks! #8896 (comment)

@eVoloshchak
Copy link
Contributor Author

eVoloshchak commented May 10, 2022

@eVoloshchak Can you handle these cases thanks! [#8896 (comment)]

Thats a good catch
I've commited fix for emojis with spaces between them.

I have a solution for the case with line breaks, but would like your input on it before i push it:
Problem: when we have a line break between characters, there is a <br /> tag between them. That means that condition here is false (since fragment.text does not include html tags) and we RenderHTML rather than rendering Text, which means EmojiUtils.containsOnlyEmojis will never get called in this case.

Proposed solution:

  1. Determine if the only difference between fragment.text and fragment.html is a <br /> tag
  2. If if is, replace <br /> tag with line break ('/n')
  3. Assign newly created string to both fragment.text and fragment.html, since they are effectively the same
  4. Ignore line breaks in containsOnlyEmojis function

In practice, it means adding the following before this line:

  const differByLineBreaksOnly = props.fragment.html.replaceAll('<br />', ' ') === props.fragment.text;
  if (differByLineBreaksOnly) {
      props.fragment.text = props.fragment.html = props.fragment.html.replaceAll('<br />', '\n');
  }

What do you think?

@tgolen
Copy link
Contributor

tgolen commented May 10, 2022

I think I'm OK with that fix for the newlines. Nice that the whitespace idea was suggested.

tgolen
tgolen previously approved these changes May 12, 2022
Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

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

Thank you!

@tgolen
Copy link
Contributor

tgolen commented May 12, 2022

all you @Santhosh-Sellavel

@Santhosh-Sellavel
Copy link
Collaborator

Yeah will check this today.

Julesssss
Julesssss previously approved these changes May 12, 2022
Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

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

Re-approving. Tests well 👍

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

Just a small change can we clean this up, thanks!


// Emojis are stored as multiple characters, so we're using spread operator
// to iterate over the actual emojis, not just characters that compose them
const messageCodes = _.filter(_.map([...message.replace(/ /g, '').replaceAll('\n', '')],
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not DRY, message.replace(/ /g, '').replaceAll('\n', '') computing this twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not DRY, message.replace(/ /g, '').replaceAll('\n', '') computing this twice.

All done

@eVoloshchak eVoloshchak dismissed stale reviews from Julesssss and tgolen via 9c86b32 May 12, 2022 17:50
Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

Looks good to me, tests well!

cc: @tgolen @Julesssss

Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

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

Thanks all, looks good to me 👍

@Santhosh-Sellavel
Copy link
Collaborator

I think we are good to merge this cc: @tgolen

@tgolen tgolen merged commit 5c5f79b into Expensify:main May 16, 2022
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @tgolen in version: 1.1.61-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @AndrewGable in version: 1.1.61-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@marcaaron
Copy link
Contributor

Interesting FYI that these changes appear to be breaking mobile web for me on iOS simulator running iOS 13 - my device running iOS 15 is not affected. Pretty sure we are not tracking support for mobile web on all iOS versions so unsure if this counts as a "regression" - but gonna fix it.

@marcaaron
Copy link
Contributor

replaceAll() seems to not be available in Safari iOS 13.

@eVoloshchak
Copy link
Contributor Author

@marcaaron, that's a good catch, thank you!
replaceAll() is indeed unavailable on iOS 13.3 and below, so we can just use replace() with //g regex instead.
I submitted a PR that fixes this: #9063

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented May 18, 2022

@marcaaron I think we should capture this somewhere to avoid this happening again.

@marcaaron
Copy link
Contributor

Thanks, I'm working on a fix already so feel free to close your PR @eVoloshchak.

@marcaaron I think we should capture this somewhere to avoid this happening again.

One solution I can think of is to...

  1. Create a change in expensify-common Str.replaceAll() and use a polyfill there
  2. Enforce this method is used with a lint rule that prohibits using replaceAll() and prefers using Str.replaceAll()

@Santhosh-Sellavel
Copy link
Collaborator

One solution I can think of is to...

  1. Create a change in expensify-common Str.replaceAll() and use a polyfill there
  2. Enforce this method is used with a lint rule that prohibits using replaceAll() and prefers using Str.replaceAll()

Sounds good to me!

@luacmartins
Copy link
Contributor

Just stopping by to say that I saw the same error (replaceAll is not a function) on mWeb Chrome.

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.

7 participants