2021-10-20 16:32:58 +00:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import { Text } from 'react-native';
|
|
|
|
import { Emoji as EmojiProps } from '@rocket.chat/message-parser';
|
|
|
|
|
2022-06-06 14:17:51 +00:00
|
|
|
import shortnameToUnicode from '../../../lib/methods/helpers/shortnameToUnicode';
|
2022-07-04 18:10:14 +00:00
|
|
|
import { themes } from '../../../lib/constants';
|
2021-10-20 16:32:58 +00:00
|
|
|
import { useTheme } from '../../../theme';
|
|
|
|
import styles from '../styles';
|
|
|
|
import CustomEmoji from '../../EmojiPicker/CustomEmoji';
|
|
|
|
import MarkdownContext from './MarkdownContext';
|
|
|
|
|
|
|
|
interface IEmojiProps {
|
2022-07-06 20:01:33 +00:00
|
|
|
block: EmojiProps;
|
2021-10-20 16:32:58 +00:00
|
|
|
isBigEmoji?: boolean;
|
|
|
|
}
|
|
|
|
|
2022-07-06 20:01:33 +00:00
|
|
|
const Emoji = ({ block, isBigEmoji }: IEmojiProps) => {
|
2022-07-04 18:10:14 +00:00
|
|
|
const { theme } = useTheme();
|
2021-10-20 16:32:58 +00:00
|
|
|
const { baseUrl, getCustomEmoji } = useContext(MarkdownContext);
|
2022-07-06 20:01:33 +00:00
|
|
|
|
|
|
|
if ('unicode' in block) {
|
|
|
|
return <Text style={[{ color: themes[theme].bodyText }, isBigEmoji ? styles.textBig : styles.text]}>{block.unicode}</Text>;
|
|
|
|
}
|
|
|
|
const emojiToken = block?.shortCode ? `:${block.shortCode}:` : `:${block.value?.value}:`;
|
|
|
|
const emojiUnicode = shortnameToUnicode(emojiToken);
|
|
|
|
const emoji = getCustomEmoji?.(block.value?.value);
|
2021-10-20 16:32:58 +00:00
|
|
|
|
|
|
|
if (emoji) {
|
|
|
|
return <CustomEmoji baseUrl={baseUrl} style={[isBigEmoji ? styles.customEmojiBig : styles.customEmoji]} emoji={emoji} />;
|
|
|
|
}
|
2022-07-06 20:01:33 +00:00
|
|
|
return (
|
|
|
|
<Text style={[{ color: themes[theme].bodyText }, isBigEmoji && emojiToken !== emojiUnicode ? styles.textBig : styles.text]}>
|
|
|
|
{emojiUnicode}
|
|
|
|
</Text>
|
|
|
|
);
|
2021-10-20 16:32:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Emoji;
|