2018-01-30 19:48:26 +00:00
|
|
|
import React from 'react';
|
2018-02-08 14:08:50 +00:00
|
|
|
import { Text, ViewPropTypes } from 'react-native';
|
2018-01-30 19:48:26 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { emojify } from 'react-emojione';
|
|
|
|
import CustomEmoji from '../EmojiPicker/CustomEmoji';
|
|
|
|
|
|
|
|
export default class Emoji extends React.PureComponent {
|
|
|
|
static propTypes = {
|
2018-09-11 16:32:52 +00:00
|
|
|
content: PropTypes.string.isRequired,
|
|
|
|
baseUrl: PropTypes.string.isRequired,
|
2018-02-08 14:08:50 +00:00
|
|
|
standardEmojiStyle: Text.propTypes.style,
|
|
|
|
customEmojiStyle: ViewPropTypes.style,
|
2018-09-11 16:32:52 +00:00
|
|
|
customEmojis: PropTypes.oneOfType([
|
|
|
|
PropTypes.array,
|
|
|
|
PropTypes.object
|
|
|
|
])
|
2018-09-25 19:28:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 19:48:26 +00:00
|
|
|
render() {
|
|
|
|
const {
|
2018-09-11 16:32:52 +00:00
|
|
|
content, standardEmojiStyle, customEmojiStyle, customEmojis, baseUrl
|
2018-01-30 19:48:26 +00:00
|
|
|
} = this.props;
|
|
|
|
const parsedContent = content.replace(/^:|:$/g, '');
|
|
|
|
const emojiExtension = customEmojis[parsedContent];
|
|
|
|
if (emojiExtension) {
|
|
|
|
const emoji = { extension: emojiExtension, content: parsedContent };
|
2018-09-11 16:32:52 +00:00
|
|
|
return <CustomEmoji key={content} baseUrl={baseUrl} style={customEmojiStyle} emoji={emoji} />;
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
return <Text style={standardEmojiStyle}>{ emojify(`${ content }`, { output: 'unicode' }) }</Text>;
|
|
|
|
}
|
|
|
|
}
|