import React from 'react' import { Image, StyleSheet, Text } from 'react-native' import { useTheme } from 'src/utils/styles/ThemeManager' const regexEmoji = new RegExp(/(:[a-z0-9_]+:)/) export interface Props { content: string emojis: Mastodon.Emoji[] size: number fontBold?: boolean } const Emojis: React.FC = ({ content, emojis, size, fontBold = false }) => { const { theme } = useTheme() const styles = StyleSheet.create({ text: { fontSize: size, lineHeight: size + 2, color: theme.primary, ...(fontBold && { fontWeight: 'bold' }) }, image: { width: size, height: size } }) const hasEmojis = content.match(regexEmoji) return hasEmojis ? ( <> {content.split(regexEmoji).map((str, i) => { if (str.match(regexEmoji)) { const emojiShortcode = str.split(regexEmoji)[1] const emojiIndex = emojis.findIndex(emoji => { return emojiShortcode === `:${emoji.shortcode}:` }) return emojiIndex === -1 ? ( {emojiShortcode} ) : ( ) } else { return ( {str} ) } })} ) : ( {content} ) } export default Emojis