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 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, ...props }: IEmojiCategory) => { const renderItem = (emoji: IEmoji) => ( onEmojiSelected(emoji)} testID={`reaction-picker-${emoji && emoji.isCustom ? emoji.content : emoji}`}> {renderEmoji(emoji, EMOJI_SIZE, baseUrl)} ); if (!width) { return null; } const numColumns = Math.trunc(width / EMOJI_SIZE); const marginHorizontal = (width - numColumns * EMOJI_SIZE) / 2; 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;