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';
|
2018-04-24 19:34:03 +00:00
|
|
|
import { connect } from 'react-redux';
|
2018-01-30 19:48:26 +00:00
|
|
|
import CustomEmoji from '../EmojiPicker/CustomEmoji';
|
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
@connect(state => ({
|
|
|
|
customEmojis: state.customEmojis
|
|
|
|
}))
|
2018-01-30 19:48:26 +00:00
|
|
|
export default class Emoji extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
content: PropTypes.string,
|
2018-02-08 14:08:50 +00:00
|
|
|
standardEmojiStyle: Text.propTypes.style,
|
|
|
|
customEmojiStyle: ViewPropTypes.style,
|
2018-01-30 19:48:26 +00:00
|
|
|
customEmojis: PropTypes.object.isRequired
|
|
|
|
};
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
content, standardEmojiStyle, customEmojiStyle, customEmojis
|
|
|
|
} = this.props;
|
|
|
|
const parsedContent = content.replace(/^:|:$/g, '');
|
|
|
|
const emojiExtension = customEmojis[parsedContent];
|
|
|
|
if (emojiExtension) {
|
|
|
|
const emoji = { extension: emojiExtension, content: parsedContent };
|
|
|
|
return <CustomEmoji key={content} style={customEmojiStyle} emoji={emoji} />;
|
|
|
|
}
|
|
|
|
return <Text style={standardEmojiStyle}>{ emojify(`${ content }`, { output: 'unicode' }) }</Text>;
|
|
|
|
}
|
|
|
|
}
|