Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
OtavioStasiak committed Oct 10, 2024
1 parent 85e301c commit 2a3f786
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 4 additions & 6 deletions app/containers/markdown/Emoji.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { View, Text } from 'react-native';
import { Text } from 'react-native';

import shortnameToUnicode from '../../lib/methods/helpers/shortnameToUnicode';
import CustomEmoji from '../EmojiPicker/CustomEmoji';
Expand All @@ -25,11 +25,9 @@ const Emoji = React.memo(({ literal, isMessageContainsOnlyEmoji, getCustomEmoji,
}

return (
<View style={{ flexDirection: 'row' }}>
<Text style={[{ color: colors.fontDefault }, isMessageContainsOnlyEmoji ? styles.textBig : styles.text, style]}>
{emojiUnicode}
</Text>
</View>
<Text style={[{ color: colors.fontDefault }, isMessageContainsOnlyEmoji ? styles.textBig : styles.text, style]}>
{emojiUnicode}
</Text>
);
});

Expand Down
17 changes: 14 additions & 3 deletions app/containers/markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,20 @@ const isOnlyEmoji = (str: string) => {
return !removeAllEmoji(str).length;
};

const emojiCount = (str: string) => {
const counter = removeSpaces(str).length;
const removeOneEmoji = (str: string) => str.replace(new RegExp(emojiRanges), '');

const emojiCount = (str: string) => {
str = removeSpaces(str);
let oldLength = 0;
let counter = 0;

while (oldLength !== str.length) {
oldLength = str.length;
str = removeOneEmoji(str);
if (oldLength !== str.length) {
counter += 1;
}
}
return counter;
};

Expand Down Expand Up @@ -337,7 +348,7 @@ class Markdown extends PureComponent<IMarkdownProps, any> {
m = formatHyperlink(m);
let ast = parser.parse(m);
ast = mergeTextNodes(ast);
this.isMessageContainsOnlyEmoji = isOnlyEmoji(m) && emojiCount(m) <= 6;
this.isMessageContainsOnlyEmoji = isOnlyEmoji(m) && emojiCount(m) <= 3;
return this.renderer?.render(ast) || null;
}
}
Expand Down

0 comments on commit 2a3f786

Please sign in to comment.