import React from 'react'; import { FlatList, Text, TouchableOpacity } from 'react-native'; import shortnameToUnicode from '../../lib/methods/helpers/shortnameToUnicode'; import styles from './styles'; import CustomEmoji from './CustomEmoji'; import scrollPersistTaps from '../../lib/methods/helpers/scrollPersistTaps'; import { IEmoji, IEmojiCategory } from '../../definitions/IEmoji'; const MAX_EMOJI_SIZE = 50; const renderEmoji = (emoji: IEmoji, size: number, baseUrl: string) => { if (emoji && emoji.isCustom) { return ( ); } return ( {shortnameToUnicode(`:${emoji}:`)} ); }; const EmojiCategory = React.memo(({ baseUrl, onEmojiSelected, emojis, width, tabsCount, ...props }: IEmojiCategory) => { const emojiSize = width ? Math.min(width / tabsCount, MAX_EMOJI_SIZE) : MAX_EMOJI_SIZE; const numColumns = Math.trunc(width ? width / emojiSize : tabsCount); const renderItem = (emoji: IEmoji) => ( onEmojiSelected(emoji)} testID={`reaction-picker-${emoji && emoji.isCustom ? emoji.content : emoji}`}> {renderEmoji(emoji, emojiSize, baseUrl)} ); if (!width) { return null; } return ( (item && item.isCustom && item.content) || item} data={emojis} extraData={{ baseUrl, onEmojiSelected, width, ...props }} renderItem={({ item }) => renderItem(item)} numColumns={numColumns} initialNumToRender={45} removeClippedSubviews {...scrollPersistTaps} keyboardDismissMode={'none'} /> ); }); export default EmojiCategory;