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
2 changes: 2 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ const CONST = {

EMOJI_FREQUENT_ROW_COUNT: 3,

EMOJI_INVISIBLE_CODEPOINT: 'fe0f',

LOGIN_TYPE: {
PHONE: 'phone',
EMAIL: 'email',
Expand Down
29 changes: 27 additions & 2 deletions src/libs/EmojiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as User from './actions/User';
* @param {String} input
* @returns {String}
*/
function getEmojiUnicode(input) {
const getEmojiUnicode = _.memoize((input) => {
if (input.length === 0) {
return '';
}
Expand Down Expand Up @@ -40,7 +40,7 @@ function getEmojiUnicode(input) {
}
}
return _.map(pairs, val => parseInt(val, 10).toString(16)).join(' ');
}
});

/**
* Function to remove Skin Tone and utf16 surrogates from Emoji
Expand Down Expand Up @@ -70,6 +70,30 @@ function isSingleEmoji(message) {
return matchedUnicode === currentMessageUnicode;
}

/**
* Validates that this message contains only emojis
*
* @param {String} message
* @returns {Boolean}
*/
function containsOnlyEmojis(message) {
const match = message.match(CONST.REGEX.EMOJIS);
if (match) {
const codes = [];

Julesssss marked this conversation as resolved.
Show resolved Hide resolved
_.map(match, emoji => _.map(getEmojiUnicode(emoji).split(' '), (code) => {
if (code !== CONST.EMOJI_INVISIBLE_CODEPOINT) {
codes.push(code);
}
return code;
}));

const messageCodes = _.filter(_.map([...message], char => getEmojiUnicode(char)), string => string.length > 0 && string !== CONST.EMOJI_INVISIBLE_CODEPOINT);
return codes.length === messageCodes.length;
}
return false;
}

/**
* Get the header indices based on the max emojis per row
* @param {Object[]} emojis
Expand Down Expand Up @@ -176,4 +200,5 @@ export {
getDynamicHeaderIndices,
mergeEmojisWithFrequentlyUsedEmojis,
addToFrequentlyUsedEmojis,
containsOnlyEmojis,
};
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItemFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const ReportActionItemFragment = (props) => {
) : (
<Text
selectable={!canUseTouchScreen() || !props.isSmallScreenWidth}
style={EmojiUtils.isSingleEmoji(props.fragment.text) ? styles.singleEmojiText : undefined}
style={EmojiUtils.containsOnlyEmojis(props.fragment.text) ? styles.multipleEmojisText : undefined}
>
{Str.htmlDecode(props.fragment.text)}
{props.fragment.isEdited && (
Expand Down
2 changes: 1 addition & 1 deletion src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ const styles = {
textDecorationLine: 'none',
},

singleEmojiText: {
multipleEmojisText: {
Julesssss marked this conversation as resolved.
Show resolved Hide resolved
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.

},
Expand Down