2018-01-30 19:48:26 +00:00
|
|
|
import React from 'react';
|
2022-10-21 18:27:55 +00:00
|
|
|
import { FlatList } from 'react-native-gesture-handler';
|
2019-01-29 19:52:56 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
import { IEmoji } from '../../definitions/IEmoji';
|
2023-03-09 20:17:20 +00:00
|
|
|
import scrollPersistTaps from '../../lib/methods/helpers/scrollPersistTaps';
|
2022-10-21 18:27:55 +00:00
|
|
|
import { PressableEmoji } from './PressableEmoji';
|
2023-03-09 20:17:20 +00:00
|
|
|
import { EMOJI_BUTTON_SIZE } from './styles';
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
interface IEmojiCategoryProps {
|
|
|
|
emojis: IEmoji[];
|
|
|
|
onEmojiSelected: (emoji: IEmoji) => void;
|
|
|
|
tabLabel?: string; // needed for react-native-scrollable-tab-view only
|
2023-03-09 20:17:20 +00:00
|
|
|
parentWidth: number;
|
2022-10-21 18:27:55 +00:00
|
|
|
}
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2023-03-09 20:17:20 +00:00
|
|
|
const EmojiCategory = ({ onEmojiSelected, emojis, parentWidth }: IEmojiCategoryProps): React.ReactElement | null => {
|
|
|
|
if (!parentWidth) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2023-03-09 20:17:20 +00:00
|
|
|
const numColumns = Math.trunc(parentWidth / EMOJI_BUTTON_SIZE);
|
|
|
|
const marginHorizontal = (parentWidth % EMOJI_BUTTON_SIZE) / 2;
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
const renderItem = ({ item }: { item: IEmoji }) => <PressableEmoji emoji={item} onPress={onEmojiSelected} />;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
return (
|
|
|
|
<FlatList
|
2023-03-09 20:17:20 +00:00
|
|
|
key={`emoji-category-${parentWidth}`}
|
2022-10-21 18:27:55 +00:00
|
|
|
keyExtractor={item => (typeof item === 'string' ? item : item.name)}
|
|
|
|
data={emojis}
|
|
|
|
renderItem={renderItem}
|
|
|
|
numColumns={numColumns}
|
|
|
|
initialNumToRender={45}
|
|
|
|
removeClippedSubviews
|
|
|
|
contentContainerStyle={{ marginHorizontal }}
|
|
|
|
{...scrollPersistTaps}
|
|
|
|
keyboardDismissMode={'none'}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2020-06-17 17:35:58 +00:00
|
|
|
export default EmojiCategory;
|