import React from 'react'; import { View } from 'react-native'; import ScrollableTabView from 'react-native-scrollable-tab-view'; import TabBar from './TabBar'; import EmojiCategory from './EmojiCategory'; import Footer from './Footer'; import styles from './styles'; import { categories, emojisByCategory } from '../../lib/constants'; import { useTheme } from '../../theme'; import { IEmoji, ICustomEmojis } from '../../definitions'; import { useAppSelector, useFrequentlyUsedEmoji } from '../../lib/hooks'; import { addFrequentlyUsed } from '../../lib/methods'; import { IEmojiPickerProps, EventTypes } from './interfaces'; const EmojiPicker = ({ onItemClicked, isEmojiKeyboard = false, searching = false, searchedEmojis = [] }: IEmojiPickerProps): React.ReactElement | null => { const { colors } = useTheme(); const { frequentlyUsed, loaded } = useFrequentlyUsedEmoji(); const allCustomEmojis: ICustomEmojis = useAppSelector( state => state.customEmojis, () => true ); const customEmojis = Object.keys(allCustomEmojis) .filter(item => item === allCustomEmojis[item].name) .map(item => ({ name: allCustomEmojis[item].name, extension: allCustomEmojis[item].extension })); const handleEmojiSelect = (emoji: IEmoji) => { onItemClicked(EventTypes.EMOJI_PRESSED, emoji); addFrequentlyUsed(emoji); }; const renderCategory = (category: keyof typeof emojisByCategory, i: number, label: string) => { let emojis = []; if (i === 0) { emojis = frequentlyUsed; } else if (i === 1) { emojis = customEmojis; } else { emojis = emojisByCategory[category]; } if (!emojis.length) { return null; } return handleEmojiSelect(emoji)} tabLabel={label} />; }; if (!loaded) { return null; } return ( {searching ? ( handleEmojiSelect(emoji)} /> ) : ( } contentProps={{ keyboardShouldPersistTaps: 'always', keyboardDismissMode: 'none' }} style={{ backgroundColor: colors.messageboxBackground }} > {categories.tabs.map((tab: any, i) => renderCategory(tab.category, i, tab.tabLabel))} )} {isEmojiKeyboard && (