Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
OtavioStasiak authored and diegolmello committed Oct 22, 2024
1 parent a478d68 commit 90909f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 4 additions & 7 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 @@ -23,13 +23,10 @@ const Emoji = React.memo(({ literal, isMessageContainsOnlyEmoji, getCustomEmoji,
if (emoji && customEmojis) {
return <CustomEmoji style={[isMessageContainsOnlyEmoji ? styles.customEmojiBig : styles.customEmoji]} emoji={emoji} />;
}

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
18 changes: 15 additions & 3 deletions app/containers/markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,20 @@ const isOnlyEmoji = (str: string) => {
return !removeAllEmoji(str).length;
};

const removeOneEmoji = (str: string) => str.replace(new RegExp(emojiRanges), '');

const emojiCount = (str: string) => {
const counter = removeSpaces(str).length;
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 @@ -131,7 +143,7 @@ class Markdown extends PureComponent<IMarkdownProps, any> {
const { numberOfLines } = this.props;
const defaultStyle = [this.isMessageContainsOnlyEmoji ? styles.textBig : {}, ...context.map(type => styles[type])];

if (this.isMessageContainsOnlyEmoji) return this.renderEmoji({ literal: removeSpaces(literal) });
if (this.isMessageContainsOnlyEmoji) return this.renderEmoji({ literal });

return (
<Text accessibilityLabel={literal} style={[styles.text, defaultStyle]} numberOfLines={numberOfLines}>
Expand Down Expand Up @@ -337,7 +349,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 90909f9

Please sign in to comment.