2018-01-30 19:48:26 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { FlatList, Text, TouchableOpacity } from 'react-native';
|
2019-01-29 19:52:56 +00:00
|
|
|
|
2022-06-06 14:17:51 +00:00
|
|
|
import shortnameToUnicode from '../../lib/methods/helpers/shortnameToUnicode';
|
2018-01-30 19:48:26 +00:00
|
|
|
import styles from './styles';
|
|
|
|
import CustomEmoji from './CustomEmoji';
|
2022-06-06 14:17:51 +00:00
|
|
|
import scrollPersistTaps from '../../lib/methods/helpers/scrollPersistTaps';
|
2022-02-17 15:27:01 +00:00
|
|
|
import { IEmoji, IEmojiCategory } from '../../definitions/IEmoji';
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
const EMOJI_SIZE = 50;
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const renderEmoji = (emoji: IEmoji, size: number, baseUrl: string) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
if (emoji && emoji.isCustom) {
|
2021-09-13 20:41:05 +00:00
|
|
|
return (
|
|
|
|
<CustomEmoji
|
|
|
|
style={[styles.customCategoryEmoji, { height: size - 16, width: size - 16 }]}
|
|
|
|
emoji={emoji}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
/>
|
|
|
|
);
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Text style={[styles.categoryEmoji, { height: size, width: size, fontSize: size - 14 }]}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{shortnameToUnicode(`:${emoji}:`)}
|
2018-01-30 19:48:26 +00:00
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-07 01:06:08 +00:00
|
|
|
class EmojiCategory extends React.Component<IEmojiCategory> {
|
|
|
|
renderItem(emoji: IEmoji) {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { baseUrl, onEmojiSelected } = this.props;
|
2018-01-30 19:48:26 +00:00
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
activeOpacity={0.7}
|
2022-05-07 01:06:08 +00:00
|
|
|
// @ts-ignore
|
2019-11-25 20:01:17 +00:00
|
|
|
key={emoji && emoji.isCustom ? emoji.content : emoji}
|
2022-05-07 01:06:08 +00:00
|
|
|
onPress={() => onEmojiSelected(emoji)}
|
2021-09-13 20:41:05 +00:00
|
|
|
testID={`reaction-picker-${emoji && emoji.isCustom ? emoji.content : emoji}`}>
|
2022-05-07 01:06:08 +00:00
|
|
|
{renderEmoji(emoji, EMOJI_SIZE, baseUrl)}
|
2019-02-07 15:48:10 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-11-25 20:01:17 +00:00
|
|
|
const { emojis, width } = this.props;
|
|
|
|
|
|
|
|
if (!width) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const numColumns = Math.trunc(width / EMOJI_SIZE);
|
2021-09-13 20:41:05 +00:00
|
|
|
const marginHorizontal = (width - numColumns * EMOJI_SIZE) / 2;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-02-08 14:08:50 +00:00
|
|
|
return (
|
2019-11-25 20:01:17 +00:00
|
|
|
<FlatList
|
|
|
|
contentContainerStyle={{ marginHorizontal }}
|
|
|
|
// rerender FlatList in case of width changes
|
2021-09-13 20:41:05 +00:00
|
|
|
key={`emoji-category-${width}`}
|
2022-03-31 12:38:20 +00:00
|
|
|
// @ts-ignore
|
2019-11-25 20:01:17 +00:00
|
|
|
keyExtractor={item => (item && item.isCustom && item.content) || item}
|
2018-09-25 19:28:42 +00:00
|
|
|
data={emojis}
|
2019-11-25 20:01:17 +00:00
|
|
|
extraData={this.props}
|
|
|
|
renderItem={({ item }) => this.renderItem(item)}
|
|
|
|
numColumns={numColumns}
|
2018-02-08 14:08:50 +00:00
|
|
|
initialNumToRender={45}
|
|
|
|
removeClippedSubviews
|
|
|
|
{...scrollPersistTaps}
|
|
|
|
/>
|
|
|
|
);
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2020-06-17 17:35:58 +00:00
|
|
|
export default EmojiCategory;
|