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/make-emojis-larger-in-other-message-contexts #15611

Conversation

josemak25
Copy link

@josemak25 josemak25 commented Mar 2, 2023

HOLD on facebook/hermes#932

Details

This solution covers several related scenarios:

Scenario 1

Action Performed:

Add an emoji with other plain text characters in a message in the composer.

Expected Result:

The emoji should be larger (19pt) compared to the default size for text (15pt) in the composer. The emoji and text should appear vertically centered with respect to each other, such that the baseline of the emoji is below the plain text and the middle of the text vertically aligns with the middle of the emoji (like the right-hand-side of #4114 (comment).

Solution does not cover this case as handling emojis inside the input is a bit tricky

Scenario 2

Action Performed:

Send a message with emojis and text.

Expected Result:

The emoji should be larger (19pt) compared to the default size for text (15pt) in the chat history. The emoji and text should appear vertically centered with respect to each other, such that the baseline of the emoji is below the plain text and the middle of the text vertically aligns with the middle of the emoji (like the right-hand-side of #4114 (comment)

Solution covers this case

Scenario 3

Action Performed

Draft a message (of any length) with only an emoji.

Expected Result:

The emoji should appear very large (27pt) in the composer.

Solution does not cover this case as handling emojis inside the input is a bit tricky

Scenario 4

Action Performed

Send a message (of any length) with only emoji.

Expected Result:

The emoji should appear very large (27pt) in the report history.

Solution covers this case

Scenario 5

Action Performed

Go to Settings -> Profile and add emoji(s) to your last name 😎

Expected Result:

The emoji should appear larger (19pt) than the rest of the text (15pt) in the text input. The emoji and text should appear vertically centered with respect to each other, such that the baseline of the emoji is below the plain text and the middle of the text vertically aligns with the middle of the emoji (like the right-hand-side of #4114 (comment)

Solution does not cover this case as handling emojis inside the input is a bit tricky

Scenario 6

Action Performed

  1. Go to Settings -> Profile and add emoji(s) to your last name 😎.
  2. Save your profile.
  3. Open the Settings RHP and look at your name:

Expected Result:

The emoji should appear larger (21pt) than the rest of the text (17pt) in the text input. The emoji and text should appear vertically centered with respect to each other, such that the baseline of the emoji is below the plain text and the middle of the text vertically aligns with the middle of the emoji (like the right-hand-side of #4114 (comment)

Solution covers this case

Scenario 7

Action Performed

  1. Go to Settings -> Profile and add emoji(s) to your last name 😎.
  2. Save your profile.
  3. Open a chat with another user and send them a message. Take a look at your message in the report history.

Expected Result:

The emoji should appear larger (19pt) than the rest of the test (15pt). The emoji and text should appear vertically centered with respect to each other, such that the baseline of the emoji is below the plain text and the middle of the text vertically aligns with the middle of the emoji (like the right-hand-side of #4114 (comment)

Solution covers this case

Fixed Issues

PROPOSAL: #4114

Tests

  1. The emoji and text should appear vertically centered with respect to each other, such that the baseline of the emoji is below the plain text and the middle of the text vertically aligns with the middle of the emoji
  2. Draft a message (of any length) with only emoji the emoji should appear very large (27pt) in the composer.
  3. Go to Settings -> Profile and add emoji(s)[😎] to your last name or first name and save your profile. now open the settings RHP and look at your name, the emoji appear to be bigger in size than the text.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. The emoji and text should appear vertically centered with respect to each other, such that the baseline of the emoji is below the plain text and the middle of the text vertically aligns with the middle of the emoji
  2. Draft a message (of any length) with only emoji the emoji should appear very large (27pt) in the composer.
  3. Go to Settings -> Profile and add emoji(s)[😎] to your last name or first name and save your profile. now open the settings RHP and look at your name, the emoji appear to be bigger in size than the text.
  • 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
      • 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

Chrome Web
Chrome.Web.Recording.mov
Safari Web
Safari.Web.Recording.mov
Mobile Web - Chrome
Mobile.Web.-.Chrome.mov
Mobile Web - Safari
Mobile.Web.-.Safari.mp4
Desktop
Desktop.mov
iOS
iOS.mp4
Android
Android.mov

@josemak25 josemak25 requested a review from a team as a code owner March 2, 2023 17:43
@melvin-bot melvin-bot bot requested review from parasharrajat and roryabraham and removed request for a team March 2, 2023 17:43
@MelvinBot
Copy link

@roryabraham @parasharrajat One of you needs to 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]

src/components/TextEmoji.js Outdated Show resolved Hide resolved
src/styles/styles/index.js Outdated Show resolved Hide resolved
src/styles/variables/index.js Outdated Show resolved Hide resolved
src/styles/styles/styles.android.js Outdated Show resolved Hide resolved
},
};

export default {...baseStyles, ...styles};
Copy link
Contributor

Choose a reason for hiding this comment

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

Since baseStyles is a very large object and shouldn't be imported anywhere else, I'd recommend using Object.assign for better performance:

export default Object.assign(baseStyles, styles);

Copy link
Author

Choose a reason for hiding this comment

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

Yea I used lodash assign method as required by the app standards

 export default _.assign(baseStyles, styles);

Copy link
Contributor

Choose a reason for hiding this comment

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

did you forget to push this change?

src/styles/styles/styles.ios.js Outdated Show resolved Hide resolved
},
};

export default {...baseStyles, ...styles};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export default {...baseStyles, ...styles};
export default Object.assign(baseStyles, styles);

Copy link
Author

Choose a reason for hiding this comment

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

Yea I used lodash assign method as required by the app standards

 export default _.assign(baseStyles, styles);

src/components/TextEmoji.js Outdated Show resolved Hide resolved
return false;
}
const trimmedMessage = Str.replaceAll(message.replace(/ /g, ''), '\n', '');
return Boolean(trimmedMessage.match(CONST.REGEX.EMOJIS));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return Boolean(trimmedMessage.match(CONST.REGEX.EMOJIS));
return CONST.REGEX.EMOJIS.test(trimmedMessage);

@@ -806,6 +806,7 @@ const CONST = {

// eslint-disable-next-line max-len, no-misleading-character-class
EMOJIS: /[\p{Extended_Pictographic}\u200d\u{1f1e6}-\u{1f1ff}\u{1f3fb}-\u{1f3ff}\u{e0020}-\u{e007f}\u20E3\uFE0F]|[#*0-9]\uFE0F?\u20E3/gu,
EMOJI_SURROGATE: /(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain what this regex represents? I was not able to figure it out

Copy link
Author

Choose a reason for hiding this comment

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

From the algorithm, we were expected to capture emojis in a text, though while doing this we need to be careful when we capture emojis that are surrogate pairs.
Surrogate pair Emojis are emojis that can be made up of multiple values that are overlayed on each other to get the final displayed representation.
An example of this is the cloud face emoji made up of 2 different emoji (face emoji and cloud emoji) combined together.
If we split the cloud face emoji we would end up with both separate emojis, so from our algorithm, we need to identify these sorts of surrogate pairs and have them combined back together to maintain the original emoji

Screenshot 2023-03-03 at 6 58 45 PM

Read more on surrogate pair characters

Copy link
Contributor

@roryabraham roryabraham Mar 3, 2023

Choose a reason for hiding this comment

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

Awesome, thanks for that explanation.

Maybe what we should do then is:

  1. Update the emoji regex to capture chunks of 1 or more emojis
  2. For each chunk containing emojis, use the emoji surrogate regex to capture and "squash" surrogate pairs

Copy link
Contributor

Choose a reason for hiding this comment

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

Also we should include some comments to explain what this regex is about

Copy link
Author

Choose a reason for hiding this comment

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

@roryabraham

  1. Update the emoji regex to capture chunks of 1 or more emojis
    • How do I do this from your implementation?

Copy link
Author

@josemak25 josemak25 Mar 6, 2023

Choose a reason for hiding this comment

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

the d flag works for the web but not on android and ios platforms as they both crash

Have logs for this crash? Could this be because the d flag is not implemented in the Hermes JS engine, or something else?

Edit: Yep, it seems that the hasIndices flag is not implemented in Hermes: https://github.com/facebook/hermes/blob/417190297242f14fed540378390d28926c2a7f7e/include/hermes/Regex/RegexTypes.h#L213-L343. Shoot ... did not see that coming.

Edit 2: Created facebook/hermes#932, but we need to decide if we should HOLD this PR on that or not

@roryabraham @parasharrajat

the d flag works for the web but not on android and ios platforms as they both crash

Have logs for this crash? Could this be because the d flag is not implemented in the Hermes JS engine, or something else?

Edit: Yep, it seems that the hasIndices flag is not implemented in Hermes: https://github.com/facebook/hermes/blob/417190297242f14fed540378390d28926c2a7f7e/include/hermes/Regex/RegexTypes.h#L213-L343. Shoot ... did not see that coming.

Edit 2: Created facebook/hermes#932, but we need to decide if we should HOLD this PR on that or not

@roryabraham @parasharrajat this would prolong this task by extra few days should we try to fix this regex issue.
I would suggest we go with the former implementation which worked perfectly avoiding the need for this regex d fix also if it helps I would put a comment on it explaining every step of the algorithm and also remove all the other functions that aren't needed.

/**
 * Get all the emojis in the message
 * @param {String} text
 * @returns {Array}
 */
function getAllEmojiFromText(text) {
    // return an empty array when no text is passed
    if (!text) {
        return [];
    }

    // Unicode Character 'ZERO WIDTH JOINER' (U+200D) is usually used to join surrogate pair together without breaking the emoji
    const zeroWidthJoiner = '\u200D'; // https://codepoints.net/U+200D?lang=en
    const splittedMessage = text.split('');
    const result = [];

    let wordHolder = ''; // word counter
    let emojiHolder = ''; // emoji counter

    const setResult = (word, isEmoji = false) => {
        // for some weird reason javascript sees the empty string `"` as a word with `length = 1`
        // this is caused after splitting the text empty spaces are added to both the start and the end of all emojis and text
        // given the empty space is close to a text then its length is counted as 0
        // while if it's before or after an emoji then it's counted as 1, so we remove the word where word.length equals 1
        // NOTE: this does not affect a single character element example typing `[i | J]` cause after splitting its empty word.length is calculated as 0
        if (!isEmoji && word.length === 1) {
            return;
        }

        result.push({text: word, isEmoji});
    };

    _.forEach(splittedMessage, (word, index) => {
        if (CONST.REGEX.EMOJI_SURROGATE.test(word) || word === zeroWidthJoiner) {
            setResult(wordHolder);
            wordHolder = '';
            emojiHolder += word;
        } else {
            setResult(emojiHolder, true);
            emojiHolder = '';
            wordHolder += word;
        }

        if (index === splittedMessage.length - 1) {
            setResult(emojiHolder, true);
            setResult(wordHolder);
        }
    });

    // remove none text characters like '' only return where text is a word or white space ' '
    return _.filter(result, res => res.text);
}


/**
 * Validates that this message contains has emojis
 *
 * @param {String} message
 * @returns {Boolean}
 */
function hasEmojis(message) {
    const splitText = getAllEmojiFromText(message);
    return _.find(splitText, chunk => chunk.isEmoji) !== undefined;
}

/**
 * Validates that this message contains only emojis
 *
 * @param {String} message
 * @returns {Boolean}
 */
function containsOnlyEmojis(message) {
    const splitText = getAllEmojiFromText(message);
    return _.every(splitText, chunk => chunk.isEmoji);
}

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.

There are a number of other changes I want to see included in this PR.

Unit Test Coverage

EmojiUtils desperately needs some unit test coverage. That's almost always a good idea when we are dealing with complex regexes. Furthermore, it's probably a good place to start to establish a baseline before making the other changes listed here.

Unused Method

Next, I noticed that EmojiUtils.trimEmojiUnicode is unused, so we should remove it

Refactoring EmojiUtils

Third, I noticed some inefficiencies and unnecessarily complex code in the following three methods:

  1. containsOnlyEmoji
  2. hasEmojis
  3. getAllEmojisFromText

I think we should refactor these methods such that the string is only traversed by a regex exactly once when any one of the three methods is called.

I've done some research, and I think this should be possible in a few steps.

Step 1

Refactor CONST.REGEX.EMOJIS such that it will match not just a single emoji at a time, but 1 or more. This means that if we have an input string like so:

Hello world 🙂🙂🙂 what a great day ☀️

const input = 'Hello world U+1F600U+1F600U+1F600 what a great day U+2600';

then we do this:

input.split(CONST.REGEX.EMOJIS);

We would get a result like this:

['Hello world ', ':slightly_smiling_face::slightly_smiling_face::slightly_smiling_face:', ' what a great day ', ':sunny:']

result = ['Hello world ', 'U+1F600U+1F600U+1F600', ' what a great day ', 'U+2600']

Furthermore, it should ignore whitespace or 0-length characters if they are surrounded by emoji. So doing a split on this input:

const input = 'Hello world U+1F600     U+1F600     U+1F600 what a great day U+2600'

would produce this output:

result = ['Hello world ', 'U+1F600     U+1F600     U+1F600', ' what a great day ', 'U+2600']

Step 2

  1. Add the d flag to CONST.REGEX.EMOJIS such that the result of a regular expression match should contain the start and end indices of the substrings of each capture group.
  2. Wrap the regex in a capture group such that the chunks of 1 or more potentially-whitespace-separated emojis are captured.

Step 3

Refactor EmojiUtils.getAllEmojisFromText so that it works something like this (this hasn't been properly tested, but should be enough to give you the idea).

  • note: when the regex has the global flag then it becomes stateful where exec just gives you one match at a time.
  • note: while exec is used multiple times, the entire string is only traversed once.
function getAllEmojiFromText(text) {
    if (!text) {
        return [];
    }

    const splitText = [];
    let reResult;
    let lastMatchIndexEnd = 0;
    do {
        // Look for an emoji chunk in the string
        reResult = CONST.REGEX.EMOJIS.exec(text);

        // If we reached the end of the string and it wasn't included in a previous match
        // the chunk between the end of the last match and the end of the string is plain text
        if (reResult === null && lastMatchIndexEnd !== text.length - 1) {
            splitText.push({
                text: text.slice(lastMatchIndexEnd, text.length - 1),
                isEmoji: false,
            })
            continue;
        }

        const matchIndexStart = reResult.indices[0][0];
        const matchIndexEnd = reResult.indices[0][1];

        // The chunk between the end of the last match and the start of the new one is plain-text
        splitText.push({
            text: text.slice(lastMatchIndexEnd, matchIndexStart),
            isEmoji: false,
        });
        
        // Everything captured by the regex itself is emoji + whitespace
        splitText.push({
            text: text.slice(matchIndexStart, matchIndexEnd),
            isEmoji: true,
        });

        lastMatchIndexEnd = matchIndexEnd;
    } while (reResult !== null);

    return splitText;
}

Step 4

Refactor EmojiUtils.hasEmojis like so:

function hasEmojis(message) {
    const splitText = getAllEmojiFromText(message);
    return _.find(splitText, chunk => chunk.isEmoji) !== undefined;
}

Step 5

Refactor EmojiUtils.containsOnlyEmojis like so:

function containsOnlyEmojis(message) {
    const splitText = getAllEmojiFromText(message);
    return _.every(splitText, chunk => chunk.isEmoji);
}

src/styles/styles/styles.native.js Outdated Show resolved Hide resolved
src/styles/variables/variables.native.js Outdated Show resolved Hide resolved
src/styles/styles/index.js Outdated Show resolved Hide resolved
@josemak25
Copy link
Author

There are a number of other changes I want to see included in this PR.

Unit Test Coverage

EmojiUtils desperately needs some unit test coverage. That's almost always a good idea when we are dealing with complex regexes. Furthermore, it's probably a good place to start to establish a baseline before making the other changes listed here.

Unused Method

Next, I noticed that EmojiUtils.trimEmojiUnicode is unused, so we should remove it

Refactoring EmojiUtils

Third, I noticed some inefficiencies and unnecessarily complex code in the following three methods:

  1. containsOnlyEmoji
  2. hasEmojis
  3. getAllEmojisFromText

I think we should refactor these methods such that the string is only traversed by a regex exactly once when any one of the three methods is called.

I've done some research, and I think this should be possible in a few steps.

Step 1

Refactor CONST.REGEX.EMOJIS such that it will match not just a single emoji at a time, but 1 or more. This means that if we have an input string like so:

Hello world 🙂🙂🙂 what a great day ☀️

const input = 'Hello world U+1F600U+1F600U+1F600 what a great day U+2600';

then we do this:

input.split(CONST.REGEX.EMOJIS);

We would get a result like this:

['Hello world ', '🙂🙂🙂', ' what a great day ', '☀️']

result = ['Hello world ', 'U+1F600U+1F600U+1F600', ' what a great day ', 'U+2600']

Furthermore, it should ignore whitespace or 0-length characters if they are surrounded by emoji. So doing a split on this input:

const input = 'Hello world U+1F600     U+1F600     U+1F600 what a great day U+2600'

would produce this output:

result = ['Hello world ', 'U+1F600     U+1F600     U+1F600', ' what a great day ', 'U+2600']

Step 2

  1. Add the d flag to CONST.REGEX.EMOJIS such that the result of a regular expression match should contain the start and end indices of the substrings of each capture group.
  2. Wrap the regex in a capture group such that the chunks of 1 or more potentially-whitespace-separated emojis are captured.

Step 3

Refactor EmojiUtils.getAllEmojisFromText so that it works something like this (this hasn't been properly tested, but should be enough to give you the idea).

  • note: when the regex has the global flag then it becomes stateful where exec just gives you one match at a time.
  • note: while exec is used multiple times, the entire string is only traversed once.
function getAllEmojiFromText(text) {
    if (!text) {
        return [];
    }

    const splitText = [];
    let reResult;
    let lastMatchIndexEnd = 0;
    do {
        // Look for an emoji chunk in the string
        reResult = CONST.REGEX.EMOJIS.exec(text);

        // If we reached the end of the string and it wasn't included in a previous match
        // the chunk between the end of the last match and the end of the string is plain text
        if (reResult === null && lastMatchIndexEnd !== text.length - 1) {
            splitText.push({
                text: text.slice(lastMatchIndexEnd, text.length - 1),
                isEmoji: false,
            })
            continue;
        }

        const matchIndexStart = reResult.indices[0][0];
        const matchIndexEnd = reResult.indices[0][1];

        // The chunk between the end of the last match and the start of the new one is plain-text
        splitText.push({
            text: text.slice(lastMatchIndexEnd, matchIndexStart),
            isEmoji: false,
        });
        
        // Everything captured by the regex itself is emoji + whitespace
        splitText.push({
            text: text.slice(matchIndexStart, matchIndexEnd),
            isEmoji: true,
        });

        lastMatchIndexEnd = matchIndexEnd;
    } while (reResult !== null);

    return splitText;
}

Step 4

Refactor EmojiUtils.hasEmojis like so:

function hasEmojis(message) {
    const splitText = getAllEmojiFromText(message);
    return _.find(splitText, chunk => chunk.isEmoji) !== undefined;
}

Step 5

Refactor EmojiUtils.containsOnlyEmojis like so:

function containsOnlyEmojis(message) {
    const splitText = getAllEmojiFromText(message);
    return _.every(splitText, chunk => chunk.isEmoji);
}

@roryabraham from my test with your solution adding the d flag works for the web but not on android and ios platforms as they both crash

EMOJIS: /[\p{Extended_Pictographic}\u200d\u{1f1e6}-\u{1f1ff}\u{1f3fb}-\u{1f3ff}\u{e0020}-\u{e007f}\u20E3\uFE0F]|[#*0-9]\uFE0F?\u20E3/dgu,

Also, the solution does not satisfy surrogate pair emojis, more context on this here #15611 (comment)

Crash screenshot for mobile platforms with `d flag`

simulator_screenshot_B32DC407-C3AC-4899-BD51-1612262A958B

Screenshot of suggested refactor not covering surrogate pair emojis on the web

Screenshot 2023-03-03 at 7 17 48 PM

Screenshot of my initial PR covering surrogate pair emojis on all platforms

My solution

@roryabraham
Copy link
Contributor

roryabraham commented Mar 3, 2023

the d flag works for the web but not on android and ios platforms as they both crash

Have logs for this crash? Could this be because the d flag is not implemented in the Hermes JS engine, or something else?

Edit: Yep, it seems that the hasIndices flag is not implemented in Hermes: https://github.com/facebook/hermes/blob/417190297242f14fed540378390d28926c2a7f7e/include/hermes/Regex/RegexTypes.h#L213-L343. Shoot ... did not see that coming.

Edit 2: Created facebook/hermes#932, but we need to decide if we should HOLD this PR on that or not

@josemak25 josemak25 requested review from parasharrajat and roryabraham and removed request for parasharrajat and roryabraham March 6, 2023 12:14
@fbmal7
Copy link

fbmal7 commented Apr 11, 2023

@fabioh8010 I just ran 262 against latest main and it reported no errors. It reported 19274 passing tests, so it seems like for some reason you are running more tests.

@roryabraham
Copy link
Contributor

roryabraham commented Apr 11, 2023

Maybe we should continue discussion on this topic either in an upstream draft PR or in facebook/hermes#932 ?

@fabioh8010
Copy link
Contributor

@roryabraham @fbmal7 Yes, it's better. I'll create a draft PR tomorrow and will let you know, so we can have continue discussions there.

@roryabraham roryabraham changed the title Fix/make-emojis-larger-in-other-message-contexts [HOLD] Fix/make-emojis-larger-in-other-message-contexts Apr 11, 2023
@fabioh8010
Copy link
Contributor

@fbmal7 @roryabraham

I published a Draft PR here -> facebook/hermes#968

@fabioh8010
Copy link
Contributor

Update: PR is being reviewed, I left some questions there after the first review and I'll address all of them once I get feedback.

@fabioh8010
Copy link
Contributor

Update: PR reviewed and some changes made, also I made it ready to review.

@fabioh8010
Copy link
Contributor

Update: PR reviewed again and I need to make some more changes to keep the implementation closer to ECMAScript specifications. I'll be OOO for some days and will return on May 4th to start working on these changes in the following days.

@twisterdotcom
Copy link
Contributor

Got some issues Held on this. How is the review going?

@fabioh8010
Copy link
Contributor

Hi @twisterdotcom , I addressed the last review comments on Friday and I'm now waiting for his feedback.

Latest update -> facebook/hermes#968 (comment)

@fabioh8010
Copy link
Contributor

Update: Addressed more requested changes on the PR, waiting for another review now.

@pecanoro
Copy link
Contributor

Is there any reason why this is on HOLD?

@roryabraham
Copy link
Contributor

roryabraham commented Jun 13, 2023

Yes, @pecanoro it's on HOLD for a new regex feature in the Hermes JS engine: facebook/hermes#968

More context in this comment

@fabioh8010
Copy link
Contributor

fabioh8010 commented Jun 20, 2023

Update: Looks like we are coming to an end in the Hermes PR 🎉 Meta's team is discussing how to merge those changes.

@twisterdotcom
Copy link
Contributor

@fabioh8010 yessss!

@fabioh8010
Copy link
Contributor

Update: Still waiting for Meta's team decision about how to merge the Hermes PR.

@jeet-dhandha
Copy link
Contributor

Don't know much context of the PR but if you are looking for the Regex to get all the emojis.

Check this comment:
#23153 (comment)

@fabioh8010
Copy link
Contributor

@jeet-dhandha The Hermes engine doesn't support unicode property escapes -> https://hermesengine.dev/docs/regexp#supported-syntax

So this type of regex will crash on mobile platforms.

@fabioh8010
Copy link
Contributor

Update: Hermes PR is expected to land on RN 0.73 -> facebook/hermes#968 (comment)

@roryabraham
Copy link
Contributor

This is blocked on the RN 0.73 release. They just published 0.73-rc.3 a few days ago

@pecanoro
Copy link
Contributor

It seems RN 0.73 has finally been released!

@roryabraham
Copy link
Contributor

Yes, and we're upgrading E/App to 0.73.1 in #31558

@pecanoro
Copy link
Contributor

Just wondering, can we finally remove the HOLD in this PR?

@roryabraham
Copy link
Contributor

Yep, I think we can lift the HOLD here 🎉

@roryabraham roryabraham changed the title [HOLD] Fix/make-emojis-larger-in-other-message-contexts Fix/make-emojis-larger-in-other-message-contexts Jan 24, 2024
@twisterdotcom
Copy link
Contributor

Who is responsible for this now? @avijeetpandey?

@roryabraham
Copy link
Contributor

@roryabraham
Copy link
Contributor

Closing this out per this comment

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.

10 participants