import React, { useContext } from 'react'; import { View, Text } from 'react-native'; import Touchable from './Touchable'; import { CustomIcon } from '../../lib/Icons'; import styles from './styles'; import Emoji from './Emoji'; import { BUTTON_HIT_SLOP } from './utils'; import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import MessageContext from './Context'; type TMessageAddReaction = { theme: string }; type TMessageReaction = { reaction: { usernames: []; emoji: object; }; getCustomEmoji: Function; theme: string; }; interface IMessageReactions { reactions: object[]; getCustomEmoji: Function; theme: string; } const AddReaction = React.memo(({ theme }: TMessageAddReaction) => { const { reactionInit } = useContext(MessageContext); return ( ); }); const Reaction = React.memo(({reaction, getCustomEmoji, theme}: TMessageReaction) => { const { onReactionPress, onReactionLongPress, baseUrl, user } = useContext(MessageContext); const reacted = reaction.usernames.findIndex((item: TMessageReaction) => item === user.username) !== -1; return ( onReactionPress(reaction.emoji)} onLongPress={onReactionLongPress} key={reaction.emoji} testID={`message-reaction-${ reaction.emoji }`} style={[styles.reactionButton, { backgroundColor: reacted ? themes[theme].bannerBackground : themes[theme].backgroundColor }]} background={Touchable.Ripple(themes[theme].bannerBackground)} hitSlop={BUTTON_HIT_SLOP} > { reaction.usernames.length } ); }); const Reactions = React.memo(({ reactions, getCustomEmoji, theme }: IMessageReactions) => { if (!Array.isArray(reactions) || reactions.length === 0) { return null; } return ( {reactions.map((reaction: any) => ( ))} ); }); Reaction.displayName = 'MessageReaction'; Reactions.displayName = 'MessageReactions'; AddReaction.displayName = 'MessageAddReaction'; export default withTheme(Reactions);