2018-01-30 19:48:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-02-08 14:08:50 +00:00
|
|
|
import { Text, TouchableOpacity, Platform } from 'react-native';
|
2018-01-30 19:48:26 +00:00
|
|
|
import { emojify } from 'react-emojione';
|
|
|
|
import { responsive } from 'react-native-responsive-ui';
|
2018-02-08 14:08:50 +00:00
|
|
|
import { OptimizedFlatList } from 'react-native-optimized-flatlist';
|
2018-01-30 19:48:26 +00:00
|
|
|
import styles from './styles';
|
|
|
|
import CustomEmoji from './CustomEmoji';
|
2018-02-08 14:08:50 +00:00
|
|
|
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
2018-01-30 19:48:26 +00:00
|
|
|
|
|
|
|
const emojisPerRow = Platform.OS === 'ios' ? 8 : 9;
|
|
|
|
|
|
|
|
const renderEmoji = (emoji, size) => {
|
|
|
|
if (emoji.isCustom) {
|
|
|
|
return <CustomEmoji style={[styles.customCategoryEmoji, { height: size - 8, width: size - 8 }]} emoji={emoji} />;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Text style={[styles.categoryEmoji, { height: size, width: size, fontSize: size - 14 }]}>
|
|
|
|
{emojify(`:${ emoji }:`, { output: 'unicode' })}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@responsive
|
|
|
|
export default class EmojiCategory extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
emojis: PropTypes.any,
|
|
|
|
window: PropTypes.any,
|
|
|
|
onEmojiSelected: PropTypes.func,
|
|
|
|
emojisPerRow: PropTypes.number,
|
|
|
|
width: PropTypes.number
|
|
|
|
};
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
const { width, height } = this.props.window;
|
|
|
|
|
|
|
|
this.size = Math.min(this.props.width || width, height) / (this.props.emojisPerRow || emojisPerRow);
|
2018-03-06 17:40:44 +00:00
|
|
|
this.emojis = props.emojis;
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderItem(emoji, size) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
activeOpacity={0.7}
|
|
|
|
key={emoji.isCustom ? emoji.content : emoji}
|
|
|
|
onPress={() => this.props.onEmojiSelected(emoji)}
|
|
|
|
>
|
|
|
|
{renderEmoji(emoji, size)}
|
|
|
|
</TouchableOpacity>);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-02-08 14:08:50 +00:00
|
|
|
return (
|
|
|
|
<OptimizedFlatList
|
|
|
|
keyExtractor={item => (item.isCustom && item.content) || item}
|
|
|
|
data={this.props.emojis}
|
|
|
|
renderItem={({ item }) => this.renderItem(item, this.size)}
|
|
|
|
numColumns={emojisPerRow}
|
|
|
|
initialNumToRender={45}
|
|
|
|
getItemLayout={(data, index) => ({ length: this.size, offset: this.size * index, index })}
|
|
|
|
removeClippedSubviews
|
|
|
|
{...scrollPersistTaps}
|
|
|
|
/>
|
|
|
|
);
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
}
|